// File: tomfunkhouser[P]gaps/pkgs/png/trees.c
// Function: send_all_trees
local void send_all_trees(s, lcodes, dcodes, blcodes)
    deflate_state *s;
    int lcodes, dcodes, blcodes; /* number of codes for each tree */
{
    int rank;                    /* index in bl_order */

    Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
    Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
            "too many codes");
    Tracev((stderr, "\nbl counts: "));
    send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
    send_bits(s, dcodes-1,   5);
    send_bits(s, blcodes-4,  4); /* not -3 as stated in appnote.txt */
    for (rank = 0; rank < blcodes; rank++) {
        Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
        send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
    }
    Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));

    send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
    Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));

    send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
    Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movl %edx, 0x28(%rsp)
movl %ecx, 0x24(%rsp)
movl $0x5, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jle 0x120c1b
movl 0x2c(%rsp), %eax
subl $0x101, %eax            # imm = 0x101
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movzwl %ax, %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl 0x18(%rsp), %eax
movzwl %ax, %eax
movq 0x30(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq 0x1c(%rsp), %rdx
subq $0x10, %rdx
movq 0x30(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x120c5e
movl 0x2c(%rsp), %eax
subl $0x101, %eax            # imm = 0x101
movzwl %ax, %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl 0x1c(%rsp), %ecx
movq 0x30(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
movl $0x5, 0x14(%rsp)
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl 0x14(%rsp), %ecx
cmpl %ecx, %eax
jle 0x120d62
movl 0x28(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movzwl %ax, %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl 0x10(%rsp), %eax
movzwl %ax, %eax
movq 0x30(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq 0x14(%rsp), %rdx
subq $0x10, %rdx
movq 0x30(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x120da3
movl 0x28(%rsp), %eax
subl $0x1, %eax
movzwl %ax, %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
movl $0x4, 0xc(%rsp)
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jle 0x120ea7
movl 0x24(%rsp), %eax
subl $0x4, %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movzwl %ax, %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl 0x8(%rsp), %eax
movzwl %ax, %eax
movq 0x30(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq 0xc(%rsp), %rdx
subq $0x10, %rdx
movq 0x30(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x120ee8
movl 0x24(%rsp), %eax
subl $0x4, %eax
movzwl %ax, %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl 0xc(%rsp), %ecx
movq 0x30(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x12107b
movl $0x3, 0x4(%rsp)
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %eax
movl $0x10, %ecx
subl 0x4(%rsp), %ecx
cmpl %ecx, %eax
jle 0x121015
movq 0x30(%rsp), %rax
movslq 0x20(%rsp), %rdx
leaq 0x1df5d(%rip), %rcx     # 0x13ee90
movzbl (%rcx,%rdx), %ecx
movzwl 0xaae(%rax,%rcx,4), %eax
movl %eax, (%rsp)
movl (%rsp), %eax
movzwl %ax, %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
andl $0xff, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rsi
movl 0x28(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x28(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl (%rsp), %eax
movzwl %ax, %eax
movq 0x30(%rsp), %rcx
movslq 0x1724(%rcx), %rdx
movl $0x10, %ecx
subq %rdx, %rcx
sarl %cl, %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x1720(%rax)
movslq 0x4(%rsp), %rdx
subq $0x10, %rdx
movq 0x30(%rsp), %rax
movslq 0x1724(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x1724(%rax)
jmp 0x121069
movq 0x30(%rsp), %rax
movslq 0x20(%rsp), %rdx
leaq 0x1de6a(%rip), %rcx     # 0x13ee90
movzbl (%rcx,%rdx), %ecx
movzwl 0xaae(%rax,%rcx,4), %edx
movq 0x30(%rsp), %rax
movl 0x1724(%rax), %ecx
shll %cl, %edx
movq 0x30(%rsp), %rax
movzwl 0x1720(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1720(%rax)
movl 0x4(%rsp), %ecx
movq 0x30(%rsp), %rax
addl 0x1724(%rax), %ecx
movl %ecx, 0x1724(%rax)
jmp 0x12106b
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x120ef0
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0xc4, %rsi
movl 0x2c(%rsp), %edx
subl $0x1, %edx
callq 0x121bf0
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x9b8, %rsi            # imm = 0x9B8
movl 0x28(%rsp), %edx
subl $0x1, %edx
callq 0x121bf0
addq $0x38, %rsp
retq
nopw (%rax,%rax)