// File: /workspace/github_c_makefile_star2_O2/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)
leaq 0x10(%rdi), %r12
movw $0x20, %r13w
movq (%r12), %rbp
testq %rbp, %rbp
je 0x5712
movq 0x680(%rbp), %rax
testq %rax, %rax
je 0x56a0
cmpb $0x0, (%rax)
je 0x56a0
movq %r15, %rdi
callq 0x3190
movw $0x2d2d, (%r15,%rax)    # imm = 0x2D2D
movb $0x0, 0x2(%r15,%rax)
movq 0x10(%rbp), %rsi
movq %r15, %rdi
callq 0x3510
movq %r15, %rdi
callq 0x3190
movw %r13w, (%r15,%rax)
movq 0x680(%rbp), %rsi
movq %r15, %rdi
callq 0x3510
movq %r15, %rdi
callq 0x3190
movw %r13w, (%r15,%rax)
addq $0x8, %r12
jmp 0x5638
callq 0x35d0
testb %bpl, %bpl
je 0x5712
movq (%rax), %rcx
movsbq %bpl, %rdx
testb $0x20, 0x1(%rcx,%rdx,2)
je 0x56cb
movb $0x0, (%r15)
movb 0x1(%r15), %bpl
incq %r15
jmp 0x56ab
movslq 0xb70(%rbx), %rcx
cmpq $0xc8, %rcx
jge 0x57a4
leal 0x1(%rcx), %edx
movl %edx, 0xb70(%rbx)
movq %r15, 0xb78(%rbx,%rcx,8)
movq %r15, %rcx
movsbq (%r15), %rdx
testq %rdx, %rdx
je 0x570f
movq (%rax), %rsi
leaq 0x1(%rcx), %r15
testb $0x20, 0x1(%rsi,%rdx,2)
je 0x56f0
movb $0x0, (%rcx)
jmp 0x5712
movq %rcx, %r15
movb (%r15), %bpl
testb %bpl, %bpl
jne 0x56a6
movslq 0x4(%rsp), %rax
pushq $0x1
popq %rcx
cmpq %rax, %rcx
jge 0x5751
movslq 0xb70(%rbx), %rdx
cmpq $0xc8, %rdx
jge 0x5785
movq (%r14,%rcx,8), %rsi
leal 0x1(%rdx), %edi
movl %edi, 0xb70(%rbx)
movq %rsi, 0xb78(%rbx,%rdx,8)
incq %rcx
jmp 0x5722
andl $0x0, 0x11c0(%rbx)
andq $0x0, 0x338(%rbx)
andq $0x0, 0x348(%rbx)
andl $0x0, 0x670(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5312
leaq 0xdcab(%rip), %rdi      # 0x13437
leaq 0xdbc1(%rip), %rsi      # 0x13354
leaq 0xdcc4(%rip), %rcx      # 0x1345e
movl $0x1d4, %edx            # imm = 0x1D4
callq 0x3200
leaq 0xdc8c(%rip), %rdi      # 0x13437
leaq 0xdba2(%rip), %rsi      # 0x13354
leaq 0xdca5(%rip), %rcx      # 0x1345e
movl $0x1c9, %edx            # imm = 0x1C9
callq 0x3200