// File: /workspace/github_c_makefile_star2_O3/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 0x1423d(%rip), %rax     # 0x1a0f8
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r13, 0x30(%rsp)
movl $0x13, 0x28(%rsp)
leaq 0x1423a(%rip), %rax     # 0x1a118
movq %rax, 0x38(%rsp)
testl %ebx, %ebx
jle 0x5f02
movslq %ebx, %rax
addq %r15, %rax
movq %r15, %rcx
movzbl (%rcx), %edx
incq %rcx
incl 0x100(%rsp,%rdx,4)
cmpq %rax, %rcx
jb 0x5ef0
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 0x5f0f
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x619f
movq (%r12), %rax
movslq 0x8(%r12), %rsi
movl %esi, %ecx
movzwl 0x2(%rax), %edx
movw $0xffff, 0x6(%rax,%rsi,4) # imm = 0xFFFF
movdqa 0xd17b(%rip), %xmm0     # 0x130d0
movdqa 0xd183(%rip), %xmm1     # 0x130e0
movl $0x3, %esi
movdqa 0xd186(%rip), %xmm2     # 0x130f0
movdqa 0xdf6e(%rip), %xmm3     # 0x13ee0
pshufd $0xf5, %xmm3, %xmm4     # xmm4 = xmm3[1,1,3,3]
movdqa 0xdf71(%rip), %xmm5     # 0x13ef0
movdqa %xmm1, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm3, %xmm7
pcmpgtd %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pcmpeqd %xmm4, %xmm6
pand %xmm7, %xmm6
movd %xmm6, %edi
testb $0x1, %dil
je 0x5fad
movw $0x0, 0x54(%rsp,%rsi,4)
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x5fbf
movw $0x0, 0x58(%rsp,%rsi,4)
movdqa %xmm0, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm3, %xmm7
pcmpgtd %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pcmpeqd %xmm4, %xmm6
pand %xmm7, %xmm6
pextrw $0x0, %xmm6, %edi
testb $0x1, %dil
je 0x5fee
movw $0x0, 0x5c(%rsp,%rsi,4)
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x6000
movw $0x0, 0x60(%rsp,%rsi,4)
paddq %xmm5, %xmm1
paddq %xmm5, %xmm0
addq $0x4, %rsi
cmpq $0x17, %rsi
jne 0x5f7f
testl %ecx, %ecx
js 0x60e8
xorl %r10d, %r10d
testl %edx, %edx
movl $0x8a, %esi
movl $0x7, %r9d
cmovel %esi, %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 0x605d
cmpl %r8d, %edx
je 0x60d6
cmpl %r10d, %ebp
jge 0x606d
movl %edx, %r9d
addw %bp, 0x60(%rsp,%r9,4)
jmp 0x60a1
testl %edx, %edx
je 0x6089
cmpl %r11d, %edx
je 0x607f
movl %edx, %r9d
incw 0x60(%rsp,%r9,4)
incw 0xa0(%rsp)
jmp 0x60a1
cmpl $0x9, %r12d
jg 0x6099
incw 0xa4(%rsp)
jmp 0x60a1
incw 0xa8(%rsp)
xorl %r10d, %r10d
cmpl %r8d, %edx
sete %r10b
movl %r10d, %r9d
xorl $0x7, %r9d
testl %r8d, %r8d
cmovel %esi, %r9d
sete %r11b
orb %r11b, %r10b
movzbl %r10b, %r11d
andl $0x1, %r11d
movl $0x4, %r10d
subl %r11d, %r10d
xorl %ebp, %ebp
movl %edx, %r11d
incq %rdi
movl %ebp, %r12d
movl %r8d, %edx
cmpq %rdi, %rcx
jne 0x6048
leaq 0x20(%rsp), %rdi
callq 0x619f
movl $0x13, %ecx
leaq 0xde32(%rip), %rdx      # 0x13f30
leal -0x1(%rcx), %eax
movzbl (%rax,%rdx), %esi
cmpw $0x0, 0x62(%rsp,%rsi,4)
jne 0x6119
decl %ecx
cmpl $0x3, %ecx
ja 0x60fe
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 0x6166
movb %al, (%r14)
leaq 0x510(%rsp), %rdx
leaq 0x60(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %r8d
callq 0x6993
movq (%rsp), %rax
addq 0x10(%rsp), %rax
jmp 0x6185
leaq 0xdde3(%rip), %rdx      # 0x13f50
leaq 0x60(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %r8d
callq 0x6993
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