// File: /workspace/github_c_makefile_star2_O2/salextpuru[P]speccy-toochain/src/megalz/MegaLZ.c
// Function: main_job
int main_job(void)
{


	// open input file
	file_in=fopen(fname_in,"rb");

	if(!file_in)
	{
		printf("Cannot open input file \"%s\"!\n",fname_in);
		return 0;
	}


	// open output file
	file_out=fopen(fname_out,"wb");
	if(!file_out)
	{
		printf("Cannot create output file \"%s\"!\n",fname_out);
		return 0;
	}




	//get length of file
	if( fseek(file_in,0,SEEK_END) )
	{
		printf("Cannot fseek input file \"%s\"!\n",fname_in);
		return 0;
	}

	inlen=ftell(file_in);
	if( inlen==(-1L)  )
	{
		printf("Cannot ftell() length of input file \"%s\"!\n",fname_in);
		inlen=0;
		return 0;
	}
	else if( inlen<4 )
	{
		printf("Input file \"%s\" is smaller than 4 bytes - I won't process it!\n",fname_in);
		return 0;
	}

	//return ptr to beginning
	if( fseek(file_in,0,SEEK_SET) )
	{
		printf("Cannot fseek() input file \"%s\"!\n",fname_in);
		return 0;
	}




	//alloc mem for file and load it into mem

	indata=(UBYTE*)malloc(inlen);
	if( !indata )
	{
		printf("Cannot allocate memory for loading input file \"%s\"!\n",fname_in);
		return 0;
	}

	if( inlen!=fread(indata,1,inlen,file_in) )
	{
		printf("Cannot successfully load input file \"%s\" into mem!\n",fname_in);
		return 0;
	}




	// now file loaded, pack it

	if( (mode==MODE_PACK_OPTIMAL)||(mode==MODE_PACK_GREEDY) )
	{
		if( !pack() )
		{
			printf("main_job(): pack() failed!\n");
			return 0;
		}
	}
	else if( mode==MODE_DEPACK )
	{
		if( !depack() )
		{
			printf("main_job(): depack() failed!\n");
			return 0;
		}
	}


	return 1;
}

// Assembly:
pushq %rbx
movq 0x3b1d(%rip), %rdi      # 0x50b8
leaq 0x1a6c(%rip), %rsi      # 0x300e
callq 0x10c0
movq %rax, 0x3b1a(%rip)      # 0x50c8
testq %rax, %rax
je 0x15f9
movq 0x3b06(%rip), %rdi      # 0x50c0
leaq 0x1a6e(%rip), %rsi      # 0x302f
callq 0x10c0
movq %rax, 0x3b03(%rip)      # 0x50d0
testq %rax, %rax
je 0x1609
movq 0x3aef(%rip), %rdi      # 0x50c8
xorl %ebx, %ebx
pushq $0x2
popq %rdx
xorl %esi, %esi
callq 0x10a0
testl %eax, %eax
je 0x1619
movq 0x3ac8(%rip), %rsi      # 0x50b8
leaq 0x1a5c(%rip), %rdi      # 0x3053
jmp 0x1640
movq 0x3ab8(%rip), %rsi      # 0x50b8
leaq 0x1a0a(%rip), %rdi      # 0x3011
jmp 0x163e
movq 0x3ab0(%rip), %rsi      # 0x50c0
leaq 0x1a1b(%rip), %rdi      # 0x3032
jmp 0x163e
movq 0x3aa8(%rip), %rdi      # 0x50c8
callq 0x1030
movl %eax, 0x3aad(%rip)      # 0x50d8
cmpl $0x3, %eax
ja 0x164b
movq 0x3a81(%rip), %rsi      # 0x50b8
leaq 0x1a34(%rip), %rdi      # 0x3072
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1040
movl %ebx, %eax
popq %rbx
retq
movq 0x3a76(%rip), %rdi      # 0x50c8
xorl %esi, %esi
xorl %edx, %edx
callq 0x10a0
testl %eax, %eax
je 0x1678
movq 0x3a52(%rip), %rsi      # 0x50b8
leaq 0x1a44(%rip), %rdi      # 0x30b1
xorl %eax, %eax
callq 0x1040
xorl %ebx, %ebx
jmp 0x1647
movl 0x3a5a(%rip), %ebx      # 0x50d8
movq %rbx, %rdi
callq 0x10e0
movq %rax, 0x3a53(%rip)      # 0x50e0
testq %rax, %rax
je 0x16cb
movq 0x3a2f(%rip), %rcx      # 0x50c8
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0x1100
cmpq %rbx, %rax
jne 0x16de
movl 0x3a36(%rip), %eax      # 0x50e8
leal -0x1(%rax), %ecx
cmpl $0x1, %ecx
ja 0x16f1
callq 0x1f6c
testl %eax, %eax
je 0x1713
pushq $0x1
popq %rbx
jmp 0x1647
movq 0x39e6(%rip), %rsi      # 0x50b8
leaq 0x19f9(%rip), %rdi      # 0x30d2
jmp 0x163e
movq 0x39d3(%rip), %rsi      # 0x50b8
leaq 0x1a1b(%rip), %rdi      # 0x3107
jmp 0x163e
pushq $0x1
popq %rbx
cmpl $0x3, %eax
jne 0x1647
callq 0x1724
testl %eax, %eax
jne 0x1647
leaq 0x1c9c(%rip), %rdi      # 0x33ad
jmp 0x171a
leaq 0x1cb0(%rip), %rdi      # 0x33ca
callq 0x1110
jmp 0x1674