// File: /workspace/github_c_makefile_star2_O2/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 %r9, -0x50(%rbp)
movq %r8, -0x60(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, -0x48(%rbp)
movq %rsi, %r15
movl %edi, %r12d
movq $0x0, -0x40(%rbp)
pushq $0x1
popq %rax
movabsq $0x100000000, %r14      # imm = 0x100000000
movl %eax, %r13d
movl $0x0, -0x34(%rbp)
movq %rsi, -0x30(%rbp)
cmpl %r12d, %r13d
jge 0x278c
movl %r12d, %ebx
movslq %r13d, %rax
movq (%r15,%rax,8), %r15
movb (%r15), %r12b
cmpb $0x2d, %r12b
jne 0x25fd
cmpb $0x64, 0x1(%r15)
jne 0x25eb
cmpb $0x0, 0x2(%r15)
je 0x26d8
cmpb $0x77, 0x1(%r15)
jne 0x25fd
cmpb $0x0, 0x2(%r15)
je 0x271d
movq %r15, %rdi
leaq 0x4a05(%rip), %rsi      # 0x700c
callq 0x2180
testl %eax, %eax
je 0x26c5
cmpb $0x2d, %r12b
jne 0x274e
cmpb $0x6e, 0x1(%r15)
jne 0x274e
cmpb $0x0, 0x2(%r15)
jne 0x274e
leal 0x1(%r13), %eax
cmpl %ebx, %eax
je 0x2765
movl %ebx, %r12d
movslq %eax, %r15
movq -0x30(%rbp), %rbx
movq (%rbx,%r15,8), %rdi
callq 0x2120
shlq $0x20, %rax
leaq (%rax,%r14), %rdi
sarq $0x20, %rdi
callq 0x2200
movq 0x10(%rbp), %rcx
movq %rax, (%rcx)
movq (%rbx,%r15,8), %rsi
movq %rax, %rdi
callq 0x2080
addl $0x2, %r13d
cmpl %r12d, %r13d
je 0x276e
movslq %r13d, %r15
movq -0x30(%rbp), %rax
movq (%rax,%r15,8), %rdi
callq 0x2120
shlq $0x20, %rax
leaq (%rax,%r14), %rdi
sarq $0x20, %rdi
callq 0x2200
movq 0x18(%rbp), %rcx
movq %rax, (%rcx)
movq -0x30(%rbp), %rcx
movq (%rcx,%r15,8), %rsi
movq -0x30(%rbp), %r15
movq %rax, %rdi
callq 0x2080
jmp 0x2746
movq -0x60(%rbp), %rax
movl $0x1, (%rax)
movl %ebx, %r12d
movq -0x30(%rbp), %r15
jmp 0x2746
incl %r13d
cmpl %ebx, %r13d
je 0x2777
movl %ebx, %r12d
movslq %r13d, %rax
movq -0x30(%rbp), %rbx
movq (%rbx,%rax,8), %r15
movq %r15, %rdi
callq 0x2120
leaq 0x1(%rax), %rdi
callq 0x2200
movq %rax, -0x40(%rbp)
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %r15
callq 0x2080
pushq $0x1
popq %rax
movl %eax, -0x34(%rbp)
jmp 0x2746
incl %r13d
cmpl %ebx, %r13d
je 0x2780
movl %ebx, %r12d
movslq %r13d, %rax
movq -0x30(%rbp), %r15
movq (%r15,%rax,8), %rdi
callq 0x2290
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
je 0x27d8
incl %r13d
jmp 0x25bd
leaq 0x48ec(%rip), %rdi      # 0x7041
callq 0x20a0
movq -0x40(%rbp), %rdi
callq 0x2030
jmp 0x27c4
leaq 0x4906(%rip), %rdi      # 0x7072
jmp 0x27bf
leaq 0x48e4(%rip), %rdi      # 0x7059
jmp 0x27bf
leaq 0x496e(%rip), %rdi      # 0x70ec
jmp 0x27bf
leaq 0x4918(%rip), %rdi      # 0x709f
callq 0x20a0
cmpl $0x0, -0x34(%rbp)
je 0x27b8
movq -0x40(%rbp), %r14
movq %r14, %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x242c
movl %eax, %ebx
movq %r14, %rdi
callq 0x2030
sarl $0x1f, %ebx
andl $-0x2, %ebx
jmp 0x27c7
leaq 0x4917(%rip), %rdi      # 0x70d6
callq 0x20a0
pushq $-0x2
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48ac(%rip), %rdi      # 0x708b
jmp 0x2755