// File: /workspace/github_c_makefile_star2_O2/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
movslq 0x7b6c(%rip), %r15      # 0xa108
cmpq $0x1, %r15
jne 0x25b8
andq $0x0, 0x7b7e(%rip)      # 0xa128
movb $0x0, 0x7b7f(%rip)      # 0xa130
xorl %r12d, %r12d
xorl %ecx, %ecx
jmp 0x25c5
movb 0x7b72(%rip), %cl       # 0xa130
movq 0x7b63(%rip), %r12      # 0xa128
movslq %edi, %rbp
movq %r15, %r13
shlq $0x20, %r13
leal 0x1(%r15), %r14d
movabsq $0x100000000, %rax      # imm = 0x100000000
testb $0x1, %cl
jne 0x2659
testq %r12, %r12
setne %cl
cmpq %rbp, %r15
setl %sil
orb %cl, %sil
cmpb $0x1, %sil
jne 0x2659
testq %r12, %r12
jne 0x2697
movl %r14d, 0x7b00(%rip)     # 0xa108
movq (%rbx,%r15,8), %r12
cmpb $0x2d, (%r12)
jne 0x2622
movzbl 0x1(%r12), %ecx
cmpl $0x2d, %ecx
je 0x2627
testl %ecx, %ecx
jne 0x262f
xorl %r12d, %r12d
jmp 0x2639
cmpb $0x0, 0x2(%r12)
je 0x2646
incq %r12
movq %r12, 0x7aef(%rip)      # 0xa128
xorl %ecx, %ecx
addq %rax, %r13
incl %r14d
incq %r15
jmp 0x25dd
andq $0x0, (%rbx,%r15,8)
movb $0x1, 0x7ade(%rip)      # 0xa130
movb $0x1, %cl
xorl %r12d, %r12d
jmp 0x263b
movl %edi, 0x7aa9(%rip)      # 0xa108
movl %edi, %eax
cmpl $0x2, %eax
jl 0x2688
movq -0x8(%rbx,%rax,8), %rcx
decq %rax
testq %rcx, %rcx
je 0x2661
movslq %edi, %rdx
leal -0x1(%rdi), %esi
movl %esi, 0x7a89(%rip)      # 0xa108
movq %rcx, -0x8(%rbx,%rdx,8)
movl %esi, %edi
jmp 0x2661
movb $0x1, 0x7aa1(%rip)      # 0xa130
pushq $-0x1
popq %rax
jmp 0x2757
movb (%r12), %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 0x26d8
incq %r12
movq %r12, 0x7a66(%rip)      # 0xa128
cmpb $0x3a, 0x1(%rax)
jne 0x26ff
cmpb $0x0, (%r12)
je 0x2705
movq %r12, 0x7a62(%rip)      # 0xa138
jmp 0x2726
cmpl $0x0, 0x7a2d(%rip)      # 0xa10c
movl 0xc(%rsp), %ebx
je 0x26f5
leaq 0x51c5(%rip), %rdi      # 0x78b1
movl %ebx, %esi
xorl %eax, %eax
callq 0x1eb8
movl %ebx, 0x7a39(%rip)      # 0xa134
pushq $0x3f
jmp 0x2691
movl 0x8(%rsp), %ecx
jmp 0x2738
cmpq %rbp, %r15
jge 0x2766
sarq $0x1d, %r13
andq $0x0, -0x8(%rbx,%r13)
movl %r14d, 0x79ed(%rip)     # 0xa108
movq (%rbx,%r13), %rax
movq %rax, 0x7a12(%rip)      # 0xa138
movl 0x8(%rsp), %ecx
leaq 0x79ef(%rip), %r12      # 0xa120
movq %r12, 0x79f0(%rip)      # 0xa128
cmpb $0x0, (%r12)
jne 0x2754
movslq 0x79c2(%rip), %rax      # 0xa108
andq $0x0, -0x8(%rbx,%rax,8)
andq $0x0, 0x79d4(%rip)      # 0xa128
movsbl %cl, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x799f(%rip)      # 0xa10c
movq 0x10(%rsp), %rcx
movl 0xc(%rsp), %ebp
je 0x2792
cmpb $0x3a, (%rcx)
je 0x2792
leaq 0x5144(%rip), %rdi      # 0x78c8
movl %ebp, %esi
xorl %eax, %eax
callq 0x1eb8
movq 0x10(%rsp), %rcx
movl %ebp, 0x799c(%rip)      # 0xa134
xorl %eax, %eax
cmpb $0x3a, (%rcx)
setne %al
leal (%rax,%rax,4), %ecx
addl $0x3a, %ecx
jmp 0x272a