// File: tomfunkhouser[P]gaps/pkgs/png/trees.c
// Function: compress_block
local void compress_block(s, ltree, dtree)
    deflate_state *s;
    ct_data *ltree; /* literal tree */
    ct_data *dtree; /* distance tree */
{
    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 code;      /* the code to send */
    int extra;          /* number of extra bits to send */

    if (s->last_lit != 0) do {
        dist = s->d_buf[lx];
        lc = s->l_buf[lx++];
        if (dist == 0) {
            send_code(s, 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(s, code+LITERALS+1, ltree); /* send the length code */
            extra = extra_lbits[code];
            if (extra != 0) {
                lc -= base_length[code];
                send_bits(s, lc, extra);       /* send the extra length bits */
            }
            dist--; /* dist is now the match distance - 1 */
            code = d_code(dist);
            Assert (code < D_CODES, "bad d_code");

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

        /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
        Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
               "pendingBuf overflow");

    } while (lx < s->last_lit);

    send_code(s, END_BLOCK, ltree);
    s->last_eob_len = ltree[END_BLOCK].Len;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movl $0x0, -0x24(%rsp)
movq -0x8(%rsp), %rax
cmpl $0x0, 0x16fc(%rax)
je 0x120988
jmp 0x12019b
movq -0x8(%rsp), %rax
movq 0x1700(%rax), %rax
movl -0x24(%rsp), %ecx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x1c(%rsp)
movq -0x8(%rsp), %rax
movq 0x16f0(%rax), %rax
movl -0x24(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x24(%rsp)
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x20(%rsp)
cmpl $0x0, -0x1c(%rsp)
jne 0x120341
movq -0x10(%rsp), %rax
movslq -0x20(%rsp), %rcx
movzwl 0x2(%rax,%rcx,4), %eax
movl %eax, -0x30(%rsp)
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl -0x30(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1202f7
movq -0x10(%rsp), %rax
movslq -0x20(%rsp), %rcx
movzwl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rsp)
movl -0x34(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x34(%rsp), %eax
movzwl %ax, %eax
movq -0x8(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq -0x30(%rsp), %rdx
subq $0x10, %rdx
movq -0x8(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x12033c
movq -0x10(%rsp), %rax
movslq -0x20(%rsp), %rcx
movzwl (%rax,%rcx,4), %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl -0x30(%rsp), %ecx
movq -0x8(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
jmp 0x12096f
movslq -0x20(%rsp), %rcx
leaq 0x1e3f3(%rip), %rax     # 0x13e740
movzbl (%rax,%rcx), %eax
movl %eax, -0x28(%rsp)
movq -0x10(%rsp), %rax
movl -0x28(%rsp), %ecx
addl $0x100, %ecx            # imm = 0x100
addl $0x1, %ecx
movl %ecx, %ecx
movzwl 0x2(%rax,%rcx,4), %eax
movl %eax, -0x38(%rsp)
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl -0x38(%rsp), %ecx
cmpl %ecx, %eax
jle 0x12047f
movq -0x10(%rsp), %rax
movl -0x28(%rsp), %ecx
addl $0x100, %ecx            # imm = 0x100
addl $0x1, %ecx
movl %ecx, %ecx
movzwl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rsp)
movl -0x3c(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x3c(%rsp), %eax
movzwl %ax, %eax
movq -0x8(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq -0x38(%rsp), %rdx
subq $0x10, %rdx
movq -0x8(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x1204ce
movq -0x10(%rsp), %rax
movl -0x28(%rsp), %ecx
addl $0x100, %ecx            # imm = 0x100
addl $0x1, %ecx
movl %ecx, %ecx
movzwl (%rax,%rcx,4), %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl -0x38(%rsp), %ecx
movq -0x8(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
movl -0x28(%rsp), %eax
movl %eax, %ecx
leaq 0x1e865(%rip), %rax     # 0x13ed40
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rsp)
cmpl $0x0, -0x2c(%rsp)
je 0x120648
movl -0x28(%rsp), %eax
movl %eax, %ecx
leaq 0x1e9b6(%rip), %rax     # 0x13eeb0
movl (%rax,%rcx,4), %ecx
movl -0x20(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x20(%rsp)
movl -0x2c(%rsp), %eax
movl %eax, -0x40(%rsp)
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl -0x40(%rsp), %ecx
cmpl %ecx, %eax
jle 0x120608
movl -0x20(%rsp), %eax
movl %eax, -0x44(%rsp)
movl -0x44(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x44(%rsp), %eax
movzwl %ax, %eax
movq -0x8(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq -0x40(%rsp), %rdx
subq $0x10, %rdx
movq -0x8(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x120646
movl -0x20(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl -0x40(%rsp), %ecx
movq -0x8(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
jmp 0x120648
movl -0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rsp)
cmpl $0x100, -0x1c(%rsp)     # imm = 0x100
jae 0x120674
movl -0x1c(%rsp), %eax
movl %eax, %ecx
leaq 0x1ded6(%rip), %rax     # 0x13e540
movzbl (%rax,%rcx), %eax
movl %eax, -0x60(%rsp)
jmp 0x120693
movl -0x1c(%rsp), %eax
shrl $0x7, %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, %eax
movl %eax, %ecx
leaq 0x1deb5(%rip), %rax     # 0x13e540
movzbl (%rax,%rcx), %eax
movl %eax, -0x60(%rsp)
movl -0x60(%rsp), %eax
movl %eax, -0x28(%rsp)
movq -0x18(%rsp), %rax
movl -0x28(%rsp), %ecx
movzwl 0x2(%rax,%rcx,4), %eax
movl %eax, -0x48(%rsp)
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl -0x48(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1207af
movq -0x18(%rsp), %rax
movl -0x28(%rsp), %ecx
movzwl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rsp)
movl -0x4c(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x4c(%rsp), %eax
movzwl %ax, %eax
movq -0x8(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq -0x48(%rsp), %rdx
subq $0x10, %rdx
movq -0x8(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x1207f3
movq -0x18(%rsp), %rax
movl -0x28(%rsp), %ecx
movzwl (%rax,%rcx,4), %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl -0x48(%rsp), %ecx
movq -0x8(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
movl -0x28(%rsp), %eax
movl %eax, %ecx
leaq 0x1e5c0(%rip), %rax     # 0x13edc0
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rsp)
cmpl $0x0, -0x2c(%rsp)
je 0x12096d
movl -0x28(%rsp), %eax
movl %eax, %ecx
leaq 0x1e711(%rip), %rax     # 0x13ef30
movl (%rax,%rcx,4), %ecx
movl -0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rsp)
movl -0x2c(%rsp), %eax
movl %eax, -0x50(%rsp)
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl -0x50(%rsp), %ecx
cmpl %ecx, %eax
jle 0x12092d
movl -0x1c(%rsp), %eax
movl %eax, -0x54(%rsp)
movl -0x54(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x54(%rsp), %eax
movzwl %ax, %eax
movq -0x8(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq -0x50(%rsp), %rdx
subq $0x10, %rdx
movq -0x8(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x12096b
movl -0x1c(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl -0x50(%rsp), %ecx
movq -0x8(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
jmp 0x12096d
jmp 0x12096f
jmp 0x120971
movl -0x24(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x16fc(%rcx), %eax
jb 0x12019b
jmp 0x120988
movq -0x10(%rsp), %rax
movzwl 0x402(%rax), %eax
movl %eax, -0x58(%rsp)
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl -0x58(%rsp), %ecx
cmpl %ecx, %eax
jle 0x120a99
movq -0x10(%rsp), %rax
movzwl 0x400(%rax), %eax
movl %eax, -0x5c(%rsp)
movl -0x5c(%rsp), %eax
movzwl %ax, %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x5c(%rsp), %eax
movzwl %ax, %eax
movq -0x8(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq -0x8(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq -0x58(%rsp), %rdx
subq $0x10, %rdx
movq -0x8(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x120adc
movq -0x10(%rsp), %rax
movzwl 0x400(%rax), %edx
movq -0x8(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq -0x8(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl -0x58(%rsp), %ecx
movq -0x8(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
movq -0x10(%rsp), %rax
movzwl 0x402(%rax), %ecx
movq -0x8(%rsp), %rax
movl %ecx, 0x171c(%rax)
retq
nopw %cs:(%rax,%rax)