// File: /workspace/github_c_makefile_star2_O1/DavidSM64[P]DKR-Decompressor/DKRGzip.c
// Function: compress_block(ct_data*, ct_data*)
void compress_block(ct_data* ltree, ct_data* dtree) {
    unsigned dist;      /* distance of matched string */
    int lc;             /* match length or unmatched char (if dist == 0) */
    unsigned lx = 0;    /* running index in l_buf */
    unsigned dx = 0;    /* running index in d_buf */
    unsigned fx = 0;    /* running index in flag_buf */
    u8 flag = 0;       /* current flags */
    unsigned code;      /* the code to send */
    int extra;          /* number of extra bits to send */

    if (last_lit != 0) do {
        if ((lx & 7) == 0) flag = flag_buf[fx++];
        lc = l_buf[lx++];
        if ((flag & 1) == 0) {
            send_code(lc, ltree); /* send a literal byte */
            //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
        } else {
            /* Here, lc is the match length - MIN_MATCH */
            code = length_code[lc];
            send_code(code+LITERALS+1, ltree); /* send the length code */
            extra = extra_lbits[code];
            if (extra != 0) {
                lc -= base_length[code];
                send_bits(lc, extra);        /* send the extra length bits */
            }
            dist = d_buf[dx++];
            /* Here, dist is the match distance - 1 */
            code = d_code(dist);
            //Assert (code < D_CODES, "bad d_code");

            send_code(code, dtree);       /* send the distance code */
            extra = extra_dbits[code];
            if (extra != 0) {
                dist -= base_dist[code];
                send_bits(dist, extra);   /* send the extra distance bits */
            }
        } /* literal or match pair ? */
        flag >>= 1;
    } while (lx < last_lit);

    send_code(END_BLOCK, ltree);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
cmpl $0x0, 0x807f(%rip)      # 0xdae0
je 0x5b96
xorl %r12d, %r12d
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
xorl %r14d, %r14d
testb $0x7, %r12b
jne 0x5a96
movl -0x2c(%rbp), %ecx
movl %ecx, %eax
incl %ecx
movl %ecx, -0x2c(%rbp)
leaq 0x704e(%rip), %rcx      # 0xcae0
movb (%rax,%rcx), %r14b
movq 0x100807b(%rip), %rax   # 0x100db18
movzbl (%rax,%r12), %r15d
testb $0x1, %r14b
jne 0x5abc
movq -0x38(%rbp), %rax
movzwl (%rax,%r15,4), %edi
movzwl 0x2(%rax,%r15,4), %esi
jmp 0x5b7c
leaq 0x6c1d(%rip), %rax      # 0xc6e0
movzbl (%r15,%rax), %r13d
leal (,%r13,4), %ebx
movq -0x38(%rbp), %rax
movzwl 0x404(%rax,%rbx), %edi
movzwl 0x406(%rax,%rbx), %esi
callq 0x4f64
leaq 0x4950(%rip), %rax      # 0xa440
movl (%rbx,%rax), %esi
testl %esi, %esi
je 0x5b0a
leaq 0x6ee2(%rip), %rax      # 0xc9e0
subl (%rax,%r13,4), %r15d
movl %r15d, %edi
callq 0x4f64
movl -0x30(%rbp), %ecx
movl %ecx, %eax
incl %ecx
movl %ecx, -0x30(%rbp)
leaq 0x1038025(%rip), %rcx   # 0x103db40
movzwl (%rcx,%rax,2), %r15d
movl %r15d, %eax
shrl $0x7, %eax
addq $0x100, %rax            # imm = 0x100
cmpl $0x100, %r15d           # imm = 0x100
movq %r15, %rcx
cmovaeq %rax, %rcx
leaq 0x6c9f(%rip), %rax      # 0xc7e0
movzbl (%rcx,%rax), %r13d
leal (,%r13,4), %ebx
movq -0x40(%rbp), %rax
movzwl (%rax,%rbx), %edi
movzwl 0x2(%rax,%rbx), %esi
callq 0x4f64
leaq 0x4959(%rip), %rax      # 0xa4c0
movl (%rbx,%rax), %esi
testl %esi, %esi
je 0x5b81
leaq 0x6eeb(%rip), %rax      # 0xca60
subl (%rax,%r13,4), %r15d
movl %r15d, %edi
callq 0x4f64
incq %r12
shrb %r14b
movl 0x7f53(%rip), %eax      # 0xdae0
cmpq %rax, %r12
jb 0x5a7b
movq -0x38(%rbp), %rax
movzwl 0x400(%rax), %edi
movzwl 0x402(%rax), %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4f64