// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x34c4
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1011(%rip), %rsi      # 0x41fb
callq 0x2190
cmpl $0x0, %eax
jne 0x32f1
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl -0x8(%rbp), %eax
jne 0x3220
leaq 0xff1(%rip), %rdi       # 0x41fe
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x20d0
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x45(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x0, %rdi
callq 0x21e0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x2070
movsbl -0x45(%rbp), %eax
cmpl $0x2f, %eax
jne 0x32a9
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x2290
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x32ec
callq 0x2050
movq %rax, %rcx
movl $0x2, %eax
cmpl (%rcx), %eax
jne 0x32ea
leaq 0xf3e(%rip), %rdi       # 0x4215
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
jmp 0x32ec
jmp 0x34b4
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xf33(%rip), %rsi       # 0x4237
callq 0x2190
cmpl $0x0, %eax
jne 0x3375
movl -0x34(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jne 0x332c
leaq 0xf1a(%rip), %rdi       # 0x423a
movb $0x0, %al
callq 0x2100
jmp 0x34c4
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22d0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x3370
leaq 0xf17(%rip), %rdi       # 0x4274
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
jmp 0x34b2
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xf00(%rip), %rsi       # 0x4288
callq 0x2190
cmpl $0x0, %eax
jne 0x3409
movl -0x34(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jne 0x33b7
leaq 0xee7(%rip), %rdi       # 0x428b
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22d0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x3404
leaq 0xeb1(%rip), %rdi       # 0x42a2
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
jmp 0x34b0
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xea5(%rip), %rsi       # 0x42c1
callq 0x2190
cmpl $0x0, %eax
jne 0x3497
movl -0x34(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jne 0x344b
leaq 0xe8c(%rip), %rdi       # 0x42c4
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
movq -0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22d0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x3495
leaq 0xe56(%rip), %rdi       # 0x42db
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
jmp 0x34ae
leaq 0xe5c(%rip), %rdi       # 0x42fa
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
jmp 0x34b0
jmp 0x34b2
jmp 0x34b4
jmp 0x34b6
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x31cb
cmpl $0x0, -0x38(%rbp)
je 0x34d6
cmpl $0x0, -0x3c(%rbp)
je 0x34d6
cmpl $0x0, -0x40(%rbp)
jne 0x34ed
leaq 0xe36(%rip), %rdi       # 0x4313
movb $0x0, %al
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x34f4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)