// File: /workspace/github_c_makefile_star2_O1/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, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, %r13d
movl %edi, -0x2c(%rbp)
cmpl $0x2, %edi
jl 0x3325
movq %rsi, %r14
xorl %r13d, %r13d
movl $0x1, %r12d
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movq %rsi, -0x48(%rbp)
movslq %r12d, %r15
movq (%r14,%r15,8), %rbx
movq %rbx, %rdi
leaq 0x1f76(%rip), %rsi      # 0x5055
callq 0x2180
testl %eax, %eax
je 0x3171
movq %rbx, %rdi
leaq 0x1f62(%rip), %rsi      # 0x5058
callq 0x2180
testl %eax, %eax
je 0x3210
movq %rbx, %rdi
leaq 0x1f4e(%rip), %rsi      # 0x505b
callq 0x2180
testl %eax, %eax
je 0x323c
movq %rbx, %rdi
leaq 0x1f3a(%rip), %rsi      # 0x505e
callq 0x2180
testl %eax, %eax
je 0x326b
movq %rbx, %rdi
leaq 0x1f26(%rip), %rsi      # 0x5061
callq 0x2180
leal 0x1(%r12), %r14d
testl %eax, %eax
je 0x3297
cmpl -0x2c(%rbp), %r14d
jne 0x3382
movq -0x48(%rbp), %rax
leaq (%rax,%r15,8), %r15
incl -0x38(%rbp)
movq 0x18(%rbp), %rax
movl %r12d, %r14d
movq %rax, %r12
jmp 0x32b6
incl %r12d
cmpl -0x2c(%rbp), %r12d
je 0x32fe
movl %r13d, -0x4c(%rbp)
movslq %r12d, %r15
movq (%r14,%r15,8), %rbx
movq %rbx, %rdi
callq 0x20f0
shlq $0x20, %rax
movq %r14, %r13
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
leaq (%rax,%rcx), %r14
sarq $0x20, %r14
movb (%rbx,%r14), %cl
movb %cl, -0x2d(%rbp)
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x2220
movq %rax, %rbx
movq -0x70(%rbp), %rax
movq %rbx, (%rax)
movq (%r13,%r15,8), %rsi
movq %rbx, %rdi
callq 0x2070
cmpb $0x2f, -0x2d(%rbp)
jne 0x31ea
movb $0x0, (%rbx,%r14)
movq %rbx, %rdi
callq 0x3004
cmpl $-0x2, %eax
movl -0x4c(%rbp), %r13d
je 0x3310
cmpl $-0x1, %eax
je 0x3307
incl %r13d
jmp 0x32eb
incl %r12d
cmpl -0x2c(%rbp), %r12d
je 0x3319
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
callq 0x2300
movq -0x68(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
jne 0x32ef
jmp 0x3367
incl %r12d
cmpl -0x2c(%rbp), %r12d
je 0x3370
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
callq 0x2300
movq -0x60(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x3379
incl -0x40(%rbp)
jmp 0x32ef
incl %r12d
cmpl -0x2c(%rbp), %r12d
je 0x3393
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
callq 0x2300
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x339c
incl -0x3c(%rbp)
jmp 0x32ef
cmpl -0x2c(%rbp), %r14d
je 0x33a5
incl -0x34(%rbp)
movslq %r14d, %rax
movq -0x48(%rbp), %rcx
leaq (%rcx,%rax,8), %r15
movq (%r15), %rbx
movq 0x10(%rbp), %r12
movq %rbx, %rdi
callq 0x20f0
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x2220
movq %rax, (%r12)
movq (%r15), %rsi
movq %rax, %rdi
callq 0x2070
movl %r14d, %r12d
movq -0x48(%rbp), %r14
incl %r12d
cmpl -0x2c(%rbp), %r12d
jl 0x30ce
jmp 0x3325
leaq 0x1e99(%rip), %rdi      # 0x519e
jmp 0x334e
leaq 0x1e70(%rip), %rdi      # 0x517e
jmp 0x334e
leaq 0x1e4c(%rip), %rdi      # 0x5163
jmp 0x334e
leaq 0x1df2(%rip), %rdi      # 0x5112
callq 0x2090
leaq 0x1e1f(%rip), %rdi      # 0x514b
testl %r13d, %r13d
je 0x334e
cmpl $0x0, -0x40(%rbp)
je 0x334e
cmpl $0x0, -0x3c(%rbp)
je 0x334e
cmpl $0x0, -0x34(%rbp)
je 0x334e
cmpl $0x0, -0x38(%rbp)
movl $0x0, %eax
jne 0x3358
callq 0x2090
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d91(%rip), %rdi      # 0x50ff
jmp 0x334e
leaq 0x1d72(%rip), %rdi      # 0x50e9
jmp 0x334e
leaq 0x1d4b(%rip), %rdi      # 0x50cb
jmp 0x334e
movq %rbx, %rdi
callq 0x2090
leaq 0x1cd3(%rip), %rdi      # 0x5064
jmp 0x334e
leaq 0x1d1b(%rip), %rdi      # 0x50b5
jmp 0x334e
leaq 0x1cf4(%rip), %rdi      # 0x5097
jmp 0x334e
leaq 0x1cd7(%rip), %rdi      # 0x5083
jmp 0x334e
nop