// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x7, -0x24(%rbp)
movl $0x4, -0x28(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x9b7a
movl $0x8a, -0x24(%rbp)
movl $0x3, -0x28(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0x9d13
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl 0x2(%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl -0x24(%rbp), %eax
jge 0x9bc3
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x9bc3
jmp 0x9d05
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x9c04
jmp 0x9bcd
movslq -0x18(%rbp), %rcx
leaq 0x7f68(%rip), %rax      # 0x11b40
movzwl (%rax,%rcx,4), %edi
movslq -0x18(%rbp), %rcx
leaq 0x7f59(%rip), %rax      # 0x11b40
movzwl 0x2(%rax,%rcx,4), %esi
callq 0x8ed0
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jne 0x9bcd
jmp 0x9cb6
cmpl $0x0, -0x18(%rbp)
je 0x9c64
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x9c3f
movslq -0x18(%rbp), %rcx
leaq 0x7f23(%rip), %rax      # 0x11b40
movzwl (%rax,%rcx,4), %edi
movslq -0x18(%rbp), %rcx
leaq 0x7f14(%rip), %rax      # 0x11b40
movzwl 0x2(%rax,%rcx,4), %esi
callq 0x8ed0
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movzwl 0x7f3a(%rip), %edi      # 0x11b80
movzwl 0x7f35(%rip), %esi      # 0x11b82
callq 0x8ed0
movl -0x20(%rbp), %edi
subl $0x3, %edi
movl $0x2, %esi
callq 0x8ed0
jmp 0x9cb4
cmpl $0xa, -0x20(%rbp)
jg 0x9c8f
movzwl 0x7f13(%rip), %edi      # 0x11b84
movzwl 0x7f0e(%rip), %esi      # 0x11b86
callq 0x8ed0
movl -0x20(%rbp), %edi
subl $0x3, %edi
movl $0x3, %esi
callq 0x8ed0
jmp 0x9cb2
movzwl 0x7ef2(%rip), %edi      # 0x11b88
movzwl 0x7eed(%rip), %esi      # 0x11b8a
callq 0x8ed0
movl -0x20(%rbp), %edi
subl $0xb, %edi
movl $0x7, %esi
callq 0x8ed0
jmp 0x9cb4
jmp 0x9cb6
jmp 0x9cb8
movl $0x0, -0x20(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x9cdb
movl $0x8a, -0x24(%rbp)
movl $0x3, -0x28(%rbp)
jmp 0x9d03
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x9cf3
movl $0x6, -0x24(%rbp)
movl $0x3, -0x28(%rbp)
jmp 0x9d01
movl $0x7, -0x24(%rbp)
movl $0x4, -0x28(%rbp)
jmp 0x9d03
jmp 0x9d05
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x9b81
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)