// File: /workspace/github_c_makefile_star2_O2/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 $0xd38, %rsp            # imm = 0xD38
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movslq %edx, %r12
addq %rsi, %r12
pxor %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movdqa %xmm0, (%r14)
leaq 0x20(%rsp), %r13
movdqa %xmm0, (%r13)
leaq 0x110(%rsp), %rdi
movl $0x404, %edx            # imm = 0x404
xorl %esi, %esi
callq 0x10c0
leaq 0x520(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %r14, 0x60(%rsp)
movl $0x101, 0x58(%rsp)      # imm = 0x101
leaq 0x10dd9(%rip), %rax     # 0x160f8
movq %rax, 0x68(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r13, 0x40(%rsp)
movl $0x13, 0x38(%rsp)
leaq 0x10dd6(%rip), %rax     # 0x16118
movq %rax, 0x48(%rsp)
movq %r15, %rax
cmpq %r12, %rax
jae 0x535e
movzbl (%rax), %ecx
incq %rax
incl 0x110(%rsp,%rcx,4)
jmp 0x534a
movl $0x1, 0x510(%rsp)
xorl %eax, %eax
movzwl 0x110(%rsp,%rax,4), %ecx
movw %cx, 0x520(%rsp,%rax,4)
incq %rax
cmpq $0x101, %rax            # imm = 0x101
jne 0x536b
leaq 0x50(%rsp), %r12
movq %r12, %rdi
callq 0x5609
movq (%r12), %rax
movslq 0x8(%r12), %rdi
movzwl 0x2(%rax), %ecx
orw $-0x1, 0x6(%rax,%rdi,4)
movdqa 0xaa72(%rip), %xmm0     # 0xfe20
movdqa 0xaa7a(%rip), %xmm1     # 0xfe30
pushq $0x3
popq %rdx
movdqa 0xaa7f(%rip), %xmm2     # 0xfe40
movdqa 0xaa87(%rip), %xmm3     # 0xfe50
pshufd $0xf5, %xmm3, %xmm4     # xmm4 = xmm3[1,1,3,3]
movdqa 0xaa8a(%rip), %xmm5     # 0xfe60
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, %esi
testb $0x1, %sil
je 0x5403
andw $0x0, 0x64(%rsp,%rdx,4)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x5414
andw $0x0, 0x68(%rsp,%rdx,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, %esi
testb $0x1, %sil
je 0x5442
andw $0x0, 0x6c(%rsp,%rdx,4)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x5453
andw $0x0, 0x70(%rsp,%rdx,4)
paddq %xmm5, %xmm1
paddq %xmm5, %xmm0
addq $0x4, %rdx
cmpq $0x17, %rdx
jne 0x53d6
xorl %r11d, %r11d
testl %ecx, %ecx
movl $0x8a, %edx
pushq $0x7
popq %r10
cmovel %edx, %r10d
setne %r11b
addl $0x3, %r11d
testq %rdi, %rdi
pushq $-0x1
popq %rsi
cmovnsq %rdi, %rsi
incq %rsi
addq $0x6, %rax
pushq $-0x1
popq %r9
xorl %edi, %edi
pushq $0x4
popq %r8
movl %r9d, %ebp
movq %rsi, %r13
subq %rdi, %r13
leaq (%rax,%rdi,4), %r14
xorl %r12d, %r12d
cmpq %r12, %r13
je 0x554e
movl %ecx, %r9d
movzwl (%r14,%r12,4), %ecx
incq %r12
cmpl %r10d, %r12d
jge 0x54cc
cmpl %ecx, %r9d
je 0x54ae
movl %r9d, %r10d
cmpl %r11d, %r12d
jae 0x54e4
movl 0x70(%rsp,%r10,4), %r11d
addl %r12d, %r11d
movw %r11w, 0x70(%rsp,%r10,4)
jmp 0x551b
testl %r9d, %r9d
je 0x54fe
cmpl %ebp, %r9d
je 0x54f4
incw 0x70(%rsp,%r10,4)
incw 0xb0(%rsp)
jmp 0x551b
leaq -0x1(%r12), %r10
cmpl $0x9, %r10d
ja 0x5513
incw 0xb4(%rsp)
jmp 0x551b
incw 0xb8(%rsp)
addq %r12, %rdi
xorl %r11d, %r11d
cmpl %ecx, %r9d
sete %r11b
movl %r11d, %r10d
xorl $0x7, %r10d
testl %ecx, %ecx
sete %bpl
cmovel %edx, %r10d
orb %bpl, %r11b
movzbl %r11b, %ebp
andl $0x1, %ebp
movl %r8d, %r11d
subl %ebp, %r11d
jmp 0x549e
leaq 0x30(%rsp), %rdi
callq 0x5609
pushq $0x12
popq %rcx
pushq $0x2
popq %rax
leaq 0xa92b(%rip), %rdx      # 0xfe90
cmpl $0x3, %ecx
jb 0x557e
movl %ecx, %esi
movzbl (%rsi,%rdx), %esi
cmpw $0x0, 0x72(%rsp,%rsi,4)
jne 0x557c
decl %ecx
jmp 0x5565
movl %ecx, %eax
incl %eax
leal (%rax,%rax,2), %ecx
movslq %ecx, %rcx
movq 0x20(%rsp), %rdx
addq %rdx, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
addq 0x10(%rsp), %rcx
cmpq 0x18(%rsp), %rcx
jae 0x55ce
movq 0x8(%rsp), %rsi
movb %al, (%rsi)
leaq 0x520(%rsp), %rdx
leaq 0x70(%rsp), %rcx
movq %r15, %rdi
movl %ebx, %r8d
callq 0x5aa4
movq 0x10(%rsp), %rax
addq 0x20(%rsp), %rax
jmp 0x55ef
leaq 0xa8db(%rip), %rdx      # 0xfeb0
leaq 0x70(%rsp), %rcx
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movl %ebx, %r8d
callq 0x5aa4
movq 0x18(%rsp), %rax
addq $0x8, %rax
shrq $0x3, %rax
addq $0xd38, %rsp            # imm = 0xD38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq