getopt() implements the "standard" command line structure, i.e. all options come before all arguments (ref). Not all Unix commands adhere to this "standard"; if your command needs to deviate, you can parse argv[] by hand, without the getopt() function. From man 3 getopt:
If there are no more option characters, getopt() returns -1. Then
optind is the index in argv of the first argv-element that is not an
option.