// File: /workspace/github_c_makefile_star2_O1/Cyan4973[P]FiniteStateEntropy/programs/zlibh.c
// Function: ZLIBH_compress
int ZLIBH_compress (char* dest, const char* source, int inputSize)
{
    const unsigned char* ip = (const unsigned char*)source;
    const unsigned char* const bsourceend = ip+inputSize;
    const unsigned char* bsource = (const unsigned char*)source;
    unsigned char* op = (unsigned char*)dest;
    tree_desc ltree;
    ct_data dyn_ltree[ZLIBH_HEAP_SIZE];
    unsigned long ldata_compsize[2] = {0};
    tree_desc bltree;
    ct_data dyn_bltree[2*ZLIBH_BL_CODES+1];
    unsigned long bldata_compsize[2] = {0};
    int symbol;
    int max_blindex;
    int compressed_size;

    U32   freq_l[257]= {0};

    /* literal tree init */
    ltree.dyn_tree  = dyn_ltree;
    ltree.comp_size = ldata_compsize;
    ltree.max_code  = ZLIBH_L_CODES;
    ltree.stat_desc = &static_l_desc;

    /* bitlen tree init */
    bltree.dyn_tree  = dyn_bltree;
    bltree.comp_size = bldata_compsize;
    bltree.max_code  = ZLIBH_BL_CODES;
    bltree.stat_desc = &static_bl_desc;

    /* scan for stats */
    while (bsource < bsourceend) freq_l[*bsource++]++;
    freq_l[256]=1;

    symbol = 0;
    do {
        dyn_ltree[symbol].Freq = (unsigned short)freq_l[symbol];
        ++symbol;
    } while (symbol < 257);

    build_tree(&ltree);

    /* Determine the bit length frequencies for literal tree */
    feed_bltree(&ltree, &bltree);

    /* Build the bit length tree: */
    build_tree(&bltree);

    /* Determine the number of bit length codes to send. The pkzip format
    * requires that at least 4 bit length codes be sent.
    */
    for (max_blindex = ZLIBH_BL_CODES-1; max_blindex >= 3; max_blindex--) {
        if (dyn_bltree[bl_order[max_blindex]].Len != 0) break;
    }
    bldata_compsize[0] += 3*(max_blindex+1)+4;

    if ((bldata_compsize[0]+ldata_compsize[0]) < ldata_compsize[1]) {  /* write block using the dynamic tree */
        *op = (unsigned char)(max_blindex+1);
        ZLIBH_compress_block(ip, op, dyn_ltree, dyn_bltree, inputSize);
        compressed_size = (int)((bldata_compsize[0]+ldata_compsize[0]+8) >> 3);
    }
    else {                                                             /* write block using the static tree */
        ZLIBH_compress_block(ip, op, static_ltree, dyn_bltree, inputSize);
        compressed_size = (int)((ldata_compsize[1]+8) >> 3);
    }
    return compressed_size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd28, %rsp            # imm = 0xD28
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
movq %rsp, %r12
movaps %xmm0, (%r12)
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
leaq 0x100(%rsp), %rdi
movl $0x404, %edx            # imm = 0x404
xorl %esi, %esi
callq 0x10c0
leaq 0x510(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r12, 0x50(%rsp)
movl $0x101, 0x48(%rsp)      # imm = 0x101
leaq 0x13539(%rip), %rax     # 0x190f8
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r13, 0x30(%rsp)
movl $0x13, 0x28(%rsp)
leaq 0x13536(%rip), %rax     # 0x19118
movq %rax, 0x38(%rsp)
testl %ebx, %ebx
jle 0x5c06
movslq %ebx, %rax
addq %r15, %rax
movq %r15, %rcx
movzbl (%rcx), %edx
incq %rcx
incl 0x100(%rsp,%rdx,4)
cmpq %rax, %rcx
jb 0x5bf4
movl $0x1, 0x500(%rsp)
xorl %eax, %eax
movzwl 0x100(%rsp,%rax,4), %ecx
movw %cx, 0x510(%rsp,%rax,4)
incq %rax
cmpq $0x101, %rax            # imm = 0x101
jne 0x5c13
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x5dec
movq (%r12), %rax
movslq 0x8(%r12), %rdx
movl %edx, %ecx
movzwl 0x2(%rax), %esi
movw $0xffff, 0x6(%rax,%rdx,4) # imm = 0xFFFF
xorl %edx, %edx
movw $0x0, 0x60(%rsp,%rdx,4)
incq %rdx
cmpq $0x13, %rdx
jne 0x5c53
testl %ecx, %ecx
js 0x5d35
xorl %r10d, %r10d
testl %esi, %esi
movl $0x8a, %edx
movl $0x7, %r9d
cmovel %edx, %r9d
setne %r10b
addl $0x3, %r10d
incq %rcx
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %edi, %edi
xorl %r12d, %r12d
movzwl 0x6(%rax,%rdi,4), %r8d
leal 0x1(%r12), %ebp
cmpl %r9d, %ebp
jge 0x5caa
cmpl %r8d, %esi
je 0x5d23
cmpl %r10d, %ebp
jge 0x5cba
movl %esi, %r9d
addw %bp, 0x60(%rsp,%r9,4)
jmp 0x5cee
testl %esi, %esi
je 0x5cd6
cmpl %r11d, %esi
je 0x5ccc
movl %esi, %r9d
incw 0x60(%rsp,%r9,4)
incw 0xa0(%rsp)
jmp 0x5cee
cmpl $0x9, %r12d
jg 0x5ce6
incw 0xa4(%rsp)
jmp 0x5cee
incw 0xa8(%rsp)
xorl %r10d, %r10d
cmpl %r8d, %esi
sete %r10b
movl %r10d, %r9d
xorl $0x7, %r9d
testl %r8d, %r8d
cmovel %edx, %r9d
sete %r11b
orb %r11b, %r10b
movzbl %r10b, %r11d
andl $0x1, %r11d
movl $0x4, %r10d
subl %r11d, %r10d
xorl %ebp, %ebp
movl %esi, %r11d
incq %rdi
movl %ebp, %r12d
movl %r8d, %esi
cmpq %rdi, %rcx
jne 0x5c95
leaq 0x20(%rsp), %rdi
callq 0x5dec
movl $0x13, %ecx
leaq 0xd0c5(%rip), %rdx      # 0x12e10
leal -0x1(%rcx), %eax
movzbl (%rax,%rdx), %esi
cmpw $0x0, 0x62(%rsp,%rsi,4)
jne 0x5d66
decl %ecx
cmpl $0x3, %ecx
ja 0x5d4b
movl $0x2, %eax
incl %eax
leal (%rax,%rax,2), %ecx
movslq %ecx, %rcx
movq 0x10(%rsp), %rdx
addq %rdx, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%rsp)
addq (%rsp), %rcx
cmpq 0x8(%rsp), %rcx
jae 0x5db3
movb %al, (%r14)
leaq 0x510(%rsp), %rdx
leaq 0x60(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %r8d
callq 0x62bb
movq (%rsp), %rax
addq 0x10(%rsp), %rax
jmp 0x5dd2
leaq 0xd076(%rip), %rdx      # 0x12e30
leaq 0x60(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %r8d
callq 0x62bb
movq 0x8(%rsp), %rax
addq $0x8, %rax
shrq $0x3, %rax
addq $0xd28, %rsp            # imm = 0xD28
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq