// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/mhmt/mhmt-depack.c
// Function: depack
ULONG depack(void)
{
    ULONG (*checker) (void) = NULL;
    ULONG (*depacker)(void) = NULL;
    ULONG success=1;

    // some preparations
    //
    if( wrk.packtype==PK_MLZ ) {
        checker  = &checker_megalz;
        depacker = &depacker_megalz;

    } else if( wrk.packtype==PK_HRM ) {
        checker  = &checker_hrum;
        depacker = &depacker_hrum;

    } else if( wrk.packtype==PK_HST ) {
//		checker  = &checker_hrust;
        depacker = &depacker_hrust;

    } else {
        printf("mhmt-depack.c:depack() - format unsupported!\n");
        return 0;
    }

    // allocate buffer used for depacking
    //
    buf_size = ( wrk.maxwin==4352 ) ? 8192 : wrk.maxwin; // provided there are no other non-2^n sizes
    buffer=(UBYTE*)malloc(buf_size);

    if( !buffer ) {
        printf("mhmt-depack.c:depack() cannot allocate memory for depack buffer!\n");
        return 0;
    }

    buf_ptr=0;
    success = success && emit_file(NULL,EMIT_FILE_INIT);
//	success = success && (*checker) ();
//#ifdef DBG
//	printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
//#endif
    success = success && (*depacker)();
    /*success = success && */depack_outbyte( 0, DEPACK_OUTBYTE_FLUSH );
    /*success = success && */emit_file(NULL,EMIT_FILE_FINISH);

    if( buffer )
        free(buffer);

    return success;
}

// Assembly:
subq $0x28, %rsp
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x1, 0xc(%rsp)
leaq 0x7e1b(%rip), %rax      # 0xe3a0
cmpl $0x1, (%rax)
jne 0x65a4
leaq 0x18f(%rip), %rax       # 0x6720
movq %rax, 0x18(%rsp)
leaq 0x5c3(%rip), %rax       # 0x6b60
movq %rax, 0x10(%rsp)
jmp 0x6603
leaq 0x7df5(%rip), %rax      # 0xe3a0
cmpl $0x2, (%rax)
jne 0x65ca
leaq 0x939(%rip), %rax       # 0x6ef0
movq %rax, 0x18(%rsp)
leaq 0xedd(%rip), %rax       # 0x74a0
movq %rax, 0x10(%rsp)
jmp 0x6601
leaq 0x7dcf(%rip), %rax      # 0xe3a0
cmpl $0x3, (%rax)
jne 0x65e4
leaq 0x1403(%rip), %rax      # 0x79e0
movq %rax, 0x10(%rsp)
jmp 0x65ff
leaq 0x3d49(%rip), %rdi      # 0xa334
movb $0x0, %al
callq 0x1040
movl $0x0, 0x24(%rsp)
jmp 0x6708
jmp 0x6601
jmp 0x6603
leaq 0x7d96(%rip), %rax      # 0xe3a0
cmpl $0x1100, 0x1c(%rax)     # imm = 0x1100
jne 0x661e
movl $0x2000, %eax           # imm = 0x2000
movl %eax, 0x8(%rsp)
jmp 0x662c
leaq 0x7d7b(%rip), %rax      # 0xe3a0
movl 0x1c(%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x8f66a(%rip)     # 0x95ca0
movl 0x8f664(%rip), %eax     # 0x95ca0
movl %eax, %edi
callq 0x10d0
movq %rax, 0x8f65e(%rip)     # 0x95ca8
cmpq $0x0, 0x8f656(%rip)     # 0x95ca8
jne 0x666f
leaq 0x3d07(%rip), %rdi      # 0xa362
movb $0x0, %al
callq 0x1040
movl $0x0, 0x24(%rsp)
jmp 0x6708
movl $0x0, 0x8f62b(%rip)     # 0x95ca4
xorl %eax, %eax
cmpl $0x0, 0xc(%rsp)
movb %al, 0x7(%rsp)
je 0x669e
xorl %eax, %eax
movl %eax, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x1950
cmpl $0x0, %eax
setne %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0xc(%rsp)
xorl %eax, %eax
cmpl $0x0, 0xc(%rsp)
movb %al, 0x6(%rsp)
je 0x66c6
callq *0x10(%rsp)
cmpl $0x0, %eax
setne %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0xc(%rsp)
xorl %edi, %edi
movl $0x1, %esi
callq 0x85f0
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0x1950
cmpq $0x0, 0x8f5b6(%rip)     # 0x95ca8
je 0x6700
movq 0x8f5ad(%rip), %rdi     # 0x95ca8
callq 0x10b0
movl 0xc(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)