// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %r9, -0x68(%rbp)
movq %r8, -0x58(%rbp)
movq %rcx, -0x60(%rbp)
movq %rdx, -0x50(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, %r15d
cmpl $0x2, %edi
jl 0x324a
movq %rsi, %r12
movl %edi, %r13d
xorl %r15d, %r15d
movl $0x1, %r14d
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq %rsi, -0x48(%rbp)
movl %edi, -0x38(%rbp)
movslq %r14d, %rax
movq (%r12,%rax,8), %rbx
movq %rbx, %rdi
leaq 0x112c(%rip), %rsi      # 0x41cb
callq 0x2190
testl %eax, %eax
je 0x311b
movq %rbx, %rdi
leaq 0x111c(%rip), %rsi      # 0x41ce
callq 0x2190
testl %eax, %eax
je 0x31bf
movq %rbx, %rdi
leaq 0x1108(%rip), %rsi      # 0x41d1
callq 0x2190
testl %eax, %eax
je 0x31e2
movq %rbx, %rdi
leaq 0x10f4(%rip), %rsi      # 0x41d4
callq 0x2190
testl %eax, %eax
jne 0x322c
incl %r14d
cmpl %r13d, %r14d
je 0x3235
movslq %r14d, %rax
movq (%r12,%rax,8), %rdi
callq 0x22e0
movq -0x60(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x3289
incl %r15d
jmp 0x3215
incl %r14d
cmpl %r13d, %r14d
je 0x3223
movl %r15d, -0x3c(%rbp)
movslq %r14d, %r15
movq (%r12,%r15,8), %rbx
movq %rbx, %rdi
callq 0x20e0
shlq $0x20, %rax
movq %r12, %r13
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq (%rax,%rcx), %r12
sarq $0x20, %r12
movb (%rbx,%r12), %cl
movb %cl, -0x29(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x21f0
movq %rax, %rbx
movq -0x68(%rbp), %rax
movq %rbx, (%rax)
movq (%r13,%r15,8), %rsi
movq %rbx, %rdi
callq 0x2070
cmpb $0x2f, -0x29(%rbp)
jne 0x3193
movb $0x0, (%rbx,%r12)
incl -0x34(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x22a0
testl %eax, %eax
movl -0x3c(%rbp), %r15d
je 0x320d
callq 0x2050
cmpl $0x2, (%rax)
movq -0x48(%rbp), %r12
movl -0x38(%rbp), %r13d
jne 0x3215
jmp 0x3292
incl %r14d
cmpl %r13d, %r14d
je 0x323e
movslq %r14d, %rax
movq (%r12,%rax,8), %rdi
callq 0x22e0
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
jne 0x3215
jmp 0x329b
incl %r14d
cmpl %r13d, %r14d
je 0x32a4
movslq %r14d, %rax
movq (%r12,%rax,8), %rdi
callq 0x22e0
movq -0x50(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x32ad
incl -0x30(%rbp)
jmp 0x3215
movq -0x48(%rbp), %r12
movl -0x38(%rbp), %r13d
incl %r14d
cmpl %r13d, %r14d
jl 0x308e
jmp 0x324a
leaq 0x10df(%rip), %rdi      # 0x4309
jmp 0x3270
leaq 0xfd1(%rip), %rdi       # 0x4204
jmp 0x3270
leaq 0xffe(%rip), %rdi       # 0x423a
jmp 0x3270
leaq 0x1052(%rip), %rdi      # 0x4297
callq 0x2090
cmpl $0x0, -0x34(%rbp)
setne %al
cmpl $0x0, -0x30(%rbp)
setne %cl
andb %al, %cl
testl %r15d, %r15d
setne %al
testb %al, %cl
movl $0x0, %eax
jne 0x327a
leaq 0x1060(%rip), %rdi      # 0x42d0
callq 0x2090
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf8c(%rip), %rdi       # 0x421c
jmp 0x3270
leaq 0x104f(%rip), %rdi      # 0x42e8
jmp 0x3270
leaq 0xfe2(%rip), %rdi       # 0x4284
jmp 0x3270
leaq 0xfc3(%rip), %rdi       # 0x426e
jmp 0x3270
leaq 0xf9c(%rip), %rdi       # 0x4250
jmp 0x3270
nop