// File: /workspace/github_c_makefile_star2_O1/DrYerzinia[P]C_DigiMode/src/util/argp.c
// Function: argp_parse
error_t argp_parse(struct argp *argp, int argc, char **argv, unsigned flags, int *arg_index,  void *input){

	struct argp_state state;

	state.input = input;

	int i;

	for(i = 1; i < argc; i++){

		if(argv[i][0] == '-'){

			if(argv[i][1] == '-'){

				struct argp_option *op = argp->options;

				int c = -1;

				while(*(uint8_t*)op != 0){

					c = argp_parse_argument(op->name, argv[i]);

					// If we found the option match the parameter
					if(c >= 0)
						break;

					op++;

				}

				if(c >= 0)
					argp->parser(op->key, &argv[i][c+3], &state);

				else {
					// Check if it is help
					c = argp_parse_argument("help", argv[i]);
					if(c >= 0){
						argp_print_help(argv[0], argp->options);
						return ARGP_ERR_HELP;
					} else {
						// Invalid Option
						fprintf(stderr, "%s: unrecognized option '%s'\nTry '%s --help' for more information.\n", argv[0], argv[i], argv[0]);
						return ARGP_ERR_UNKNOWN;
					}
				}

			} else {

				// single character option
				struct argp_option *op = argp->options;

				while(op->arg[0] != 0){

					if(op->key == argv[i][1] && argv[i][2] == '\0'){
						argp->parser(op->key, NULL, &state);
						break;
					}

					op++;

				}

			}

		}

		// Invalid Option
		else {
			return -1;
		}

	}

	return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, 0x10(%rsp)
movq %r9, 0x40(%rsp)
cmpl $0x2, %esi
jl 0x2175
movq %rdx, %r12
movl %esi, %r14d
movl $0x1, %ebp
movq %r14, 0x8(%rsp)
movq (%r12,%rbp,8), %r13
cmpb $0x2d, (%r13)
jne 0x217f
movsbl 0x1(%r13), %eax
movq 0x10(%rsp), %rcx
movq (%rcx), %rbx
cmpl $0x2d, %eax
jne 0x2092
movq %r12, %r14
cmpb $0x0, (%rbx)
je 0x20c3
movq %rbx, %r12
movq (%r12), %rdi
movq %r13, %rsi
callq 0x219a
movl %eax, %r15d
testl %eax, %eax
jns 0x20ce
leaq 0x30(%r12), %rax
cmpb $0x0, 0x30(%r12)
movq %rax, %r12
jne 0x206d
jmp 0x20d1
movq 0x10(%rbx), %rcx
cmpb $0x0, (%rcx)
je 0x212a
addq $0x40, %rbx
movl -0x38(%rbx), %edi
cmpl %eax, %edi
jne 0x20b5
cmpb $0x0, 0x2(%r13)
je 0x2138
movq (%rbx), %rcx
addq $0x30, %rbx
cmpb $0x0, (%rcx)
jne 0x20a3
jmp 0x212a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %rbx, %rax
jmp 0x20d1
movq %r12, %rax
testl %r15d, %r15d
js 0x20f6
movl 0x8(%rax), %edi
movl %r15d, %eax
leaq (%rax,%r13), %rsi
addq $0x3, %rsi
leaq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rax
callq *0x8(%rax)
movq %r14, %r12
jmp 0x2120
leaq 0x125f(%rip), %rdi      # 0x335c
movq %r13, %rsi
callq 0x219a
testl %eax, %eax
movq %r14, %r12
js 0x2149
movq (%r12), %rdi
movq %rbx, %rsi
callq 0x21dd
movl $0xfffffffe, 0x4(%rsp)  # imm = 0xFFFFFFFE
movq 0x8(%rsp), %r14
testl %r15d, %r15d
js 0x2187
incq %rbp
cmpq %r14, %rbp
jne 0x2041
jmp 0x2175
xorl %esi, %esi
leaq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rax
callq *0x8(%rax)
jmp 0x212a
movq 0x2ea8(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq (%r12), %rdx
leaq 0x1203(%rip), %rsi      # 0x3361
movq %r13, %rcx
movq %rdx, %r8
xorl %eax, %eax
callq 0x10d0
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
jmp 0x2120
movl $0x0, 0x4(%rsp)
jmp 0x2187
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl 0x4(%rsp), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq