// File: /workspace/github_c_makefile_star2_O1/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:
testl %esi, %esi
js 0x581e
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movzwl 0x2(%rdi), %r8d
xorl %eax, %eax
testl %r8d, %r8d
setne %al
movl $0x8a, %ecx
movl $0x7, %edx
cmovnel %edx, %ecx
addl $0x3, %eax
incl %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
leaq 0x63ef(%rip), %rbx      # 0xbae0
xorl %r12d, %r12d
movq %rsi, -0x40(%rbp)
movq %rdi, -0x38(%rbp)
movl %r8d, %r13d
movzwl 0x6(%rdi,%r14,4), %r8d
leal 0x1(%r12), %r15d
cmpl %ecx, %r15d
jge 0x571c
cmpl %r8d, %r13d
jne 0x571c
movl %edx, %r13d
jmp 0x57fe
cmpl %eax, %r15d
movl %r8d, -0x2c(%rbp)
jge 0x5742
movl %r13d, %r12d
movzwl (%rbx,%r12,4), %edi
movzwl 0x2(%rbx,%r12,4), %esi
callq 0x4f64
decl %r15d
jne 0x5728
jmp 0x57cc
testl %r13d, %r13d
je 0x5781
cmpl %edx, %r13d
je 0x5760
movl %r13d, %eax
movzwl (%rbx,%rax,4), %edi
movzwl 0x2(%rbx,%rax,4), %esi
callq 0x4f64
movl %r12d, %r15d
movzwl 0x63b9(%rip), %edi      # 0xbb20
movzwl 0x63b4(%rip), %esi      # 0xbb22
callq 0x4f64
addl $-0x3, %r15d
movl %r15d, %edi
movl $0x2, %esi
jmp 0x57c7
cmpl $0x9, %r12d
jg 0x57a8
movzwl 0x6396(%rip), %edi      # 0xbb24
movzwl 0x6391(%rip), %esi      # 0xbb26
callq 0x4f64
addl $-0x2, %r12d
movl %r12d, %edi
movl $0x3, %esi
jmp 0x57c7
movzwl 0x6379(%rip), %edi      # 0xbb28
movzwl 0x6374(%rip), %esi      # 0xbb2a
callq 0x4f64
addl $-0xa, %r12d
movl %r12d, %edi
movl $0x7, %esi
callq 0x4f64
xorl %r15d, %r15d
movl -0x2c(%rbp), %r8d
testl %r8d, %r8d
je 0x57ec
xorl %ecx, %ecx
cmpl %r8d, %r13d
sete %cl
movl $0x4, %eax
subl %ecx, %eax
xorl $0x7, %ecx
jmp 0x57f6
movl $0x3, %eax
movl $0x8a, %ecx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdi
incq %r14
movl %r15d, %r12d
movl %r13d, %edx
cmpq %rsi, %r14
jne 0x56fc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq