// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movl %edi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
cmpl $0x1, 0xff17(%rip)      # 0x13100
jne 0x31fd
movq $0x0, 0xff2a(%rip) # 0x13120
movb $0x0, 0xff2b(%rip)      # 0x13128
jmp 0x31ff
xorl %eax, %eax
testb $0x1, 0xff20(%rip)      # 0x13128
movb %al, 0x7(%rsp)
jne 0x3237
movb $0x1, %al
cmpq $0x0, 0xff08(%rip)      # 0x13120
movb %al, 0x6(%rsp)
jne 0x322f
movl 0xfedc(%rip), %eax      # 0x13100
cmpl 0x30(%rsp), %eax
setl %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x3244
jmp 0x3475
cmpq $0x0, 0xfed4(%rip)      # 0x13120
jne 0x32e4
movq 0x28(%rsp), %rax
movl 0xfea3(%rip), %ecx      # 0x13100
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xfe98(%rip)      # 0x13100
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x32df
movq 0x18(%rsp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x32df
movq 0x18(%rsp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x32cd
movq 0x18(%rsp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x32cd
movq 0x28(%rsp), %rax
movl 0xfe4a(%rip), %ecx      # 0x13100
subl $0x1, %ecx
movslq %ecx, %rcx
movq $0x0, (%rax,%rcx,8)
movb $0x1, 0xfe5d(%rip)      # 0x13128
jmp 0x32dd
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xfe43(%rip)      # 0x13120
jmp 0x32df
jmp 0x3470
movq 0xfe35(%rip), %rax      # 0x13120
movb (%rax), %al
movb %al, 0x17(%rsp)
movq 0x20(%rsp), %rdi
movsbl 0x17(%rsp), %esi
callq 0x10a0
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x3341
cmpl $0x0, 0xfdf0(%rip)      # 0x13104
je 0x3329
movsbl 0x17(%rsp), %esi
leaq 0xd678(%rip), %rdi      # 0x1099a
movb $0x0, %al
callq 0x2660
movsbl 0x17(%rsp), %eax
movl %eax, 0xfdf8(%rip)      # 0x1312c
movl $0x3f, 0x34(%rsp)
jmp 0x34da
movq 0xfdd8(%rip), %rax      # 0x13120
addq $0x1, %rax
movq %rax, 0xfdcd(%rip)      # 0x13120
movq 0x8(%rsp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3a, %eax
jne 0x3432
movq 0xfdb4(%rip), %rax      # 0x13120
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x3387
movq 0xfda5(%rip), %rax      # 0x13120
movq %rax, 0xfdae(%rip)      # 0x13130
jmp 0x3424
movl 0xfd73(%rip), %eax      # 0x13100
cmpl 0x30(%rsp), %eax
jge 0x33d2
movq 0x28(%rsp), %rax
movl 0xfd62(%rip), %ecx      # 0x13100
subl $0x1, %ecx
movslq %ecx, %rcx
movq $0x0, (%rax,%rcx,8)
movq 0x28(%rsp), %rax
movl 0xfd49(%rip), %ecx      # 0x13100
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xfd3e(%rip)      # 0x13100
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0xfd60(%rip)      # 0x13130
jmp 0x3422
cmpl $0x0, 0xfd2b(%rip)      # 0x13104
je 0x33fb
movq 0x20(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
je 0x33fb
movsbl 0x17(%rsp), %esi
leaq 0xd5bd(%rip), %rdi      # 0x109b1
movb $0x0, %al
callq 0x2660
movsbl 0x17(%rsp), %eax
movl %eax, 0xfd26(%rip)      # 0x1312c
movq 0x20(%rsp), %rax
movsbl (%rax), %edx
movl $0x3f, %eax
movl $0x3a, %ecx
cmpl $0x3a, %edx
cmovel %ecx, %eax
movb %al, 0x17(%rsp)
jmp 0x3424
leaq 0xfced(%rip), %rax      # 0x13118
movq %rax, 0xfcee(%rip)      # 0x13120
movq 0xfce7(%rip), %rax      # 0x13120
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x3465
movq 0x28(%rsp), %rax
movl 0xfcb4(%rip), %ecx      # 0x13100
subl $0x1, %ecx
movslq %ecx, %rcx
movq $0x0, (%rax,%rcx,8)
movq $0x0, 0xfcbb(%rip) # 0x13120
movsbl 0x17(%rsp), %eax
movl %eax, 0x34(%rsp)
jmp 0x34da
jmp 0x31ff
movl 0x30(%rsp), %eax
movl %eax, 0xfc81(%rip)      # 0x13100
movl 0x30(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x30(%rsp)
cmpl $0x0, %eax
jle 0x34cb
movq 0x28(%rsp), %rax
movslq 0x30(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x34c9
movq 0x28(%rsp), %rax
movslq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x28(%rsp), %rax
movl 0xfc47(%rip), %ecx      # 0x13100
addl $-0x1, %ecx
movl %ecx, 0xfc3e(%rip)      # 0x13100
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x347f
movb $0x1, 0xfc56(%rip)      # 0x13128
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)