// File: /workspace/github_c_makefile_star2_O2/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, %r15d
leal -0x2(%r15), %eax
pushq $0x1
popq %rbx
cmpl $0x2, %eax
ja 0x154d
movq %rsi, %r14
movq 0x8(%rsi), %rax
cmpb $0x2d, (%rax)
jne 0x142e
cmpb $0x68, 0x1(%rax)
jne 0x13ee
cmpb $0x0, 0x2(%rax)
je 0x14bc
cmpb $0x48, 0x1(%rax)
jne 0x13fe
cmpb $0x0, 0x2(%rax)
je 0x14bc
cmpb $0x67, 0x1(%rax)
jne 0x140e
cmpb $0x0, 0x2(%rax)
je 0x1537
cmpb $0x47, 0x1(%rax)
jne 0x141e
cmpb $0x0, 0x2(%rax)
je 0x1537
cmpb $0x64, 0x1(%rax)
jne 0x142e
cmpb $0x0, 0x2(%rax)
je 0x155e
pushq $0x1
popq %rax
xorl %r12d, %r12d
movl %eax, %r13d
movl %eax, 0x3cab(%rip)      # 0x50e8
cmpl %r15d, %r13d
jae 0x154d
movl %r13d, %ebp
movq (%r14,%rbp,8), %rdi
callq 0x1050
leaq 0x1(%rax), %rdi
callq 0x10e0
movq %rax, 0x3c56(%rip)      # 0x50b8
testq %rax, %rax
je 0x14c3
movl %r12d, 0x4(%rsp)
pushq $0x3
popq %rbx
movq (%r14,%rbp,8), %r12
movq %rax, %rdi
movq %r12, %rsi
callq 0x1070
incl %r13d
cmpl %r15d, %r13d
jae 0x14cc
movl %r13d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x1050
leaq 0x1(%rax), %rdi
callq 0x10e0
movq %rax, 0x3c1e(%rip)      # 0x50c0
testq %rax, %rax
je 0x153e
movq (%r14,%r15,8), %rsi
movq %rax, %rdi
callq 0x1070
jmp 0x154d
pushq $0x2
jmp 0x154c
leaq 0x1e94(%rip), %rdi      # 0x335e
jmp 0x1545
movq %r12, %rdi
callq 0x1050
leaq 0x5(%rax), %rdi
callq 0x10e0
movq %rax, 0x3bdc(%rip)      # 0x50c0
testq %rax, %rax
je 0x153e
movq %rax, %r15
movq (%r14,%rbp,8), %rsi
movq %rax, %rdi
callq 0x1070
cmpb $0x0, 0x4(%rsp)
je 0x156d
movq %r15, %rdi
callq 0x1050
addl $-0x4, %eax
cltq
movq %r15, %r14
addq %rax, %r14
leaq 0x1aeb(%rip), %rsi      # 0x3004
movq %r14, %rdi
callq 0x10f0
testl %eax, %eax
je 0x1585
movq %r15, %rdi
callq 0x1050
movl $0x6b70642e, (%r15,%rax) # imm = 0x6B70642E
jmp 0x157d
pushq $0x2
jmp 0x1430
leaq 0x1e40(%rip), %rdi      # 0x3385
callq 0x1110
pushq $0x4
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %r13
movb $0x1, %r12b
pushq $0x3
popq %rax
jmp 0x1437
movq %r15, %rdi
callq 0x1050
movl $0x7a6c6d2e, (%r15,%rax) # imm = 0x7A6C6D2E
movb $0x0, 0x4(%r15,%rax)
jmp 0x154d
movb $0x0, 0x4(%r14)
movl $0x6b70642e, (%r14)     # imm = 0x6B70642E
jmp 0x154d