// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/trees.c
// Function: send_tree
local void send_tree (s, tree, max_code)
    deflate_state *s;
    ct_data *tree; /* the tree to be scanned */
    int max_code;       /* and its largest code of non zero frequency */
{
    int n;                     /* iterates over all tree elements */
    int prevlen = -1;          /* last emitted length */
    int curlen;                /* length of current code */
    int nextlen = tree[0].Len; /* length of next code */
    int count = 0;             /* repeat count of the current code */
    int max_count = 7;         /* max repeat count */
    int min_count = 4;         /* min repeat count */

    /* tree[max_code+1].Len = -1; */  /* guard already set */
    if (nextlen == 0) max_count = 138, min_count = 3;

    for (n = 0; n <= max_code; n++) {
        curlen = nextlen; nextlen = tree[n+1].Len;
        if (++count < max_count && curlen == nextlen) {
            continue;
        } else if (count < min_count) {
            do { send_code(s, curlen, s->bl_tree); } while (--count != 0);

        } else if (curlen != 0) {
            if (curlen != prevlen) {
                send_code(s, curlen, s->bl_tree); count--;
            }
            Assert(count >= 3 && count <= 6, " 3_6?");
            send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);

        } else if (count <= 10) {
            send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);

        } else {
            send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
        }
        count = 0; prevlen = curlen;
        if (nextlen == 0) {
            max_count = 138, min_count = 3;
        } else if (curlen == nextlen) {
            max_count = 6, min_count = 3;
        } else {
            max_count = 7, min_count = 4;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movzwl 0x2(%rsi), %r9d
xorl %ecx, %ecx
testl %r9d, %r9d
setne %cl
movl $0x8a, %eax
movl $0x7, %r13d
cmovel %eax, %r13d
addl $0x3, %ecx
movslq %edx, %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r11d, %r11d
movl $0x10, %r8d
movl %eax, %r10d
movl %eax, %ebp
movl %eax, %r12d
cmpq %rdx, %r11
jg 0x8b571
movl %r9d, %r15d
movl %ebp, %eax
movzwl 0x6(%rsi,%r11,4), %r9d
incq %r11
leal 0x2(%r12), %ebp
incl %r12d
cmpl %r13d, %ebp
jge 0x8b0ff
leal -0x1(%rax), %ebp
cmpl %r9d, %r15d
je 0x8b0d3
leal 0x1(%r12), %ebp
movl %r15d, %r13d
cmpl %ecx, %ebp
jge 0x8b1a6
movl 0x1724(%rdi), %ecx
movzwl 0xaae(%rdi,%r13,4), %r10d
movl %r8d, %ebx
subl %r10d, %ebx
movzwl 0xaac(%rdi,%r13,4), %ebp
movl %ebp, %r12d
shll %cl, %r12d
orw 0x1720(%rdi), %r12w
movw %r12w, 0x1720(%rdi)
cmpl %ebx, %ecx
jle 0x8b190
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %r14d
movl %r14d, 0x28(%rdi)
movb %r12b, (%rcx,%rbx)
movb 0x1721(%rdi), %cl
movq 0x10(%rdi), %rbx
movl 0x28(%rdi), %r14d
leal 0x1(%r14), %r12d
movl %r12d, 0x28(%rdi)
movb %cl, (%rbx,%r14)
movl 0x1724(%rdi), %ebx
movb $0x10, %cl
subb %bl, %cl
shrl %cl, %ebp
movw %bp, 0x1720(%rdi)
leal (%r10,%rbx), %ecx
addl $-0x10, %ecx
jmp 0x8b193
addl %r10d, %ecx
movl %ecx, 0x1724(%rdi)
incl %eax
jne 0x8b115
jmp 0x8b53a
movl 0x1724(%rdi), %eax
testl %r15d, %r15d
je 0x8b1c2
cmpl %r10d, %r15d
jne 0x8b245
movl %ebp, %r12d
jmp 0x8b33b
movzwl 0x1720(%rdi), %r13d
cmpl $0x9, %r12d
ja 0x8b2c1
movzwl 0xaf2(%rdi), %r10d
movzwl 0xaf0(%rdi), %ebp
movl %ebp, %ebx
movl %eax, %ecx
shll %cl, %ebx
movl %r8d, %ecx
subl %r10d, %ecx
orl %ebx, %r13d
cmpl %ecx, %eax
jle 0x8b431
movw %r13w, 0x1720(%rdi)
movq 0x10(%rdi), %rax
movl 0x28(%rdi), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x28(%rdi)
movb %r13b, (%rax,%rcx)
movb 0x1721(%rdi), %al
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %r14d
movl %r14d, 0x28(%rdi)
movb %al, (%rcx,%rbx)
movl 0x1724(%rdi), %eax
movb $0x10, %cl
subb %al, %cl
shrl %cl, %ebp
addl %r10d, %eax
addl $-0x10, %eax
movl %ebp, %r13d
jmp 0x8b434
movzwl 0xaae(%rdi,%r13,4), %r10d
movl %r8d, %ebx
subl %r10d, %ebx
movzwl 0xaac(%rdi,%r13,4), %ebp
movl %ebp, %r13d
movl %eax, %ecx
shll %cl, %r13d
orw 0x1720(%rdi), %r13w
movw %r13w, 0x1720(%rdi)
cmpl %ebx, %eax
jle 0x8b332
movq 0x10(%rdi), %rax
movl 0x28(%rdi), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x28(%rdi)
movb %r13b, (%rax,%rcx)
movb 0x1721(%rdi), %al
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %r14d
movl %r14d, 0x28(%rdi)
movb %al, (%rcx,%rbx)
movl 0x1724(%rdi), %eax
movb $0x10, %cl
subb %al, %cl
shrl %cl, %ebp
movw %bp, 0x1720(%rdi)
addl %r10d, %eax
addl $-0x10, %eax
jmp 0x8b335
movzwl 0xaf6(%rdi), %r10d
movzwl 0xaf4(%rdi), %ebp
movl %ebp, %ebx
movl %eax, %ecx
shll %cl, %ebx
movl %r8d, %ecx
subl %r10d, %ecx
orl %ebx, %r13d
cmpl %ecx, %eax
jle 0x8b4a2
movw %r13w, 0x1720(%rdi)
movq 0x10(%rdi), %rax
movl 0x28(%rdi), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x28(%rdi)
movb %r13b, (%rax,%rcx)
movb 0x1721(%rdi), %al
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %r14d
movl %r14d, 0x28(%rdi)
movb %al, (%rcx,%rbx)
movl 0x1724(%rdi), %eax
movb $0x10, %cl
subb %al, %cl
shrl %cl, %ebp
addl %r10d, %eax
addl $-0x10, %eax
movl %ebp, %r13d
jmp 0x8b4a5
addl %r10d, %eax
movl %eax, 0x1724(%rdi)
movzwl 0xaee(%rdi), %r10d
movl %r8d, %ebx
movzwl 0xaec(%rdi), %ebp
movl %ebp, %r13d
movl %eax, %ecx
shll %cl, %r13d
subl %r10d, %ebx
orw 0x1720(%rdi), %r13w
cmpl %ebx, %eax
jle 0x8b3ac
movw %r13w, 0x1720(%rdi)
movq 0x10(%rdi), %rax
movl 0x28(%rdi), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x28(%rdi)
movb %r13b, (%rax,%rcx)
movb 0x1721(%rdi), %al
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %r14d
movl %r14d, 0x28(%rdi)
movb %al, (%rcx,%rbx)
movl 0x1724(%rdi), %eax
movb $0x10, %cl
subb %al, %cl
shrl %cl, %ebp
addl %r10d, %eax
addl $-0x10, %eax
movl %ebp, %r13d
jmp 0x8b3af
addl %r10d, %eax
movl %eax, 0x1724(%rdi)
addl $0xfffd, %r12d          # imm = 0xFFFD
cmpl $0xf, %eax
jl 0x8b419
movzwl %r12w, %r10d
movl %eax, %ecx
shll %cl, %r12d
orl %r12d, %r13d
movw %r13w, 0x1720(%rdi)
movq 0x10(%rdi), %rax
movl 0x28(%rdi), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x28(%rdi)
movb %r13b, (%rax,%rcx)
movb 0x1721(%rdi), %al
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %ebp
movl %ebp, 0x28(%rdi)
movb %al, (%rcx,%rbx)
movl 0x1724(%rdi), %eax
movb $0x10, %cl
subb %al, %cl
shrl %cl, %r10d
movw %r10w, 0x1720(%rdi)
addl $-0xe, %eax
jmp 0x8b534
movl %eax, %ecx
shll %cl, %r12d
orl %r12d, %r13d
movw %r13w, 0x1720(%rdi)
addl $0x2, %eax
jmp 0x8b534
addl %r10d, %eax
movl %eax, 0x1724(%rdi)
addl $0xfffe, %r12d          # imm = 0xFFFE
cmpl $0xe, %eax
jl 0x8b50c
movzwl %r12w, %r10d
movl %eax, %ecx
shll %cl, %r12d
orl %r12d, %r13d
movw %r13w, 0x1720(%rdi)
movq 0x10(%rdi), %rax
movl 0x28(%rdi), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x28(%rdi)
movb %r13b, (%rax,%rcx)
movb 0x1721(%rdi), %al
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %ebp
movl %ebp, 0x28(%rdi)
movb %al, (%rcx,%rbx)
movl 0x1724(%rdi), %eax
movb $0x10, %cl
subb %al, %cl
shrl %cl, %r10d
movw %r10w, 0x1720(%rdi)
addl $-0xd, %eax
jmp 0x8b534
addl %r10d, %eax
movl %eax, 0x1724(%rdi)
addl $0xfff6, %r12d          # imm = 0xFFF6
cmpl $0xa, %eax
jl 0x8b521
movzwl %r12w, %r10d
movl %eax, %ecx
shll %cl, %r12d
orl %r12d, %r13d
movw %r13w, 0x1720(%rdi)
movq 0x10(%rdi), %rax
movl 0x28(%rdi), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x28(%rdi)
movb %r13b, (%rax,%rcx)
movb 0x1721(%rdi), %al
movq 0x10(%rdi), %rcx
movl 0x28(%rdi), %ebx
leal 0x1(%rbx), %ebp
movl %ebp, 0x28(%rdi)
movb %al, (%rcx,%rbx)
movl 0x1724(%rdi), %eax
movb $0x10, %cl
subb %al, %cl
shrl %cl, %r10d
movw %r10w, 0x1720(%rdi)
addl $-0x9, %eax
jmp 0x8b534
movl %eax, %ecx
shll %cl, %r12d
orl %r12d, %r13d
movw %r13w, 0x1720(%rdi)
addl $0x3, %eax
jmp 0x8b534
movl %eax, %ecx
shll %cl, %r12d
orl %r12d, %r13d
movw %r13w, 0x1720(%rdi)
addl $0x7, %eax
movl %eax, 0x1724(%rdi)
xorl %r13d, %r13d
cmpl %r9d, %r15d
sete %r13b
movl $0x4, %ecx
subl %r13d, %ecx
xorl $0x7, %r13d
testl %r9d, %r9d
movl $0x3, %eax
cmovel %eax, %ecx
movl $0x8a, %eax
cmovel %eax, %r13d
movl %r15d, %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x8b0ce
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq