// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x18, %rsp
movl %edi, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
cmpl $0x2, 0x10(%rsp)
jl 0x1763
cmpl $0x4, 0x10(%rsp)
jg 0x1763
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x2d92(%rip), %rsi      # 0x4235
callq 0x10f0
cmpl $0x0, %eax
je 0x14c7
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x2d7b(%rip), %rsi      # 0x4238
callq 0x10f0
cmpl $0x0, %eax
jne 0x14d4
movl $0x2, 0x14(%rsp)
jmp 0x1775
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x2d57(%rip), %rsi      # 0x423b
callq 0x10f0
cmpl $0x0, %eax
je 0x1508
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x2d40(%rip), %rsi      # 0x423e
callq 0x10f0
cmpl $0x0, %eax
jne 0x151c
movl $0x2, 0x4(%rsp)
movl $0x2, 0x4bce(%rip)      # 0x60e8
jmp 0x1578
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x2d15(%rip), %rsi      # 0x4241
callq 0x10f0
cmpl $0x0, %eax
je 0x1550
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x2cfb(%rip), %rsi      # 0x4241
callq 0x10f0
cmpl $0x0, %eax
jne 0x1564
movl $0x2, 0x4(%rsp)
movl $0x3, 0x4b86(%rip)      # 0x60e8
jmp 0x1576
movl $0x1, 0x4(%rsp)
movl $0x1, 0x4b72(%rip)      # 0x60e8
jmp 0x1578
jmp 0x157a
movl 0x4(%rsp), %eax
cmpl 0x10(%rsp), %eax
jl 0x1591
movl $0x1, 0x14(%rsp)
jmp 0x1775
movq 0x8(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1050
movq %rax, %rdi
addq $0x1, %rdi
callq 0x10e0
movq %rax, 0x4b01(%rip)      # 0x60b8
cmpq $0x0, 0x4af9(%rip)      # 0x60b8
jne 0x15dc
leaq 0x2c7c(%rip), %rdi      # 0x4244
movb $0x0, %al
callq 0x1040
movl $0x4, 0x14(%rsp)
jmp 0x1775
movq 0x4ad5(%rip), %rdi      # 0x60b8
movq 0x8(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1080
movl 0x4(%rsp), %eax
addl $0x1, %eax
cmpl 0x10(%rsp), %eax
jge 0x1677
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1050
movq %rax, %rdi
addq $0x1, %rdi
callq 0x10e0
movq %rax, 0x4a92(%rip)      # 0x60c0
cmpq $0x0, 0x4a8a(%rip)      # 0x60c0
jne 0x1653
leaq 0x2c2d(%rip), %rdi      # 0x426c
movb $0x0, %al
callq 0x1040
movl $0x4, 0x14(%rsp)
jmp 0x1775
movq 0x4a66(%rip), %rdi      # 0x60c0
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1080
jmp 0x1761
movq 0x8(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1050
movq %rax, %rdi
addq $0x1, %rdi
addq $0x4, %rdi
callq 0x10e0
movq %rax, 0x4a1f(%rip)      # 0x60c0
cmpq $0x0, 0x4a17(%rip)      # 0x60c0
jne 0x16c6
leaq 0x2bba(%rip), %rdi      # 0x426c
movb $0x0, %al
callq 0x1040
movl $0x4, 0x14(%rsp)
jmp 0x1775
movq 0x49f3(%rip), %rdi      # 0x60c0
movq 0x8(%rsp), %rax
movslq 0x4(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1080
cmpl $0x3, 0x4a01(%rip)      # 0x60e8
jne 0x174c
movq 0x49d0(%rip), %rdi      # 0x60c0
callq 0x1050
subq $0x4, %rax
movl %eax, (%rsp)
movq 0x49bd(%rip), %rdi      # 0x60c0
movslq (%rsp), %rax
addq %rax, %rdi
leaq 0x2b84(%rip), %rsi      # 0x4295
callq 0x10f0
cmpl $0x0, %eax
jne 0x1737
movq 0x499e(%rip), %rdi      # 0x60c0
movslq (%rsp), %rax
addq %rax, %rdi
leaq 0x2b6a(%rip), %rsi      # 0x429a
callq 0x1080
jmp 0x174a
movq 0x4982(%rip), %rdi      # 0x60c0
leaq 0x2b55(%rip), %rsi      # 0x429a
callq 0x1110
jmp 0x175f
movq 0x496d(%rip), %rdi      # 0x60c0
leaq 0x2b3b(%rip), %rsi      # 0x4295
callq 0x1110
jmp 0x1761
jmp 0x176d
movl $0x1, 0x14(%rsp)
jmp 0x1775
movl $0x3, 0x14(%rsp)
movl 0x14(%rsp), %eax
addq $0x18, %rsp
retq
nop