// File: /workspace/github_c_makefile_star2_O2/stefpant[P]TCPserver/webcrawler/input_parse.c
// Function: input_parse
int input_parse(int argc,char* argv[],int* s_port,int* c_port,int* n_threads,char** rootdir,
		char** hostid,char** s_url){
	int i;
	int flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;
	for(i=1;i<argc;i++){
		if(strcmp(argv[i],"-d")==0){//then next argument must be the input directory
			if(++i==argc){//error if nothing next
				printf("Missing input file...\n");
				return -2;
			}
			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';
			}

			int err = isDirEmpty(*rootdir);
			if(err == -1){
				printf("Given directory does not exist!\n");
				return -2;
			}
			else if(err == -2){
				printf("Given directory not empty!\n");
				return -2;
			}
		}
		else if(strcmp(argv[i],"-t")==0){//if found this flag change the t
			if(i+1==argc){//if value for t missing just go on with t=5
				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],"-h")==0){
			if(i+1==argc){
				printf("Missing host or id!\n");
				return -2;
			}
			flag4++;
			int len = strlen(argv[++i]);
			*hostid = malloc((len+1)*sizeof(char));
			strcpy((*hostid),argv[i]);
		}
		//else if(strcmp(argv[i],"-sorted")==0){
		//	*sorted = 1;//if found this flag sort the trie
		//}
		else{//here must be the starting url and be the last argument to succeed
			if(i+1 != argc){
				printf("%s\n",argv[i]);
				printf("Arguments may be wrong placed!\n");
				return -2;
			}
			flag5++;
			int len = strlen(argv[i]);
			*s_url = malloc((len+1)*sizeof(char));
			strcpy((*s_url),argv[i]);
		}
	}
	if(!flag1 || !flag2 || !flag3 || !flag4 || !flag5){
		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, -0x60(%rbp)
movq %r8, -0x58(%rbp)
movq %rcx, -0x48(%rbp)
movq %rdx, -0x50(%rbp)
movq %rsi, %r12
movl %edi, %r13d
pushq $0x1
popq %rbx
movl $0x0, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl %r13d, %ebx
jge 0x308b
movslq %ebx, %rax
movq (%r12,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x2ecc
cmpb $0x64, 0x1(%rdi)
jne 0x2e8c
cmpb $0x0, 0x2(%rdi)
je 0x2f18
cmpb $0x74, 0x1(%rdi)
jne 0x2e9c
cmpb $0x0, 0x2(%rdi)
je 0x2fb1
cmpb $0x70, 0x1(%rdi)
jne 0x2eac
cmpb $0x0, 0x2(%rdi)
je 0x2fdb
cmpb $0x63, 0x1(%rdi)
jne 0x2ebc
cmpb $0x0, 0x2(%rdi)
je 0x3008
cmpb $0x68, 0x1(%rdi)
jne 0x2ecc
cmpb $0x0, 0x2(%rdi)
je 0x3035
leal 0x1(%rbx), %ecx
cmpl %r13d, %ecx
jne 0x3056
leaq (%r12,%rax,8), %r15
incl -0x40(%rbp)
movq 0x18(%rbp), %r14
callq 0x20f0
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x2220
movq %rax, (%r14)
movq (%r15), %rsi
movq %rax, %rdi
callq 0x2070
incl %ebx
jmp 0x2e67
incl %ebx
cmpl %r13d, %ebx
je 0x3064
movslq %ebx, %rax
movq %rax, -0x68(%rbp)
movq (%r12,%rax,8), %r15
movq %r15, %rdi
callq 0x20f0
shlq $0x20, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq (%rax,%rcx), %r14
sarq $0x20, %r14
movb (%r15,%r14), %cl
movb %cl, -0x29(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x2220
movq %rax, %r15
movq -0x60(%rbp), %rax
movq %r15, (%rax)
movq -0x68(%rbp), %rax
movq (%r12,%rax,8), %rsi
movq %r15, %rdi
callq 0x2070
cmpb $0x2f, -0x29(%rbp)
jne 0x2f8f
movb $0x0, (%r15,%r14)
movq %r15, %rdi
callq 0x2dcc
cmpl $-0x2, %eax
je 0x306d
cmpl $-0x1, %eax
je 0x3076
incl -0x3c(%rbp)
jmp 0x2f11
incl %ebx
cmpl %r13d, %ebx
je 0x307f
movslq %ebx, %rax
movq (%r12,%rax,8), %rdi
callq 0x2300
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
jne 0x2f11
jmp 0x30d8
incl %ebx
cmpl %r13d, %ebx
je 0x30e1
movslq %ebx, %rax
movq (%r12,%rax,8), %rdi
callq 0x2300
movq -0x50(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x30ea
incl -0x38(%rbp)
jmp 0x2f11
incl %ebx
cmpl %r13d, %ebx
je 0x30f3
movslq %ebx, %rax
movq (%r12,%rax,8), %rdi
callq 0x2300
movq -0x48(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x30fc
incl -0x34(%rbp)
jmp 0x2f11
incl %ebx
cmpl %r13d, %ebx
je 0x3105
incl -0x30(%rbp)
movslq %ebx, %rax
leaq (%r12,%rax,8), %r15
movq (%r15), %rdi
movq 0x10(%rbp), %r14
jmp 0x2ee3
callq 0x2090
leaq 0x1ff0(%rip), %rdi      # 0x5052
jmp 0x30c1
leaq 0x2121(%rip), %rdi      # 0x518c
jmp 0x30c1
leaq 0x20dd(%rip), %rdi      # 0x5151
jmp 0x30c1
leaq 0x20ef(%rip), %rdi      # 0x516c
jmp 0x30c1
leaq 0x207a(%rip), %rdi      # 0x5100
callq 0x2090
cmpl $0x0, -0x3c(%rbp)
setne %al
cmpl $0x0, -0x38(%rbp)
setne %cl
andb %al, %cl
cmpl $0x0, -0x34(%rbp)
setne %al
cmpl $0x0, -0x30(%rbp)
setne %dl
andb %al, %dl
andb %cl, %dl
cmpl $0x0, -0x40(%rbp)
setne %cl
xorl %eax, %eax
testb %cl, %dl
jne 0x30c9
leaq 0x2078(%rip), %rdi      # 0x5139
callq 0x2090
pushq $-0x2
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x200e(%rip), %rdi      # 0x50ed
jmp 0x30c1
leaq 0x1fef(%rip), %rdi      # 0x50d7
jmp 0x30c1
leaq 0x1fc8(%rip), %rdi      # 0x50b9
jmp 0x30c1
leaq 0x1fa9(%rip), %rdi      # 0x50a3
jmp 0x30c1
leaq 0x1f82(%rip), %rdi      # 0x5085
jmp 0x30c1
leaq 0x1f65(%rip), %rdi      # 0x5071
jmp 0x30c1
nop