// File: Alcaro[P]bridges/arlib/argparse.cpp
// Function: argparse::parse(char const* const*)
void argparse::parse(const char * const * argv)
{
	parse_pre(argv);
	
	argv++;
	while (*argv)
	{
		const char * arg = *argv;
		argv++;
		if (arg[0] == '-')
		{
			if (arg[1] == '-')
			{
				if (arg[2] == '\0')
				{
					// just --
					while (*argv)
					{
						single_arg("", *argv, al_mandatory, NULL);
						argv++;
					}
				}
				else
				{
					// -- followed by something
					
					// +3 to skip the --, and the first actual character, otherwise '--=derp' would derp out
					const char * eq = strchr(arg+3, '=');
					if (eq)
					{
						single_arg(arrayview<char>(arg+2, eq-(arg+2)), eq+1, al_mandatory, NULL);
					}
					else
					{
						bool used;
						single_arg(arg+2, *argv, al_loose, &used);
						if (used) argv++;
					}
				}
			}
			else if (arg[1] == '\0')
			{
				// a lone -
				single_arg("", "-", al_mandatory, NULL);
			}
			else
			{
				// - followed by something
				arg++;
				while (*arg)
				{
					if (arg[1])
					{
						// -ab (*arg is 'a', argument is "b")
						bool used;
						single_arg(*arg, arg+1, al_tight, &used);
						if (used) break;
					}
					else
					{
						// -a b (*arg is 'a', next is "b")
						bool used;
						single_arg(*arg, *argv, al_loose, &used);
						if (used) argv++;
					}
					arg++;
				}
			}
		}
		else
		{
			// no leading -
			single_arg("", arg, al_mandatory, NULL);
			if (m_early_stop)
			{
				while (*argv)
				{
					single_arg("", *argv, al_mandatory, NULL);
					argv++;
				}
			}
		}
	}
	
	parse_post();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
movq -0x10(%rbp), %rsi
callq 0x5140
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x54ec
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x5441
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x5353
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x528b
jmp 0x5238
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x5286
leaq -0x28(%rbp), %rdi
leaq 0x611fc(%rip), %rsi     # 0x66449
callq 0x58c0
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x3, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x4ec0
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x5238
jmp 0x534e
movq -0x18(%rbp), %rdi
addq $0x3, %rdi
movl $0x3d, %esi
callq 0x40e0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5302
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
addq $0x2, %rax
subq %rax, %rdx
leaq -0x50(%rbp), %rdi
callq 0x5b70
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x5bb0
movq -0xa8(%rbp), %rdi
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x3, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x4ec0
jmp 0x534c
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
leaq -0x68(%rbp), %rdi
callq 0x58c0
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl $0x1, %r8d
leaq -0x51(%rbp), %r9
callq 0x4ec0
testb $0x1, -0x51(%rbp)
je 0x534a
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x534c
jmp 0x534e
jmp 0x543c
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x539b
leaq -0x78(%rbp), %rdi
leaq 0x610de(%rip), %rsi     # 0x66449
callq 0x58c0
movq -0xa8(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
leaq 0x5dd5f(%rip), %rcx     # 0x630e5
movl $0x3, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x4ec0
jmp 0x543a
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0x5438
movq -0x18(%rbp), %rax
cmpb $0x0, 0x1(%rax)
je 0x53ee
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rax
movb (%rax), %al
movq -0x18(%rbp), %rdx
addq $0x1, %rdx
movl $0x2, %ecx
leaq -0x79(%rbp), %r8
movsbl %al, %esi
callq 0x5020
testb $0x1, -0x79(%rbp)
je 0x53ec
jmp 0x5438
jmp 0x5427
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rax
movb (%rax), %al
movq -0x10(%rbp), %rcx
movq (%rcx), %rdx
movl $0x1, %ecx
leaq -0x7a(%rbp), %r8
movsbl %al, %esi
callq 0x5020
testb $0x1, -0x7a(%rbp)
je 0x5425
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x5427
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x53a7
jmp 0x543a
jmp 0x543c
jmp 0x54e7
leaq -0x90(%rbp), %rdi
leaq 0x60ffa(%rip), %rsi     # 0x66449
callq 0x58c0
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movl $0x3, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x4ec0
movq -0xa8(%rbp), %rax
testb $0x1, 0x38(%rax)
je 0x54e5
jmp 0x548c
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x54e3
leaq -0xa0(%rbp), %rdi
leaq 0x60fa5(%rip), %rsi     # 0x66449
callq 0x58c0
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movl $0x3, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x4ec0
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x548c
jmp 0x54e5
jmp 0x54e7
jmp 0x51e3
movq -0xa8(%rbp), %rdi
callq 0x5510
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)