// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movq %rdx, %r14
movq %rsi, %rbx
movslq 0x4fcc(%rip), %rax      # 0xa108
cmpq $0x1, %rax
jne 0x5159
movq $0x0, 0x4fdb(%rip) # 0xa128
movb $0x0, 0x4fdc(%rip)      # 0xa130
xorl %r15d, %r15d
jmp 0x516d
cmpb $0x0, 0x4fd0(%rip)      # 0xa130
jne 0x51fe
movq 0x4fbb(%rip), %r15      # 0xa128
testq %r15, %r15
sete %cl
cmpl %edi, %eax
setl %bpl
setge %dl
testb %dl, %cl
jne 0x51fe
movslq %edi, %rcx
movq %rax, %r12
shlq $0x20, %r12
leal 0x1(%rax), %r13d
incq %rax
movabsq $0x100000000, %rdx      # imm = 0x100000000
testq %r15, %r15
jne 0x524f
movl %r13d, 0x4f5d(%rip)     # 0xa108
movq -0x8(%rbx,%rax,8), %r15
cmpb $0x2d, (%r15)
jne 0x51db
movzbl 0x1(%r15), %esi
testl %esi, %esi
je 0x51db
cmpl $0x2d, %esi
jne 0x51cf
cmpb $0x0, 0x2(%r15)
je 0x52b7
incq %r15
movq %r15, 0x4f4f(%rip)      # 0xa128
jmp 0x51de
xorl %r15d, %r15d
testq %r15, %r15
setne %sil
cmpq %rcx, %rax
setl %bpl
orb %bpl, %sil
addq %rdx, %r12
incl %r13d
incq %rax
testb $0x1, %sil
jne 0x519b
movl %edi, 0x4f04(%rip)      # 0xa108
cmpl $0x2, %edi
jl 0x5234
movl %edi, %eax
incq %rax
movq -0x10(%rbx,%rax,8), %rcx
testq %rcx, %rcx
je 0x522b
movslq %edi, %rdx
leal -0x1(%rdi), %esi
movl %esi, 0x4ee4(%rip)      # 0xa108
movq %rcx, -0x8(%rbx,%rdx,8)
movl %esi, %edi
decq %rax
cmpq $0x2, %rax
ja 0x520e
movb $0x1, 0x4ef5(%rip)      # 0xa130
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb (%r15), %al
movl %eax, (%rsp)
movsbl %al, %esi
movq %r14, %rdi
movl %esi, 0x4(%rsp)
callq 0x10b0
testq %rax, %rax
je 0x5288
incq %r15
movq %r15, 0x4eb5(%rip)      # 0xa128
cmpb $0x3a, 0x1(%rax)
jne 0x52b2
cmpb $0x0, (%r15)
je 0x52c5
movq %r15, 0x4eb2(%rip)      # 0xa138
jmp 0x52ea
cmpl $0x0, 0x4e7d(%rip)      # 0xa10c
movl 0x4(%rsp), %ebx
je 0x52a5
leaq 0x2615(%rip), %rdi      # 0x78b1
movl %ebx, %esi
xorl %eax, %eax
callq 0x4b84
movl %ebx, 0x4e89(%rip)      # 0xa134
movl $0x3f, %eax
jmp 0x5240
movl (%rsp), %edx
jmp 0x52fb
movq $0x0, -0x8(%rbx,%rax,8)
jmp 0x51fe
testb $0x1, %bpl
je 0x531e
sarq $0x1d, %r12
movq $0x0, -0x8(%rbx,%r12)
movl %r13d, 0x4e29(%rip)     # 0xa108
movq (%rbx,%r12), %rax
movq %rax, 0x4e4e(%rip)      # 0xa138
movl (%rsp), %edx
leaq 0x4e2c(%rip), %r15      # 0xa120
movq %r15, 0x4e2d(%rip)      # 0xa128
cmpb $0x0, (%r15)
jne 0x5316
movslq 0x4e00(%rip), %rax      # 0xa108
xorl %ecx, %ecx
movq %rcx, -0x8(%rbx,%rax,8)
movq %rcx, 0x4e12(%rip)      # 0xa128
movsbl %dl, %eax
jmp 0x5240
cmpl $0x0, 0x4de7(%rip)      # 0xa10c
movl 0x4(%rsp), %ebp
je 0x5341
cmpb $0x3a, (%r14)
je 0x5341
leaq 0x2590(%rip), %rdi      # 0x78c8
movl %ebp, %esi
xorl %eax, %eax
callq 0x4b84
movl %ebp, 0x4ded(%rip)      # 0xa134
xorl %eax, %eax
cmpb $0x3a, (%r14)
setne %al
leal (%rax,%rax,4), %edx
addl $0x3a, %edx
jmp 0x52ed