// File: /workspace/github_c_makefile_star2_O2/DavidSM64[P]DKR-Decompressor/DKRGzip.c
// Function: send_tree(ct_data*, int)
void send_tree (ct_data* tree, int max_code) {
    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(curlen, bl_tree); } while (--count != 0);

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

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

        } else {
            send_code(REPZ_11_138, bl_tree); send_bits(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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movzwl 0x2(%rdi), %r15d
xorl %eax, %eax
testl %r15d, %r15d
movl $0x8a, %edx
pushq $0x7
popq %rcx
cmovel %edx, %ecx
setne %al
addl $0x3, %eax
movslq %esi, %r8
pushq $-0x1
popq %rsi
xorl %r12d, %r12d
pushq $-0xb
popq %r9
movl %esi, %ebx
movl %ebx, %edx
movl %r9d, %r13d
cmpq %r8, %r12
jg 0x51b0
movl %r15d, %ebx
movl %esi, %r14d
movzwl 0x6(%rdi,%r12,4), %r15d
incq %r12
leal 0xc(%r13), %esi
incl %r13d
cmpl %ecx, %esi
jge 0x50bd
leal -0x1(%r14), %esi
cmpl %r15d, %ebx
je 0x5091
leal 0xb(%r13), %esi
movl %ebx, %ecx
cmpl %eax, %esi
movq %rdi, -0x38(%rbp)
movq %r8, -0x30(%rbp)
jge 0x50f4
leaq 0x69fa(%rip), %rax      # 0xbad0
movzwl (%rax,%rcx,4), %edi
movzwl 0x2(%rax,%rcx,4), %esi
movq %rcx, %r13
callq 0x497b
movq %r13, %rcx
incl %r14d
jne 0x50cf
jmp 0x517b
leal 0xa(%r13), %r14d
testl %ebx, %ebx
je 0x5139
cmpl %edx, %ebx
leaq 0x69cb(%rip), %rax      # 0xbad0
je 0x5118
movzwl (%rax,%rcx,4), %edi
movzwl 0x2(%rax,%rcx,4), %esi
callq 0x497b
movl %r14d, %esi
movzwl 0x69f1(%rip), %edi      # 0xbb10
movl %esi, %r14d
movzwl 0x69e9(%rip), %esi      # 0xbb12
callq 0x497b
addl $-0x3, %r14d
movl %r14d, %edi
pushq $0x2
jmp 0x5175
cmpl $0x9, %r14d
ja 0x515d
movzwl 0x69ce(%rip), %edi      # 0xbb14
movzwl 0x69c9(%rip), %esi      # 0xbb16
callq 0x497b
addl $0x8, %r13d
movl %r13d, %edi
pushq $0x3
jmp 0x5175
movzwl 0x69b4(%rip), %edi      # 0xbb18
movzwl 0x69af(%rip), %esi      # 0xbb1a
callq 0x497b
movl %r13d, %edi
pushq $0x7
popq %rsi
callq 0x497b
xorl %ecx, %ecx
cmpl %r15d, %ebx
sete %cl
pushq $0x4
popq %rax
subl %ecx, %eax
xorl $0x7, %ecx
testl %r15d, %r15d
movl $0x8a, %edx
cmovel %edx, %ecx
pushq $0x3
popq %rdx
cmovel %edx, %eax
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %r8
pushq $-0x1
popq %rsi
pushq $-0xb
popq %r9
jmp 0x508c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq