// File: /workspace/github_c_makefile_star2_O1/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, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, -0x40(%rbp)
cmpl $0x2, %edi
jl 0x27b9
movq %rsi, %rbx
movl %edi, %r14d
movl $0x1, %r12d
movq $0x0, -0x38(%rbp)
movabsq $0x100000000, %r15      # imm = 0x100000000
movq $0x0, -0x30(%rbp)
movslq %r12d, %rax
movq (%rbx,%rax,8), %r13
movq %r13, %rdi
leaq 0x49bf(%rip), %rsi      # 0x700c
callq 0x2190
testl %eax, %eax
je 0x26fb
movq %r13, %rdi
leaq 0x49ab(%rip), %rsi      # 0x700f
callq 0x2190
testl %eax, %eax
je 0x2739
movq %r13, %rdi
leaq 0x4997(%rip), %rsi      # 0x7012
callq 0x2190
testl %eax, %eax
je 0x2760
movq %r13, %rdi
leaq 0x4988(%rip), %rsi      # 0x701a
callq 0x2190
testl %eax, %eax
jne 0x2807
leal 0x1(%r12), %eax
cmpl %r14d, %eax
je 0x2810
movslq %eax, %r13
movq (%rbx,%r13,8), %rdi
callq 0x2120
shlq $0x20, %rax
leaq (%rax,%r15), %rdi
sarq $0x20, %rdi
callq 0x2210
movq 0x10(%rbp), %rcx
movq %rax, (%rcx)
movq (%rbx,%r13,8), %rsi
movq %rax, %rdi
callq 0x2080
addl $0x2, %r12d
cmpl %r14d, %r12d
jne 0x276c
leaq 0x4971(%rip), %rdi      # 0x7062
callq 0x20a0
jmp 0x27a6
incl %r12d
cmpl %r14d, %r12d
je 0x27fe
movslq %r12d, %rax
movq (%rbx,%rax,8), %r13
movq %r13, %rdi
callq 0x2120
leaq 0x1(%rax), %rdi
callq 0x2210
movq %rax, -0x30(%rbp)
movq %rax, %rdi
movq %r13, %rsi
callq 0x2080
movl $0x1, %eax
movq %rax, -0x38(%rbp)
jmp 0x27ab
incl %r12d
cmpl %r14d, %r12d
je 0x2832
movslq %r12d, %rax
movq (%rbx,%rax,8), %rdi
callq 0x22a0
movq -0x58(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
jne 0x27ab
jmp 0x2840
movq -0x50(%rbp), %rax
movl $0x1, (%rax)
jmp 0x27ab
movslq %r12d, %r13
movq (%rbx,%r13,8), %rdi
callq 0x2120
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
leaq (%rax,%rcx), %rdi
sarq $0x20, %rdi
callq 0x2210
movq 0x18(%rbp), %rcx
movq %rax, (%rcx)
movq (%rbx,%r13,8), %rsi
movq %rax, %rdi
callq 0x2080
cmpl %r14d, %r12d
je 0x281c
incl %r12d
cmpl %r14d, %r12d
jl 0x263c
jmp 0x27c9
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x27f5
movq -0x30(%rbp), %r14
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x249c
movl %eax, %ebx
movq %r14, %rdi
callq 0x2030
sarl $0x1f, %ebx
andl $-0x2, %ebx
jmp 0x2821
leaq 0x48e3(%rip), %rdi      # 0x70df
jmp 0x2817
leaq 0x48f0(%rip), %rdi      # 0x70f5
jmp 0x2817
leaq 0x483c(%rip), %rdi      # 0x704a
jmp 0x2847
leaq 0x4864(%rip), %rdi      # 0x707b
callq 0x20a0
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 0x486f(%rip), %rdi      # 0x70a8
callq 0x20a0
jmp 0x27c9
leaq 0x484d(%rip), %rdi      # 0x7094
callq 0x20a0
movq -0x30(%rbp), %rdi
callq 0x2030
jmp 0x281c
nop