// File: /workspace/github_c_makefile_star2_O3/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, -0x70(%rbp)
movq %r8, -0x68(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, -0x60(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, %r13d
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x2, %edi
jl 0x32f5
movq %rsi, %r15
movl %edi, %r12d
movl $0x0, -0x3c(%rbp)
movl $0x1, %r14d
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
xorl %r13d, %r13d
movl $0x0, -0x30(%rbp)
movq %rsi, -0x48(%rbp)
movslq %r14d, %rax
movq (%r15,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x3116
cmpb $0x64, 0x1(%rdi)
jne 0x30d6
cmpb $0x0, 0x2(%rdi)
je 0x3171
cmpb $0x74, 0x1(%rdi)
jne 0x30e6
cmpb $0x0, 0x2(%rdi)
je 0x3217
cmpb $0x70, 0x1(%rdi)
jne 0x30f6
cmpb $0x0, 0x2(%rdi)
je 0x3242
cmpb $0x63, 0x1(%rdi)
jne 0x3106
cmpb $0x0, 0x2(%rdi)
je 0x3270
cmpb $0x68, 0x1(%rdi)
jne 0x3116
cmpb $0x0, 0x2(%rdi)
je 0x329e
leal 0x1(%r14), %ecx
cmpl %r12d, %ecx
jne 0x32c0
leaq (%r15,%rax,8), %r15
incl %r13d
movq 0x18(%rbp), %rbx
callq 0x20f0
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x2220
movq %rax, (%rbx)
movq (%r15), %rsi
movq %rax, %rdi
callq 0x2070
movq -0x48(%rbp), %r15
incl %r14d
cmpl %r12d, %r14d
jl 0x30ba
jmp 0x32f5
incl %r14d
cmpl %r12d, %r14d
je 0x32ce
movl %r13d, -0x40(%rbp)
movslq %r14d, %rax
movq %rax, -0x50(%rbp)
movq %r15, %r13
movq (%r15,%rax,8), %r15
movq %r15, %rdi
callq 0x20f0
shlq $0x20, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq (%rax,%rcx), %rbx
sarq $0x20, %rbx
movb (%r15,%rbx), %cl
movb %cl, -0x29(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x2220
movq %rax, %r15
movq -0x70(%rbp), %rax
movq %r15, (%rax)
movq -0x50(%rbp), %rax
movq (%r13,%rax,8), %rsi
movq %r15, %rdi
callq 0x2070
cmpb $0x2f, -0x29(%rbp)
jne 0x31f1
movb $0x0, (%r15,%rbx)
movq %r15, %rdi
callq 0x2ff0
cmpl $-0x2, %eax
movl -0x40(%rbp), %r13d
je 0x32e0
cmpl $-0x1, %eax
je 0x32d7
incl -0x3c(%rbp)
jmp 0x315c
incl %r14d
cmpl %r12d, %r14d
je 0x32e9
movslq %r14d, %rax
movq (%r15,%rax,8), %rdi
callq 0x2300
movq -0x68(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
jne 0x3160
jmp 0x3337
incl %r14d
cmpl %r12d, %r14d
je 0x3340
movslq %r14d, %rax
movq (%r15,%rax,8), %rdi
callq 0x2300
movq -0x60(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x3349
incl -0x38(%rbp)
jmp 0x3160
incl %r14d
cmpl %r12d, %r14d
je 0x3352
movslq %r14d, %rax
movq (%r15,%rax,8), %rdi
callq 0x2300
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x335b
incl -0x34(%rbp)
jmp 0x3160
incl %r14d
cmpl %r12d, %r14d
je 0x3364
incl -0x30(%rbp)
movslq %r14d, %rax
leaq (%r15,%rax,8), %r15
movq (%r15), %rdi
movq 0x10(%rbp), %rbx
jmp 0x312e
callq 0x2090
leaq 0x1d86(%rip), %rdi      # 0x5052
jmp 0x331e
leaq 0x1eb7(%rip), %rdi      # 0x518c
jmp 0x331e
leaq 0x1e8e(%rip), %rdi      # 0x516c
jmp 0x331e
leaq 0x1e6a(%rip), %rdi      # 0x5151
jmp 0x331e
leaq 0x1e10(%rip), %rdi      # 0x5100
callq 0x2090
leaq 0x1e3d(%rip), %rdi      # 0x5139
cmpl $0x0, -0x3c(%rbp)
je 0x331e
cmpl $0x0, -0x38(%rbp)
je 0x331e
cmpl $0x0, -0x34(%rbp)
je 0x331e
cmpl $0x0, -0x30(%rbp)
je 0x331e
testl %r13d, %r13d
movl $0x0, %eax
jne 0x3328
callq 0x2090
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1daf(%rip), %rdi      # 0x50ed
jmp 0x331e
leaq 0x1d90(%rip), %rdi      # 0x50d7
jmp 0x331e
leaq 0x1d69(%rip), %rdi      # 0x50b9
jmp 0x331e
leaq 0x1d4a(%rip), %rdi      # 0x50a3
jmp 0x331e
leaq 0x1d23(%rip), %rdi      # 0x5085
jmp 0x331e
leaq 0x1d06(%rip), %rdi      # 0x5071
jmp 0x331e
nopl (%rax)