// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x48(%rbp)
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xdb94
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xdb72
movslq -0x34(%rbp), %rdi
shlq $0x2, %rdi
callq 0x44b0
movq %rax, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xdbce
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xdbac
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xdc13
movl $0x10, %edi
callq 0x44b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movb $0x0, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq $0x0, 0x8(%rax)
jmp 0xdc15
cmpl $0x0, -0x44(%rbp)
jle 0xdded
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xd490
cmpl $0x0, %eax
je 0xddd6
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl $0x68, %esi
leaq 0x7d70(%rip), %rdx      # 0x159c7
callq 0xd4b0
cmpl $0x0, %eax
jne 0xdc93
movq -0x40(%rbp), %rdi
callq 0x4420
movl $0x1, 0xd9ac(%rip)      # 0x1b620
leaq 0xd9b5(%rip), %rdi      # 0x1b630
leaq 0x7d3d(%rip), %rsi      # 0x159bf
callq 0x42c0
movl $0x1, -0x4(%rbp)
jmp 0xdf44
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x20(%rbp), %rsi
callq 0xd720
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0xdce6
movq -0x40(%rbp), %rdi
callq 0x4420
movl $0xfffffffe, 0xd959(%rip) # imm = 0xFFFFFFFE
leaq 0xd962(%rip), %rdi      # 0x1b630
leaq 0x7d9b(%rip), %rsi      # 0x15a70
callq 0x42c0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0xdf44
cmpl $-0x2, -0x2c(%rbp)
jne 0xdd03
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xddd4
movl -0x44(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
jg 0xdd4c
movq -0x40(%rbp), %rdi
callq 0x4420
movl $0xfffffffd, 0xd8f3(%rip) # imm = 0xFFFFFFFD
leaq 0xd8fc(%rip), %rdi      # 0x1b630
leaq 0x7d7e(%rip), %rsi      # 0x15ab9
callq 0x42c0
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0xdf44
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movl -0x48(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x3, %rax
addq %rax, %rsi
movq -0x20(%rbp), %rdx
movslq -0x2c(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdx
callq 0xd8d0
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0xddd2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x48(%rbp), %edx
callq 0xd2d0
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xdd92
jmp 0xddd4
jmp 0xdde8
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xdc15
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xdf17
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x10(%rax)
jne 0xde2e
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x14(%rax)
je 0xdf07
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x14(%rax)
je 0xdeb5
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jl 0xde81
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
jle 0xdeb3
movq -0x40(%rbp), %rdi
callq 0x4420
movl $0xfffffffd, 0xd78c(%rip) # imm = 0xFFFFFFFD
leaq 0xd795(%rip), %rdi      # 0x1b630
leaq 0x7c30(%rip), %rsi      # 0x15ad2
callq 0x42c0
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0xdf44
jmp 0xdf05
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jge 0xdf03
movq -0x40(%rbp), %rdi
callq 0x4420
movl $0xfffffffd, 0xd739(%rip) # imm = 0xFFFFFFFD
leaq 0xd742(%rip), %rdi      # 0x1b630
leaq 0x7bdd(%rip), %rsi      # 0x15ad2
callq 0x42c0
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0xdf44
jmp 0xdf05
jmp 0xdf07
jmp 0xdf09
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xddf4
movq -0x40(%rbp), %rdi
callq 0x4420
movl $0x0, 0xd6f6(%rip)      # 0x1b620
leaq 0xd6ff(%rip), %rdi      # 0x1b630
leaq 0x7b2f(%rip), %rsi      # 0x15a67
callq 0x42c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)