// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x785, %rax            # imm = 0x785
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x6603
movq -0x30(%rbp), %rax
cmpq $0x0, 0x680(%rax)
je 0x65f3
movq -0x30(%rbp), %rax
movq 0x680(%rax), %rdi
callq 0x3190
cmpq $0x0, %rax
je 0x65f3
movq -0x28(%rbp), %rdi
leaq 0x14e5f(%rip), %rsi     # 0x1b408
callq 0x3500
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x3500
movq -0x28(%rbp), %rdi
leaq 0x1719a(%rip), %rsi     # 0x1d764
callq 0x3500
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x680(%rax), %rsi
callq 0x3500
movq -0x28(%rbp), %rdi
leaq 0x17176(%rip), %rsi     # 0x1d764
callq 0x3500
jmp 0x65f5
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x655f
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, (%rax)
je 0x6742
jmp 0x661a
movq -0x38(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x39(%rbp)
je 0x664f
callq 0x35c0
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x6658
jmp 0x666c
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x0, (%rax)
jmp 0x661a
movq -0x38(%rbp), %rax
cmpb $0x0, (%rax)
je 0x673d
movq -0x8(%rbp), %rax
cmpl $0xc8, 0xb70(%rax)
jge 0x668b
jmp 0x66aa
leaq 0x14d79(%rip), %rdi     # 0x1b40b
leaq 0x14c8f(%rip), %rsi     # 0x1b328
movl $0x1c9, %edx            # imm = 0x1C9
leaq 0x14d8d(%rip), %rcx     # 0x1b432
callq 0x3200
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rsi
movl 0xb70(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0xb70(%rsi)
movslq %ecx, %rcx
movq %rdx, 0xb78(%rax,%rcx,8)
movq -0x38(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3a(%rbp)
je 0x6709
callq 0x35c0
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
testb $0x1, %al
jne 0x6712
jmp 0x6720
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x66d2
movq -0x38(%rbp), %rax
cmpb $0x0, (%rax)
je 0x673b
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x0, (%rax)
jmp 0x673d
jmp 0x660b
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x67bd
movq -0x8(%rbp), %rax
cmpl $0xc8, 0xb70(%rax)
jge 0x6763
jmp 0x6782
leaq 0x14ca1(%rip), %rdi     # 0x1b40b
leaq 0x14bb7(%rip), %rsi     # 0x1b328
movl $0x1d4, %edx            # imm = 0x1D4
leaq 0x14cb5(%rip), %rcx     # 0x1b432
callq 0x3200
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rsi
movl 0xb70(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0xb70(%rsi)
movslq %ecx, %rcx
movq %rdx, 0xb78(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6749
movq -0x8(%rbp), %rax
movl $0x0, 0x11c0(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x338(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x348(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x670(%rax)
movq -0x8(%rbp), %rdi
callq 0x5f60
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)