// File: /workspace/github_cpp_makefile_star2_O3/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, 0x10(%rsp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movl (%rdi), %eax
movl %eax, 0x4(%rsp)
movq $-0x1, %r14
movq $-0x4, %rbp
movq %rdx, %rax
incq %r14
addq $0x4, %rbp
cmpb $0x0, (%rax)
leaq 0x28(%rax), %rax
jne 0x9489
movq %rbp, %rdi
callq 0x33d0
movq %rax, %r15
testq %r14, %r14
je 0x94b6
movq %r15, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x3180
movq %r13, 0x20(%rsp)
movq %r15, 0x8(%rsp)
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x94ef
movl $0x10, %edi
callq 0x33d0
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movb $0x0, (%rax)
movl $0x0, 0x4(%rax)
movq $0x0, 0x8(%rax)
movl 0x4(%rsp), %r15d
cmpl $0x2, %r15d
jl 0x95ee
decl %r15d
movl $0x1, %ebp
movq %rbx, 0x18(%rsp)
movq (%r12), %rax
movslq %ebp, %r13
movq (%rax,%r13,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x95d7
movl $0x68, %esi
leaq 0x74a0(%rip), %rdx      # 0x109cb
callq 0x8ffd
testl %eax, %eax
je 0x968e
movq (%r12), %rax
movq (%rax,%r13,8), %rdi
movq %rbx, %rsi
callq 0x91a5
cmpl $-0x2, %eax
je 0x95d7
cmpl $-0x1, %eax
je 0x96cb
movslq %eax, %rcx
leaq (%rcx,%rcx,4), %rax
cmpl 0x18(%rbx,%rax,8), %r15d
jle 0x9708
movl %r15d, 0x4(%rsp)
leaq (%rbx,%rax,8), %r15
movq (%r12), %rax
leaq (%rax,%r13,8), %rsi
addq $0x8, %rsi
movq 0x10(%rsp), %rdi
movq %r15, %rdx
movq %rcx, %r13
callq 0x92bb
movq 0x8(%rsp), %rax
incl (%rax,%r13,4)
cmpl $0x0, 0x18(%r15)
js 0x95e7
xorl %eax, %eax
movq %r12, %rbx
movq 0x20(%rsp), %r12
movl %eax, %r13d
movq %r12, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x8ecf
leal 0x1(%r13), %eax
cmpl 0x18(%r15), %r13d
jl 0x95ab
movl 0x4(%rsp), %r15d
subl %eax, %r15d
movq %rbx, %r12
movq 0x18(%rsp), %rbx
jmp 0x95dc
decl %r15d
incl %ebp
testl %r15d, %r15d
jg 0x950b
jmp 0x95ee
movl 0x4(%rsp), %r15d
jmp 0x95dc
testq %r14, %r14
movq 0x8(%rsp), %rdi
je 0x962d
addq $0x14, %rbx
xorl %eax, %eax
movl -0x4(%rbx), %edx
movl (%rbx), %ecx
testl %edx, %edx
je 0x9612
testl %ecx, %ecx
jne 0x9616
cmpl %edx, (%rdi,%rax,4)
jge 0x9621
jmp 0x965b
testl %ecx, %ecx
je 0x9621
movl (%rdi,%rax,4), %esi
cmpl %edx, %esi
jl 0x965b
cmpl %ecx, %esi
jg 0x965b
incq %rax
addq $0x28, %rbx
cmpq %rax, %r14
jne 0x95fe
callq 0x3350
movl $0x0, 0xcf64(%rip)      # 0x165a0
movabsq $0x726f727265206f4e, %rax # imm = 0x726F727265206F4E
movq %rax, 0xcf63(%rip)      # 0x165b0
movb $0x0, 0xcf64(%rip)      # 0x165b8
xorl %eax, %eax
jmp 0x973d
callq 0x3350
movl $0xfffffffd, 0xcf36(%rip) # imm = 0xFFFFFFFD
movabsq $0x6e6f6974706f20, %rax # imm = 0x6E6F6974706F20
movq %rax, 0xcf44(%rip)      # 0x165bf
movups 0x7454(%rip), %xmm0     # 0x10ad6
movaps %xmm0, 0xcf27(%rip)     # 0x165b0
jmp 0x9738
movq 0x8(%rsp), %rdi
callq 0x3350
movl $0x1, 0xcefe(%rip)      # 0x165a0
movabsq $0x2079616c70736944, %rax # imm = 0x2079616C70736944
movq %rax, 0xcefd(%rip)      # 0x165b0
movabsq $0x706c6568207961, %rax # imm = 0x706C6568207961
movq %rax, 0xcef1(%rip)      # 0x165b5
movl $0x1, %eax
jmp 0x973d
movq 0x8(%rsp), %rdi
callq 0x3350
movl $0xfffffffe, 0xcec1(%rip) # imm = 0xFFFFFFFE
movabsq $0x206e776f6e6b6e55, %rax # imm = 0x206E776F6E6B6E55
movq %rax, 0xcec0(%rip)      # 0x165b0
movabsq $0x6e6f6974706f20, %rax # imm = 0x6E6F6974706F20
movq %rax, 0xceb6(%rip)      # 0x165b7
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x973d
movq 0x8(%rsp), %rdi
callq 0x3350
movl $0xfffffffd, 0xce84(%rip) # imm = 0xFFFFFFFD
movups 0x739a(%rip), %xmm0     # 0x10abd
movaps %xmm0, 0xce86(%rip)     # 0x165b0
movups 0x7395(%rip), %xmm0     # 0x10ac6
movups %xmm0, 0xce81(%rip)     # 0x165b9
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq