// File: /workspace/github_c_makefile_star2_O1/j-hoppe[P]tu58fs/getopt2.c
// Function: getopt_first
int getopt_first(getopt_t *_this, int argc, char **argv)
{
	int	i;
	char	*cb = _this->default_cmdline_buff; // alias
	getopt_option_descr_t *odesc;
	char	*token;

	// for all options with "default" args:
	// put strings <option> <args> in front of commandline,
	// so they are parsed first and overwritten later by actual values
	// 1) build own cmdline
	*cb = 0; // clear
	for (i = 0; (odesc = _this->option_descrs[i]); i++)
		if (odesc->default_args && strlen(odesc->default_args)) {
			strcat(cb, "--");
			strcat(cb, odesc->long_name);
			strcat(cb, " ");
			strcat(cb, odesc->default_args);
			strcat(cb, " ");
		}
	// 2) separate into words and add to argv
	// Input in cb like : char space char char space space char char char space 0
	token = cb;
	while (*token) {
		// last token terminated with 0.
		// clear white space before next token
		while (*token && isspace(*token)) *token++ = 0;
		if (*token) {
			// add to arg list
			assert(_this->argc < GETOPT_MAX_CMDLINE_TOKEN);
			_this->argv[_this->argc++] = token;
			// skip and terminate token
			while (*token && !isspace(*token)) token++;
			if (*token) // convert terminating space to 0
				*token++ = 0;
		}
	}

	// 3) append user commandline tokens, so they are processed after defaults
	for (i = 1; i < argc; i++) { // skip program name of
		assert(_this->argc < GETOPT_MAX_CMDLINE_TOKEN);
		_this->argv[_this->argc++] = argv[i];
	}

	_this->cur_cline_arg_idx = 0;
	_this->cur_option = NULL;
	_this->cur_option_argval[0] = NULL;
	_this->cur_option_argvalcount = 0;

	return getopt_next(_this);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
leaq 0x785(%rdi), %r15
movb $0x0, 0x785(%rdi)
movq 0x10(%rdi), %rbp
testq %rbp, %rbp
je 0x59cd
leaq 0x18(%rbx), %r12
movw $0x20, %r13w
movq 0x680(%rbp), %rax
testq %rax, %rax
je 0x5906
cmpb $0x0, (%rax)
je 0x5906
movq %r15, %rdi
callq 0x31a0
movw $0x2d2d, (%r15,%rax)    # imm = 0x2D2D
movb $0x0, 0x2(%r15,%rax)
movq 0x10(%rbp), %rsi
movq %r15, %rdi
callq 0x3520
movq %r15, %rdi
callq 0x31a0
movw %r13w, (%r15,%rax)
movq 0x680(%rbp), %rsi
movq %r15, %rdi
callq 0x3520
movq %r15, %rdi
callq 0x31a0
movw %r13w, (%r15,%rax)
movq (%r12), %rbp
addq $0x8, %r12
testq %rbp, %rbp
jne 0x58ab
jmp 0x59cd
movsbq (%r15), %r12
testq %r12, %r12
sete %bpl
je 0x59cd
callq 0x35e0
movq (%rax), %rcx
testb $0x20, 0x1(%rcx,%r12,2)
je 0x595e
incq %r15
movb $0x0, -0x1(%r15)
movsbq (%r15), %rcx
testq %rcx, %rcx
sete %bpl
je 0x59cd
movq (%rax), %rdx
incq %r15
testb $0x20, 0x1(%rdx,%rcx,2)
jne 0x593c
decq %r15
testb %bpl, %bpl
jne 0x59cd
movslq 0xb70(%rbx), %rax
cmpq $0xc8, %rax
jge 0x5a82
leal 0x1(%rax), %ecx
movl %ecx, 0xb70(%rbx)
movq %r15, 0xb78(%rbx,%rax,8)
movsbq (%r15), %r12
testq %r12, %r12
sete %bpl
je 0x59cd
callq 0x35e0
movq (%rax), %rax
testb $0x20, 0x1(%rax,%r12,2)
jne 0x59c1
incq %r15
movsbq (%r15), %rcx
testq %rcx, %rcx
sete %bpl
je 0x59cd
incq %r15
testb $0x20, 0x1(%rax,%rcx,2)
je 0x59a7
decq %r15
testb %bpl, %bpl
jne 0x59cd
movb $0x0, (%r15)
incq %r15
cmpb $0x0, (%r15)
jne 0x5918
movl 0x4(%rsp), %ecx
cmpl $0x2, %ecx
jl 0x5a31
movslq 0xb70(%rbx), %rsi
cmpl $0xc9, %esi
movl $0xc8, %eax
cmovgel %esi, %eax
subl %esi, %eax
incl %eax
movl %ecx, %ecx
decq %rax
decq %rcx
leaq (%rbx,%rsi,8), %rdx
addq $0xb78, %rdx            # imm = 0xB78
incl %esi
xorl %edi, %edi
cmpq %rdi, %rax
je 0x5a63
movq 0x8(%r14,%rdi,8), %r8
leal (%rsi,%rdi), %r9d
movl %r9d, 0xb70(%rbx)
movq %r8, (%rdx,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x5a10
xorl %eax, %eax
movl %eax, 0x11c0(%rbx)
movq %rax, 0x338(%rbx)
movq %rax, 0x348(%rbx)
movl %eax, 0x670(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x544c
leaq 0xe9bb(%rip), %rdi      # 0x14425
leaq 0xe8d1(%rip), %rsi      # 0x14342
leaq 0xe9d4(%rip), %rcx      # 0x1444c
movl $0x1d4, %edx            # imm = 0x1D4
callq 0x3210
leaq 0xe99c(%rip), %rdi      # 0x14425
leaq 0xe8b2(%rip), %rsi      # 0x14342
leaq 0xe9b5(%rip), %rcx      # 0x1444c
movl $0x1c9, %edx            # imm = 0x1C9
callq 0x3210