// File: /workspace/github_c_makefile_star2_O1/ebiggers[P]xpack/programs/tgetopt.c
// Function: tgetopt
int
tgetopt(int argc, tchar *argv[], const tchar *optstring)
{
	static tchar empty[1];
	static tchar *nextchar;
	static bool done;

	if (toptind == 1) {
		/* Starting to scan a new argument vector */
		nextchar = NULL;
		done = false;
	}

	while (!done && (nextchar != NULL || toptind < argc)) {
		if (nextchar == NULL) {
			/* Scanning a new argument */
			tchar *arg = argv[toptind++];
			if (arg[0] == '-' && arg[1] != '\0') {
				if (arg[1] == '-' && arg[2] == '\0') {
					/* All args after "--" are nonoptions */
					argv[toptind - 1] = NULL;
					done = true;
				} else {
					/* Start of short option characters */
					nextchar = &arg[1];
				}
			}
		} else {
			/* More short options in previous arg */
			tchar opt = *nextchar;
			tchar *p = tstrchr(optstring, opt);
			if (p == NULL) {
				if (topterr)
					msg("invalid option -- '%"TC"'", opt);
				toptopt = opt;
				return '?';
			}
			/* 'opt' is a valid short option character */
			nextchar++;
			if (*(p + 1) == ':') {
				/* 'opt' requires an argument */
				if (*nextchar != '\0') {
					/* Optarg is in same argv argument */
					toptarg = nextchar;
				} else if (toptind < argc) {
					/* Optarg is next argv argument */
					argv[toptind - 1] = NULL;
					toptarg = argv[toptind++];
				} else {
					if (topterr && *optstring != ':') {
						msg("option requires an "
						    "argument -- '%"TC"'", opt);
					}
					toptopt = opt;
					opt = (*optstring == ':') ? ':' : '?';
				}
				nextchar = empty;
			}
			if (*nextchar == '\0') {
				argv[toptind - 1] = NULL;
				nextchar = NULL;
			}
			return opt;
		}
	}

	/* Done scanning.  Move all nonoptions to the end, set optind to the
	 * index of the first nonoption, and return -1. */
	toptind = argc;
	while (--argc > 0)
		if (argv[argc] != NULL)
			argv[--toptind] = argv[argc];
	done = true;
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
cmpl $0x1, 0x4fc0(%rip)      # 0xa108
jne 0x515c
movq $0x0, 0x4fd3(%rip) # 0xa128
movb $0x0, 0x4fd4(%rip)      # 0xa130
movb 0x4fce(%rip), %al       # 0xa130
testb %al, %al
je 0x51b7
movl %edi, 0x4f9c(%rip)      # 0xa108
cmpl $0x2, %edi
jl 0x519c
movl %edi, %eax
incq %rax
movq -0x10(%rbx,%rax,8), %rcx
testq %rcx, %rcx
je 0x5193
movslq %edi, %rdx
leal -0x1(%rdi), %esi
movl %esi, 0x4f7c(%rip)      # 0xa108
movq %rcx, -0x8(%rbx,%rdx,8)
movl %esi, %edi
decq %rax
cmpq $0x2, %rax
jg 0x5176
movb $0x1, 0x4f8d(%rip)      # 0xa130
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x4f4a(%rip), %r13      # 0xa108
movq 0x4f63(%rip), %r14      # 0xa128
movslq %edi, %rbp
movq %r13, %r15
shlq $0x20, %r15
leal 0x1(%r13), %r12d
movabsq $0x100000000, %rcx      # imm = 0x100000000
testq %r14, %r14
setne %r8b
cmpq %rbp, %r13
setl %sil
orb %r8b, %sil
cmpb $0x1, %sil
jne 0x5166
testq %r14, %r14
jne 0x5255
movl %r12d, 0x4f04(%rip)     # 0xa108
movq (%rbx,%r13,8), %r8
cmpb $0x2d, (%r8)
jne 0x5230
movzbl 0x1(%r8), %esi
testl %esi, %esi
je 0x5230
cmpl $0x2d, %esi
jne 0x5223
cmpb $0x0, 0x2(%r8)
je 0x5242
incq %r8
movq %r8, 0x4efb(%rip)       # 0xa128
movq %r8, %r14
addq %rcx, %r15
incl %r12d
incq %r13
testb $0x1, %al
je 0x51dd
jmp 0x5166
movq $0x0, (%rbx,%r13,8)
movb $0x1, 0x4edf(%rip)      # 0xa130
movb $0x1, %al
jmp 0x5230
movb (%r14), %al
movl %eax, 0x8(%rsp)
movsbl %al, %esi
movq %rdx, 0x10(%rsp)
movq %rdx, %rdi
movl %esi, 0xc(%rsp)
callq 0x10b0
testq %rax, %rax
je 0x5294
incq %r14
movq %r14, 0x4ea9(%rip)      # 0xa128
cmpb $0x3a, 0x1(%rax)
jne 0x52c1
cmpb $0x0, (%r14)
je 0x52c7
movq %r14, 0x4ea6(%rip)      # 0xa138
jmp 0x52eb
cmpl $0x0, 0x4e71(%rip)      # 0xa10c
movl 0xc(%rsp), %ebx
je 0x52b1
leaq 0x2609(%rip), %rdi      # 0x78b1
movl %ebx, %esi
xorl %eax, %eax
callq 0x4b60
movl %ebx, 0x4e7d(%rip)      # 0xa134
movl $0x3f, %eax
jmp 0x51a8
movl 0x8(%rsp), %edx
jmp 0x52fd
cmpq %rbp, %r13
jge 0x5326
sarq $0x1d, %r15
movq $0x0, -0x8(%rbx,%r15)
movl %r12d, 0x4e28(%rip)     # 0xa108
movq (%rbx,%r15), %rax
movq %rax, 0x4e4d(%rip)      # 0xa138
movl 0x8(%rsp), %edx
leaq 0x4e2a(%rip), %rax      # 0xa120
movq %rax, 0x4e2b(%rip)      # 0xa128
movq 0x4e24(%rip), %rax      # 0xa128
cmpb $0x0, (%rax)
jne 0x531e
movslq 0x4df8(%rip), %rax      # 0xa108
xorl %ecx, %ecx
movq %rcx, -0x8(%rbx,%rax,8)
movq %rcx, 0x4e0a(%rip)      # 0xa128
movsbl %dl, %eax
jmp 0x51a8
cmpl $0x0, 0x4ddf(%rip)      # 0xa10c
movq 0x10(%rsp), %rcx
movl 0xc(%rsp), %ebp
je 0x5352
cmpb $0x3a, (%rcx)
je 0x5352
leaq 0x2584(%rip), %rdi      # 0x78c8
movl %ebp, %esi
xorl %eax, %eax
callq 0x4b60
movq 0x10(%rsp), %rcx
movl %ebp, 0x4ddc(%rip)      # 0xa134
xorl %eax, %eax
cmpb $0x3a, (%rcx)
setne %al
leal (%rax,%rax,4), %edx
addl $0x3a, %edx
jmp 0x52ef