// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd60, %rsp            # imm = 0xD60
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x880(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x10c0
leaq -0x950(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x10c0
leaq -0xd60(%rbp), %rdi
xorl %esi, %esi
movl $0x404, %edx            # imm = 0x404
callq 0x10c0
leaq -0x870(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x880(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x101, -0x50(%rbp)     # imm = 0x101
leaq 0x203fe(%rip), %rax     # 0x2c0f8
movq %rax, -0x40(%rbp)
leaq -0x940(%rbp), %rax
movq %rax, -0x8a0(%rbp)
leaq -0x950(%rbp), %rax
movq %rax, -0x890(%rbp)
movl $0x13, -0x898(%rbp)
leaq 0x203ed(%rip), %rax     # 0x2c118
movq %rax, -0x888(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0xbd61
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movzbl (%rax), %eax
movl -0xd60(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0xd60(%rbp,%rax,4)
jmp 0xbd32
movl $0x1, -0x960(%rbp)
movl $0x0, -0x954(%rbp)
movslq -0x954(%rbp), %rax
movl -0xd60(%rbp,%rax,4), %eax
movw %ax, %cx
movslq -0x954(%rbp), %rax
movw %cx, -0x870(%rbp,%rax,4)
movl -0x954(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x954(%rbp)
cmpl $0x101, -0x954(%rbp)    # imm = 0x101
jl 0xbd75
leaq -0x58(%rbp), %rdi
callq 0xbef0
leaq -0x58(%rbp), %rdi
leaq -0x8a0(%rbp), %rsi
callq 0xc360
leaq -0x8a0(%rbp), %rdi
callq 0xbef0
movl $0x12, -0x958(%rbp)
cmpl $0x3, -0x958(%rbp)
jl 0xbe1c
movslq -0x958(%rbp), %rcx
leaq 0x1a11a(%rip), %rax     # 0x25f10
movzbl (%rax,%rcx), %eax
movzwl -0x93e(%rbp,%rax,4), %eax
cmpl $0x0, %eax
je 0xbe09
jmp 0xbe1c
jmp 0xbe0b
movl -0x958(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x958(%rbp)
jmp 0xbddf
movl -0x958(%rbp), %eax
addl $0x1, %eax
imull $0x3, %eax, %eax
addl $0x4, %eax
cltq
addq -0x950(%rbp), %rax
movq %rax, -0x950(%rbp)
movq -0x950(%rbp), %rax
addq -0x880(%rbp), %rax
cmpq -0x878(%rbp), %rax
jae 0xbea0
movl -0x958(%rbp), %eax
addl $0x1, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movb %cl, (%rax)
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x870(%rbp), %rdx
leaq -0x940(%rbp), %rcx
movl -0x14(%rbp), %r8d
callq 0xc540
movq -0x950(%rbp), %rax
addq -0x880(%rbp), %rax
addq $0x8, %rax
shrq $0x3, %rax
movl %eax, -0x95c(%rbp)
jmp 0xbed4
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x940(%rbp), %rcx
movl -0x14(%rbp), %r8d
leaq 0x1a076(%rip), %rdx     # 0x25f30
callq 0xc540
movq -0x878(%rbp), %rax
addq $0x8, %rax
shrq $0x3, %rax
movl %eax, -0x95c(%rbp)
movl -0x95c(%rbp), %eax
addq $0xd60, %rsp            # imm = 0xD60
popq %rbp
retq
nopw %cs:(%rax,%rax)