// File: /workspace/github_c_makefile_star2_O3/salextpuru[P]speccy-toochain/src/megalz/MegaLZ.c
// Function: parse_input
int parse_input(int argc,char * argv[])
// parse input arguments
{
	int fname_pos,ext_pos;

	if( (argc>=2)&&(argc<=4) )
	{
		if( !(strcmp(argv[1],"-h")&&strcmp(argv[1],"-H")) )
		{
			return PARSE_HELP;
		}
		else if( !(strcmp(argv[1],"-g")&&strcmp(argv[1],"-G")) )
		{
			fname_pos=2;
			mode=MODE_PACK_GREEDY;
		}
		else if( !(strcmp(argv[1],"-d")&&strcmp(argv[1],"-d")) )
		{
			fname_pos=2;
			mode=MODE_DEPACK;
		}
		else
		{
			fname_pos=1;
			mode=MODE_PACK_OPTIMAL;
		}

		if( fname_pos>=argc ) return PARSE_ERROR;

		// input filename
		fname_in=(char *)malloc(strlen(argv[fname_pos])+1);
		if( !fname_in )
		{
			printf("parse_input(): fname_in malloc failed!\n");
			return PARSE_FAIL;
		}
		strcpy(fname_in,argv[fname_pos]);

		// output filename
		if( (fname_pos+1)<argc )
		{ // we have second filename
			fname_out=(char *)malloc(strlen(argv[fname_pos+1])+1);
			if( !fname_out)
			{
				printf("parse_input(): fname_out malloc failed!\n");
				return PARSE_FAIL;
			}
			strcpy(fname_out,argv[fname_pos+1]);
		}
		else
		{ // no second filename - create from old adding extensions
			fname_out=(char *)malloc(strlen(argv[fname_pos])+1+4);
			if( !fname_out)
			{
				printf("parse_input(): fname_out malloc failed!\n");
				return PARSE_FAIL;
			}
			strcpy(fname_out,argv[fname_pos]);
			if( mode==MODE_DEPACK )
			{
				ext_pos=strlen(fname_out)-4;
				if( !strcmp(&fname_out[ext_pos],PACK_EXT) )
				{
					strcpy(&fname_out[ext_pos],DEPK_EXT);
				}
				else
				{
					strcat(fname_out,DEPK_EXT);
				}
			}
			else
			{ // MODE_PACK_*
				strcat(fname_out,PACK_EXT);
			}
		}
	}
	else
	{
		return PARSE_ERROR;
	}


	return PARSE_WORK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %r14d
leal -0x2(%r14), %ecx
movl $0x1, %eax
cmpl $0x2, %ecx
ja 0x15aa
movq %rsi, %rbx
movq 0x8(%rsi), %rcx
cmpb $0x2d, (%rcx)
jne 0x1451
cmpb $0x68, 0x1(%rcx)
jne 0x1411
cmpb $0x0, 0x2(%rcx)
je 0x14db
cmpb $0x48, 0x1(%rcx)
jne 0x1421
cmpb $0x0, 0x2(%rcx)
je 0x14db
cmpb $0x67, 0x1(%rcx)
jne 0x1431
cmpb $0x0, 0x2(%rcx)
je 0x155a
cmpb $0x47, 0x1(%rcx)
jne 0x1441
cmpb $0x0, 0x2(%rcx)
je 0x155a
cmpb $0x64, 0x1(%rcx)
jne 0x1451
cmpb $0x0, 0x2(%rcx)
je 0x157f
movl $0x1, %ecx
xorl %ebp, %ebp
movl $0x1, %r12d
movl %ecx, 0x3c84(%rip)      # 0x50e8
cmpl %r14d, %r12d
jae 0x15aa
movl %r12d, %r13d
movq (%rbx,%r13,8), %rdi
callq 0x1050
leaq 0x1(%rax), %rdi
callq 0x10f0
movq %rax, 0x3c2f(%rip)      # 0x50b8
testq %rax, %rax
je 0x14e5
movq (%rbx,%r13,8), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x1080
incl %r12d
cmpl %r14d, %r12d
jae 0x14f1
movl %r12d, %r14d
movq (%rbx,%r14,8), %rdi
callq 0x1050
leaq 0x1(%rax), %rdi
callq 0x10f0
movq %rax, 0x3bff(%rip)      # 0x50c0
testq %rax, %rax
je 0x156c
movq (%rbx,%r14,8), %rsi
movq %rax, %rdi
callq 0x1080
jmp 0x15a5
movl $0x2, %eax
jmp 0x15aa
leaq 0x1e72(%rip), %rdi      # 0x335e
jmp 0x1573
movq %r15, %rdi
callq 0x1050
leaq 0x5(%rax), %rdi
callq 0x10f0
movq %rax, 0x3bb7(%rip)      # 0x50c0
testq %rax, %rax
je 0x156c
movq %rax, %r14
movq (%rbx,%r13,8), %rsi
movq %rax, %rdi
callq 0x1080
movq %r14, %rdi
testb %bpl, %bpl
je 0x1592
callq 0x1050
addl $-0x4, %eax
cltq
movq %r14, %rbx
addq %rax, %rbx
leaq 0x1ac8(%rip), %rsi      # 0x3004
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
je 0x15b9
movq %r14, %rdi
callq 0x1050
movl $0x6b70642e, (%r14,%rax) # imm = 0x6B70642E
jmp 0x159f
movl $0x2, %ecx
xorl %ebp, %ebp
movl $0x2, %r12d
jmp 0x145e
leaq 0x1e12(%rip), %rdi      # 0x3385
callq 0x1120
movl $0x4, %eax
jmp 0x15aa
movl $0x2, %r12d
movb $0x1, %bpl
movl $0x3, %ecx
jmp 0x145e
callq 0x1050
movl $0x7a6c6d2e, (%r14,%rax) # imm = 0x7A6C6D2E
movb $0x0, 0x4(%r14,%rax)
movl $0x3, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0x4(%rbx)
movl $0x6b70642e, (%rbx)     # imm = 0x6B70642E
jmp 0x15a5