// File: chhylp123[P]hifiasm/./ketopt.h
// Function: ketopt(ketopt_t*, int, char**, int, char const*, ko_longopt_t const*)
static int ketopt(ketopt_t *s, int argc, char *argv[], int permute, const char *ostr, const ko_longopt_t *longopts)
{
	int opt = -1, i0, j;
	if (permute) {
		while (s->i < argc && (argv[s->i][0] != '-' || argv[s->i][1] == '\0'))
			++s->i, ++s->n_args;
	}
	s->arg = 0, s->longidx = -1, i0 = s->i;
	if (s->i >= argc || argv[s->i][0] != '-' || argv[s->i][1] == '\0') {
		s->ind = s->i - s->n_args;
		return -1;
	}
	if (argv[s->i][0] == '-' && argv[s->i][1] == '-') { /* "--" or a long option */
		if (argv[s->i][2] == '\0') { /* a bare "--" */
			ketopt_permute(argv, s->i, s->n_args);
			++s->i, s->ind = s->i - s->n_args;
			return -1;
		}
		s->opt = 0, opt = '?', s->pos = -1;
		if (longopts) { /* parse long options */
			int k, n_exact = 0, n_partial = 0;
			const ko_longopt_t *o = 0, *o_exact = 0, *o_partial = 0;
			for (j = 2; argv[s->i][j] != '\0' && argv[s->i][j] != '='; ++j) {} /* find the end of the option name */
			for (k = 0; longopts[k].name != 0; ++k)
				if (strncmp(&argv[s->i][2], longopts[k].name, j - 2) == 0) {
					if (longopts[k].name[j - 2] == 0) ++n_exact, o_exact = &longopts[k];
					else ++n_partial, o_partial = &longopts[k];
				}
			if (n_exact > 1 || (n_exact == 0 && n_partial > 1)) return '?';
			o = n_exact == 1? o_exact : n_partial == 1? o_partial : 0;
			if (o) {
				s->opt = opt = o->val, s->longidx = o - longopts;
				if (argv[s->i][j] == '=') s->arg = &argv[s->i][j + 1];
				if (o->has_arg == 1 && argv[s->i][j] == '\0') {
					if (s->i < argc - 1) s->arg = argv[++s->i];
					else opt = ':'; /* missing option argument */
				}
			}
		}
	} else { /* a short option */
		const char *p;
		if (s->pos == 0) s->pos = 1;
		opt = s->opt = argv[s->i][s->pos++];
		p = strchr((char*)ostr, opt);
		if (p == 0) {
			opt = '?'; /* unknown option */
		} else if (p[1] == ':') {
			if (argv[s->i][s->pos] == 0) {
				if (s->i < argc - 1) s->arg = argv[++s->i];
				else opt = ':'; /* missing option argument */
			} else s->arg = &argv[s->i][s->pos];
			s->pos = -1;
		}
	}
	if (s->pos < 0 || argv[s->i][s->pos] == 0) {
		++s->i, s->pos = 0;
		if (s->n_args > 0) /* permute */
			for (j = i0; j < s->i; ++j)
				ketopt_permute(argv, j, s->n_args);
	}
	s->ind = s->i - s->n_args;
	return opt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x24(%rbp)
je 0x6718
jmp 0x66a0
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x71(%rbp)
jge 0x66f1
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x2d, %ecx
movb %al, -0x72(%rbp)
jne 0x66eb
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x66fa
jmp 0x6716
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
jmp 0x66a0
jmp 0x6718
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x14(%rbp), %eax
jge 0x6776
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x6776
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x6796
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x10(%rbp), %rax
subl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6c85
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x6ae2
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x6ae2
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x682c
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edx
callq 0x72e0
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x10(%rbp), %rax
subl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6c85
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
movl $0x3f, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
cmpq $0x0, -0x38(%rbp)
je 0x6add
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x2, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x73(%rbp)
je 0x68c4
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
setne %al
movb %al, -0x73(%rbp)
movb -0x73(%rbp), %al
testb $0x1, %al
jne 0x68cd
jmp 0x68da
jmp 0x68cf
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x6881
movl $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x69a3
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x2, %rdi
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movl -0x44(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rdx
callq 0x20c0
cmpl $0x0, %eax
jne 0x6993
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x6975
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
jmp 0x6991
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
jmp 0x6993
jmp 0x6995
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x68e1
cmpl $0x1, -0x4c(%rbp)
jg 0x69b5
cmpl $0x0, -0x4c(%rbp)
jne 0x69c1
cmpl $0x1, -0x50(%rbp)
jle 0x69c1
movl $0x3f, -0x4(%rbp)
jmp 0x6c85
cmpl $0x1, -0x4c(%rbp)
jne 0x69d1
movq -0x60(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x69fa
cmpl $0x1, -0x50(%rbp)
jne 0x69e4
movq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x69ef
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x69ef
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x6adb
movq -0x58(%rbp), %rax
movl 0xc(%rax), %ecx
movl %ecx, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
sarq $0x4, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
jne 0x6a76
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movl -0x44(%rbp), %eax
addl $0x1, %eax
cltq
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x6ad9
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x6ad9
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x6ad0
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rdx
movl 0x14(%rdx), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x6ad7
movl $0x3a, -0x3c(%rbp)
jmp 0x6ad9
jmp 0x6adb
jmp 0x6add
jmp 0x6bea
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x6af7
movq -0x10(%rbp), %rax
movl $0x1, 0x18(%rax)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rdx
movl 0x18(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x18(%rdx)
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl %eax, 0x4(%rcx)
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x2080
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x6b4a
movl $0x3f, -0x3c(%rbp)
jmp 0x6be8
movq -0x70(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x3a, %eax
jne 0x6be6
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x6bb8
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x6baf
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rdx
movl 0x14(%rdx), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x6bb6
movl $0x3a, -0x3c(%rbp)
jmp 0x6bdb
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
jmp 0x6be8
jmp 0x6bea
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jl 0x6c15
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x6c6b
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jle 0x6c69
movl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x6c67
movq -0x20(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edx
callq 0x72e0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x6c3d
jmp 0x6c69
jmp 0x6c6b
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x10(%rbp), %rax
subl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)