// File: /workspace/github_c_makefile_star2_O2/stefpant[P]TCPserver/webserver/input_parse.c
// Function: input_parse
int input_parse(int argc,char* argv[],int* s_port,int* c_port,int* n_threads,char** rootdir){
	int i;
	int flag1=0,flag2=0,flag3=0;
	for(i=1;i<argc;i++){
		if(strcmp(argv[i],"-d")==0){//then next argument must be the input file
			if(++i==argc){//error if nothing next
				printf("Missing input file...\n");
				return -2;
			}
			//needs the '-i' argument to success else we haven't got the input file
			//and return failure
			flag1++;
			int len = strlen(argv[i]);
			char c = argv[i][len - 1];
			*rootdir = malloc((len+1)*sizeof(char));
			strcpy((*rootdir),argv[i]);
			if(c == '/'){
				(*rootdir)[len - 1] = '\0';
			}

			if(0 != access((*rootdir),F_OK)){
				if(ENOENT == errno){
					printf("Given directory does not exists!\n");
					return -2;
				}
			}
		}
		else if(strcmp(argv[i],"-t")==0){//if found this flag change the w
			if(i+1==argc){//if value for w missing just go on with w=3
				printf("Value for t not found.Continue by default with 5 threads\n");
				break;
			}
			*n_threads = atoi(argv[++i]);
			if(!(*n_threads)){//fails if k=0 or argument not a number
				printf("Try again with t>0\n");
				return -2;
			}
		}
		else if(strcmp(argv[i],"-p")==0){
			if(i+1==argc){
				printf("Missing serving port!\n");
				return -2;
			}
			flag2++;
			*s_port = atoi(argv[++i]);
			if(!(*s_port)){//fails if k=0 or argument not a number
				printf("Try again with serving_port>0\n");
				return -2;
			}
		}
		else if(strcmp(argv[i],"-c")==0){
			if(i+1==argc){
				printf("Missing command port!\n");
				return -2;
			}
			*c_port = atoi(argv[++i]);
			flag3++;
			if(!(*c_port)){//fails if k=0 or argument not a number
				printf("Try again with command_port>0\n");
				return -2;
			}
		}
		//else if(strcmp(argv[i],"-sorted")==0){
		//	*sorted = 1;//if found this flag sort the trie
		//}
		else{//for every other argument/flag or whatever
			printf("Unrecognized arguments!\n");
			return -2;//exits 
		}
	}
	if(!flag1 || !flag2 || !flag3){
		printf("Missing some arguments!\n");
		return -2;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, -0x60(%rbp)
movq %r8, -0x58(%rbp)
movq %rcx, %rbx
movq %rdx, -0x50(%rbp)
movq %rsi, %r13
movl %edi, %r15d
pushq $0x1
popq %r12
xorl %r14d, %r14d
movl $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movq %rcx, -0x48(%rbp)
movl %edi, -0x34(%rbp)
cmpl %r15d, %r12d
jge 0x3074
movslq %r12d, %rax
movq (%r13,%rax,8), %rax
cmpb $0x2d, (%rax)
jne 0x3044
cmpb $0x64, 0x1(%rax)
jne 0x2ee3
cmpb $0x0, 0x2(%rax)
je 0x2f42
cmpb $0x74, 0x1(%rax)
jne 0x2ef3
cmpb $0x0, 0x2(%rax)
je 0x2fe4
cmpb $0x70, 0x1(%rax)
jne 0x2f03
cmpb $0x0, 0x2(%rax)
je 0x3008
cmpb $0x63, 0x1(%rax)
jne 0x3044
cmpb $0x0, 0x2(%rax)
jne 0x3044
incl %r12d
cmpl %r15d, %r12d
je 0x304d
movslq %r12d, %rax
movq (%r13,%rax,8), %rdi
callq 0x22d0
movl %eax, (%rbx)
testl %eax, %eax
je 0x3056
incl -0x38(%rbp)
jmp 0x303c
incl %r12d
cmpl %r15d, %r12d
je 0x305f
movl %r14d, -0x3c(%rbp)
movslq %r12d, %r15
movq (%r13,%r15,8), %rbx
movq %rbx, %rdi
callq 0x20e0
shlq $0x20, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq (%rax,%rcx), %r14
sarq $0x20, %r14
movb (%rbx,%r14), %cl
movb %cl, -0x29(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x21e0
movq %rax, %rbx
movq -0x60(%rbp), %rax
movq %rbx, (%rax)
movq (%r13,%r15,8), %rsi
movq %rbx, %rdi
callq 0x2070
cmpb $0x2f, -0x29(%rbp)
jne 0x2fb8
movb $0x0, (%rbx,%r14)
movl -0x3c(%rbp), %r14d
incl %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2290
testl %eax, %eax
je 0x3034
callq 0x2050
cmpl $0x2, (%rax)
movq -0x48(%rbp), %rbx
movl -0x34(%rbp), %r15d
jne 0x303c
jmp 0x30c9
incl %r12d
cmpl %r15d, %r12d
je 0x3068
movslq %r12d, %rax
movq (%r13,%rax,8), %rdi
callq 0x22d0
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
jne 0x303c
jmp 0x30ae
incl %r12d
cmpl %r15d, %r12d
je 0x30b7
movslq %r12d, %rax
movq (%r13,%rax,8), %rdi
callq 0x22d0
movq -0x50(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x30c0
incl -0x30(%rbp)
jmp 0x303c
movq -0x48(%rbp), %rbx
movl -0x34(%rbp), %r15d
incl %r12d
jmp 0x2ebd
leaq 0x11ad(%rip), %rdi      # 0x41f8
jmp 0x3097
leaq 0x11da(%rip), %rdi      # 0x422e
jmp 0x3097
leaq 0x11b3(%rip), %rdi      # 0x4210
jmp 0x3097
leaq 0x1297(%rip), %rdi      # 0x42fd
jmp 0x3097
leaq 0x121c(%rip), %rdi      # 0x428b
callq 0x2090
testl %r14d, %r14d
setne %al
cmpl $0x0, -0x30(%rbp)
setne %cl
andb %al, %cl
cmpl $0x0, -0x38(%rbp)
setne %dl
xorl %eax, %eax
testb %dl, %cl
jne 0x309f
leaq 0x122d(%rip), %rdi      # 0x42c4
callq 0x2090
pushq $-0x2
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11c3(%rip), %rdi      # 0x4278
jmp 0x3097
leaq 0x11a4(%rip), %rdi      # 0x4262
jmp 0x3097
leaq 0x117d(%rip), %rdi      # 0x4244
jmp 0x3097
leaq 0x120c(%rip), %rdi      # 0x42dc
jmp 0x3097
nop