// File: /workspace/github_c_makefile_star2_O0/salextpuru[P]speccy-toochain/src/mhmt/mhmt-lz.c
// Function: get_lz_price_megalz
ULONG get_lz_price_megalz(ULONG position, struct lzcode * lzcode)
{
    ULONG varbits,varlen;
    LONG length,disp;
    length = lzcode->length;
    disp   = lzcode->disp;

    if( length==1 ) {
        if( disp==0 )
            return 9;

        else if( (-8)<=disp && disp<=(-1) )
            return 6;

        else
            goto INVALID_CODE_MEGALZ;

    } else if( length==2 ) {
        if( (-256)<=disp && disp<=(-1) )
            return 11;

        else
            goto INVALID_CODE_MEGALZ;

    } else if( length==3 ) {
        if( (-256)<=disp && disp<=(-1) )
            return 12;

        else if( (-4352)<=disp && disp<(-256) )
            return 16;

        else
            goto INVALID_CODE_MEGALZ;

    } else if( 4<=length && length<=255 ) {
        varlen = 0;
        varbits = (length-2)>>1;

        while( varbits ) {
            varbits >>= 1;
            varlen+=2;
        }

        if( (-256)<=disp && disp<=(-1) )
            varlen += 9;

        else if( (-4352)<=disp && disp<(-256) )
            varlen += 13;

        else
            goto INVALID_CODE_MEGALZ;

        return varlen+3;

    } else {
INVALID_CODE_MEGALZ:
        printf("mhmt-lz.c:get_lz_price_megalz(): Found invalid code length=%d, displacement=%d\n",length, disp);
        return 0;
    }
}

// Assembly:
subq $0x28, %rsp
movl %edi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x18(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x8(%rsp)
cmpl $0x1, 0xc(%rsp)
jne 0x4273
cmpl $0x0, 0x8(%rsp)
jne 0x424f
movl $0x9, 0x24(%rsp)
jmp 0x43ad
movl $0xfffffff8, %eax       # imm = 0xFFFFFFF8
cmpl 0x8(%rsp), %eax
jg 0x426e
cmpl $-0x1, 0x8(%rsp)
jg 0x426e
movl $0x6, 0x24(%rsp)
jmp 0x43ad
jmp 0x438f
cmpl $0x2, 0xc(%rsp)
jne 0x429e
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl 0x8(%rsp), %eax
jg 0x4299
cmpl $-0x1, 0x8(%rsp)
jg 0x4299
movl $0xb, 0x24(%rsp)
jmp 0x43ad
jmp 0x438f
cmpl $0x3, 0xc(%rsp)
jne 0x42eb
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl 0x8(%rsp), %eax
jg 0x42c4
cmpl $-0x1, 0x8(%rsp)
jg 0x42c4
movl $0xc, 0x24(%rsp)
jmp 0x43ad
movl $0xffffef00, %eax       # imm = 0xFFFFEF00
cmpl 0x8(%rsp), %eax
jg 0x42e6
cmpl $0xffffff00, 0x8(%rsp)  # imm = 0xFFFFFF00
jge 0x42e6
movl $0x10, 0x24(%rsp)
jmp 0x43ad
jmp 0x438f
movl $0x4, %eax
cmpl 0xc(%rsp), %eax
jg 0x438d
cmpl $0xff, 0xc(%rsp)
jg 0x438d
movl $0x0, 0x10(%rsp)
movl 0xc(%rsp), %eax
subl $0x2, %eax
sarl %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x433b
movl 0x14(%rsp), %eax
shrl %eax
movl %eax, 0x14(%rsp)
movl 0x10(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x10(%rsp)
jmp 0x431d
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl 0x8(%rsp), %eax
jg 0x435a
cmpl $-0x1, 0x8(%rsp)
jg 0x435a
movl 0x10(%rsp), %eax
addl $0x9, %eax
movl %eax, 0x10(%rsp)
jmp 0x4380
movl $0xffffef00, %eax       # imm = 0xFFFFEF00
cmpl 0x8(%rsp), %eax
jg 0x437c
cmpl $0xffffff00, 0x8(%rsp)  # imm = 0xFFFFFF00
jge 0x437c
movl 0x10(%rsp), %eax
addl $0xd, %eax
movl %eax, 0x10(%rsp)
jmp 0x437e
jmp 0x438f
jmp 0x4380
movl 0x10(%rsp), %eax
addl $0x3, %eax
movl %eax, 0x24(%rsp)
jmp 0x43ad
jmp 0x438f
movl 0xc(%rsp), %esi
movl 0x8(%rsp), %edx
leaq 0x5085(%rip), %rdi      # 0x9423
movb $0x0, %al
callq 0x1040
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)