// File: /workspace/github_c_makefile_star2_O3/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)
movl %edi, %r15d
leaq 0x1261(%rip), %rdi      # 0x42c4
cmpl $0x2, %r15d
jl 0x3247
movq %r8, %r14
movq %rcx, %r13
movq %rdx, -0x50(%rbp)
xorl %ebx, %ebx
movl $0x1, %r12d
movl $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movq %rsi, -0x48(%rbp)
movq %r8, -0x40(%rbp)
movq %rcx, -0x58(%rbp)
movslq %r12d, %rax
movq (%rsi,%rax,8), %rax
cmpb $0x2d, (%rax)
jne 0x3240
cmpb $0x64, 0x1(%rax)
jne 0x30b5
cmpb $0x0, 0x2(%rax)
je 0x3114
cmpb $0x74, 0x1(%rax)
jne 0x30c5
cmpb $0x0, 0x2(%rax)
je 0x31b6
cmpb $0x70, 0x1(%rax)
jne 0x30d5
cmpb $0x0, 0x2(%rax)
je 0x31da
cmpb $0x63, 0x1(%rax)
jne 0x3240
cmpb $0x0, 0x2(%rax)
jne 0x3240
incl %r12d
cmpl %r15d, %r12d
je 0x3260
movslq %r12d, %rax
movq (%rsi,%rax,8), %rdi
callq 0x22e0
movl %eax, (%r13)
testl %eax, %eax
je 0x3269
incl %ebx
jmp 0x320c
incl %r12d
cmpl %r15d, %r12d
je 0x3272
movl %ebx, -0x34(%rbp)
movslq %r12d, %r13
movq (%rsi,%r13,8), %r14
movq %r14, %rdi
callq 0x20e0
shlq $0x20, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq (%rax,%rcx), %rbx
sarq $0x20, %rbx
movb (%r14,%rbx), %cl
movb %cl, -0x29(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x21f0
movq %rax, %r14
movq -0x60(%rbp), %rax
movq %r14, (%rax)
movq -0x48(%rbp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
callq 0x2070
cmpb $0x2f, -0x29(%rbp)
jne 0x318b
movb $0x0, (%r14,%rbx)
incl -0x38(%rbp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x22a0
testl %eax, %eax
movq -0x58(%rbp), %r13
je 0x3205
callq 0x2050
cmpl $0x2, (%rax)
movl -0x34(%rbp), %ebx
movq -0x40(%rbp), %r14
jne 0x320c
jmp 0x32a4
incl %r12d
cmpl %r15d, %r12d
je 0x327b
movslq %r12d, %rax
movq (%rsi,%rax,8), %rdi
callq 0x22e0
movl %eax, (%r14)
testl %eax, %eax
jne 0x320c
jmp 0x3289
incl %r12d
cmpl %r15d, %r12d
je 0x3292
movslq %r12d, %rax
movq (%rsi,%rax,8), %rdi
callq 0x22e0
movq -0x50(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x329b
incl -0x30(%rbp)
jmp 0x320c
movl -0x34(%rbp), %ebx
movq -0x40(%rbp), %r14
incl %r12d
cmpl %r15d, %r12d
movq -0x48(%rbp), %rsi
jl 0x3099
cmpl $0x0, -0x38(%rbp)
setne %al
cmpl $0x0, -0x30(%rbp)
setne %cl
andb %al, %cl
testl %ebx, %ebx
setne %dl
xorl %eax, %eax
testb %dl, %cl
leaq 0x1088(%rip), %rdi      # 0x42c4
je 0x3247
jmp 0x3251
leaq 0xfb1(%rip), %rdi       # 0x41f8
callq 0x2090
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfc7(%rip), %rdi       # 0x422e
jmp 0x3247
leaq 0xfa0(%rip), %rdi       # 0x4210
jmp 0x3247
leaq 0x1084(%rip), %rdi      # 0x42fd
jmp 0x3247
leaq 0x1009(%rip), %rdi      # 0x428b
callq 0x2090
jmp 0x321c
leaq 0xfe8(%rip), %rdi       # 0x4278
jmp 0x3247
leaq 0xfc9(%rip), %rdi       # 0x4262
jmp 0x3247
leaq 0xfa2(%rip), %rdi       # 0x4244
jmp 0x3247
leaq 0x1031(%rip), %rdi      # 0x42dc
jmp 0x3247
nopl (%rax)