// File: /workspace/github_cpp_makefile_star2_O2/pelrun[P]aft/optionParser.c
// Function: parseCommandLineOption
int parseCommandLineOption(int *argc, char*** argv, struct SOption *option, struct SOptionOut **cmdOptionLine)
{


	int o,i;
	int nbOption=0;
	int *nbValOption;

	int nbArg = (*argc)-1;
	int iArgv = 1;

	//compte nb d'options
	while(option[nbOption].shortName != 0)
		nbOption++;

	//reserve memoire pour compter le nombre de valeur des options
	nbValOption = (int*)malloc(nbOption*sizeof(int));
	for (o=0;o<nbOption;o++)
	{
		nbValOption[o]=0;
	}

	//Securisation
	if ((*cmdOptionLine) == NULL)
	{
		*cmdOptionLine = (struct SOptionOut*)malloc(sizeof(struct SOptionOut));
		(*cmdOptionLine)[0].shortName=0;
		(*cmdOptionLine)[0].argc=0;
		(*cmdOptionLine)[0].argv=NULL;
	}


	//Lecture de la liste des arguments
	while (nbArg>0)
	{
		if (isOptionString((*argv)[iArgv]) != 0)
		{
			//verification si aide
			if (compareOptionString((*argv)[iArgv],'h',"help") == OPT_NO_ERROR)
			{
				free(nbValOption);
				RET_ERROR(DISPLAY_HELP, "Display help");
			}

			//recuperation option
			o = findOption((*argv)[iArgv],option);
			if (o == ERROR_UNKNOWN)
			{
				free(nbValOption);
				RET_ERROR( ERROR_UNKOPT, "Unknown option");
			}
			if (o == ERROR_UNKOPT)
			{
				// Begin like an option, but doesn't seems to be one
				nbArg--;
				iArgv++;
			}
			else
			{
				//option connue
				
				//verification nombre d'arguments minimum necessaires pour l'option
				if (nbArg <= option[o].nbArgs)
				{
					free(nbValOption);
					RET_ERROR( ERROR_OPTARG, "Wrong number of argument");
				}

				//ajout de l'option
				addOption(cmdOptionLine,&((*argv)[iArgv+1]),&option[o]);
	
				//consideration de la presence de cette option
				nbValOption[o]++;

				//suppression des arguments lus
				for (i=0;i<option[o].nbArgs + 1;i++)
				{
					removeArgv(argc,argv,iArgv);
					nbArg--;
				}
			}
		}
		else
		{
			//lecture d'une non option
			nbArg--;
			iArgv++;
		}
	}
	for (o=0;o<nbOption;o++)
	{
		if (!(option[o].nbMin == 0 && option[o].nbMax == 0))
		{
			if (option[o].nbMax != 0)
			{
				if (!((nbValOption[o] >= option[o].nbMin) && (nbValOption[o] <= option[o].nbMax)))
				{
					free(nbValOption);
					RET_ERROR( ERROR_OPTARG, "Wrong number of option");
				}
			}
			else
			{
				if (!(nbValOption[o] >= option[o].nbMin))
				{
					free(nbValOption);
					RET_ERROR( ERROR_OPTARG, "Wrong number of option");
				}
			}
		}
	}
	free(nbValOption);
	RET_ERROR(OPT_NO_ERROR, "No error");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r13
movl (%rdi), %r15d
pushq $-0x1
popq %rbx
pushq $-0x4
popq %rdi
movq %rdx, %rax
incq %rbx
addq $0x4, %rdi
cmpb $0x0, (%rax)
leaq 0x28(%rax), %rax
jne 0x7ffd
callq 0x33a0
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x8022
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x8014
movq %rax, (%rsp)
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x804d
pushq $0x10
popq %rdi
callq 0x33a0
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movb $0x0, (%rax)
andl $0x0, 0x4(%rax)
andq $0x0, 0x8(%rax)
pushq $0x1
popq %rbp
movq %r14, 0x20(%rsp)
decl %r15d
movslq %ebp, %rax
movq %rax, 0x10(%rsp)
testl %r15d, %r15d
jle 0x8132
movq (%r12), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x812b
pushq $0x68
popq %rsi
leaq 0x691f(%rip), %rdx      # 0xe9a8
callq 0x7bba
testl %eax, %eax
je 0x817e
movq (%r12), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq %r14, %rsi
callq 0x7d58
cmpl $-0x2, %eax
je 0x812b
cmpl $-0x1, %eax
je 0x81ba
movq %r14, %rcx
movslq %eax, %r14
movl %r15d, %eax
imulq $0x28, %r14, %r15
movl %eax, 0x1c(%rsp)
cmpl 0x18(%rcx,%r15), %eax
jle 0x81f6
addq %rcx, %r15
movq (%r12), %rax
movq 0x10(%rsp), %rcx
leaq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
movq 0x8(%rsp), %rdi
movq %r15, %rdx
callq 0x7e56
movq (%rsp), %rax
incl (%rax,%r14,4)
xorl %r14d, %r14d
cmpl 0x18(%r15), %r14d
jg 0x8119
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x7a99
incl %r14d
jmp 0x8101
movl 0x1c(%rsp), %r15d
subl %r14d, %r15d
movq 0x20(%rsp), %r14
jmp 0x8060
incl %ebp
jmp 0x8055
addq $0x14, %r14
xorl %eax, %eax
movq (%rsp), %rdi
cmpq %rax, %rbx
je 0x8227
movl -0x4(%r14), %edx
movl (%r14), %ecx
testl %edx, %edx
je 0x815e
testl %ecx, %ecx
jne 0x8162
cmpl %edx, (%rdi,%rax,4)
jge 0x8175
jmp 0x824f
testl %ecx, %ecx
je 0x8175
movl (%rdi,%rax,4), %esi
cmpl %edx, %esi
jl 0x824f
cmpl %ecx, %esi
jg 0x824f
incq %rax
addq $0x28, %r14
jmp 0x813c
movq (%rsp), %rdi
callq 0x3320
movl $0x1, 0xc40f(%rip)      # 0x145a0
movabsq $0x2079616c70736944, %rax # imm = 0x2079616C70736944
movq %rax, 0xc40e(%rip)      # 0x145b0
movabsq $0x706c6568207961, %rax # imm = 0x706C6568207961
movq %rax, 0xc402(%rip)      # 0x145b5
pushq $0x1
jmp 0x827f
movq (%rsp), %rdi
callq 0x3320
movl $0xfffffffe, 0xc3d3(%rip) # imm = 0xFFFFFFFE
movabsq $0x206e776f6e6b6e55, %rax # imm = 0x206E776F6E6B6E55
movq %rax, 0xc3d2(%rip)      # 0x145b0
movabsq $0x6e6f6974706f20, %rax # imm = 0x6E6F6974706F20
movq %rax, 0xc3c8(%rip)      # 0x145b7
pushq $-0x2
jmp 0x827f
movq (%rsp), %rdi
callq 0x3320
movl $0xfffffffd, 0xc397(%rip) # imm = 0xFFFFFFFD
movups 0x688a(%rip), %xmm0     # 0xea9a
movaps %xmm0, 0xc399(%rip)     # 0x145b0
movups 0x6885(%rip), %xmm0     # 0xeaa3
movups %xmm0, 0xc394(%rip)     # 0x145b9
jmp 0x827d
callq 0x3320
andl $0x0, 0xc36d(%rip)      # 0x145a0
movabsq $0x726f727265206f4e, %rax # imm = 0x726F727265206F4E
movq %rax, 0xc36c(%rip)      # 0x145b0
movb $0x0, 0xc36d(%rip)      # 0x145b8
xorl %eax, %eax
jmp 0x8280
callq 0x3320
movl $0xfffffffd, 0xc342(%rip) # imm = 0xFFFFFFFD
movabsq $0x6e6f6974706f20, %rax # imm = 0x6E6F6974706F20
movq %rax, 0xc350(%rip)      # 0x145bf
movups 0x683d(%rip), %xmm0     # 0xeab3
movaps %xmm0, 0xc333(%rip)     # 0x145b0
pushq $-0x3
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq