// File: /workspace/github_c_makefile_star2_O3/stefpant[P]TCPserver/PantoulasStefanosProject2/trie/input_parse.c
// Function: input_parse
int input_parse(int argc,char* argv[],char ***docmap,int* w,int* sorted,int *lines,char** fifoname,char** fifoname2){
	char *docfile = NULL;//just to be sure
	int i;
	int flag=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
			flag = 1;
			docfile = malloc(strlen(argv[i])+1);
			strcpy(docfile,argv[i]);
			//printf("docfile = %s\n",docfile);
		}
		else if(strcmp(argv[i],"-w")==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 k not found.Continue with default value(w=3)\n");
				break;
			}
			*w = atoi(argv[++i]);
			if(!(*w)){//fails if k=0 or argument not a number
				printf("Try again with w!=0\n");
				free(docfile);
				return -2;
			}
		}
		else if(strcmp(argv[i],"-sorted")==0){
			*sorted = 1;//if found this flag sort the trie
		}
		else if(strcmp(argv[i],"-n")==0){
			if(++i==argc){//error if nothing next
				printf("Missing 1st fifo name...\n");
				return -2;
			}
			int len = strlen(argv[i]);
			*fifoname = malloc((len+1)*sizeof(char));
			strcpy((*fifoname),argv[i]);
			if(++i==argc){//error if nothing next
				printf("Missing 2nd fifo name...\n");
				return -2;
			}
			len = strlen(argv[i]);
			*fifoname2 = malloc((len+1)*sizeof(char));
			strcpy((*fifoname2),argv[i]);
		}
		else{//for every other argument/flag or whatever
			printf("Unrecognized arguments!\n");
			free(docfile);
			return -2;//exits 
		}
	}
	if(!flag){
		printf("Input file not found!\n");
		return -2;
	}

	int error = read_doc(docfile,docmap,lines);
	free(docfile);
	if(error<0) return -2;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, -0x60(%rbp)
cmpl $0x2, %edi
jl 0x2825
movl %edi, %r12d
movq %rsi, -0x38(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movl $0x1, %r13d
movq $0x0, -0x40(%rbp)
movabsq $0x100000000, %r14      # imm = 0x100000000
movq $0x0, -0x30(%rbp)
movl %r12d, %ebx
movslq %r13d, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %r15
movb (%r15), %r12b
cmpb $0x2d, %r12b
jne 0x269d
cmpb $0x64, 0x1(%r15)
jne 0x2676
cmpb $0x0, 0x2(%r15)
je 0x277b
cmpb $0x77, 0x1(%r15)
jne 0x26c6
cmpb $0x0, 0x2(%r15)
je 0x27c0
movq %r15, %rdi
leaq 0x497a(%rip), %rsi      # 0x700c
callq 0x2190
testl %eax, %eax
jne 0x26e3
jmp 0x26b4
movq %r15, %rdi
leaq 0x4965(%rip), %rsi      # 0x700c
callq 0x2190
testl %eax, %eax
jne 0x2833
movq -0x60(%rbp), %rax
movl $0x1, (%rax)
movl %ebx, %r12d
jmp 0x27ed
movq %r15, %rdi
leaq 0x493c(%rip), %rsi      # 0x700c
callq 0x2190
testl %eax, %eax
je 0x26b4
cmpb $0x2d, %r12b
jne 0x2833
cmpb $0x6e, 0x1(%r15)
jne 0x2833
cmpb $0x0, 0x2(%r15)
jne 0x2833
leal 0x1(%r13), %eax
cmpl %ebx, %eax
je 0x285e
movl %ebx, %r12d
movslq %eax, %r15
movq -0x38(%rbp), %rbx
movq (%rbx,%r15,8), %rdi
callq 0x2120
shlq $0x20, %rax
leaq (%rax,%r14), %rdi
sarq $0x20, %rdi
callq 0x2210
movq 0x10(%rbp), %rcx
movq %rax, (%rcx)
movq (%rbx,%r15,8), %rsi
movq %rax, %rdi
callq 0x2080
addl $0x2, %r13d
cmpl %r12d, %r13d
je 0x2867
movslq %r13d, %r15
movq (%rbx,%r15,8), %rdi
callq 0x2120
shlq $0x20, %rax
leaq (%rax,%r14), %rdi
sarq $0x20, %rdi
callq 0x2210
movq 0x18(%rbp), %rcx
movq %rax, (%rcx)
movq (%rbx,%r15,8), %rsi
movq %rax, %rdi
callq 0x2080
jmp 0x27ed
incl %r13d
cmpl %ebx, %r13d
je 0x2870
movl %ebx, %r12d
movslq %r13d, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %r15
movq %r15, %rdi
callq 0x2120
leaq 0x1(%rax), %rdi
callq 0x2210
movq %rax, -0x30(%rbp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2080
movl $0x1, %eax
movq %rax, -0x40(%rbp)
jmp 0x27ed
incl %r13d
cmpl %ebx, %r13d
je 0x2879
movl %ebx, %r12d
movslq %r13d, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x22a0
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x288a
incl %r13d
cmpl %r12d, %r13d
jl 0x264d
cmpl $0x0, -0x40(%rbp)
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rsi
je 0x2825
movq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x249c
movl %eax, %ebx
movq %r14, %rdi
callq 0x2030
sarl $0x1f, %ebx
andl $-0x2, %ebx
jmp 0x284d
leaq 0x48aa(%rip), %rdi      # 0x70d6
callq 0x20a0
jmp 0x2848
leaq 0x4807(%rip), %rdi      # 0x7041
callq 0x20a0
movq -0x30(%rbp), %rdi
callq 0x2030
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x480d(%rip), %rdi      # 0x7072
jmp 0x282c
leaq 0x47eb(%rip), %rdi      # 0x7059
jmp 0x282c
leaq 0x4875(%rip), %rdi      # 0x70ec
jmp 0x282c
leaq 0x481f(%rip), %rdi      # 0x709f
callq 0x20a0
jmp 0x27f9
leaq 0x47fa(%rip), %rdi      # 0x708b
jmp 0x283a
nop