// File: /workspace/github_c_makefile_star2_O3/DavidSM64[P]DKR-Decompressor/DKRGzip.c
// Function: ct_init()
void ct_init() {
    int n;        /* iterates over tree elements */
    int bits;     /* bit counter */
    int length;   /* length value */
    int code;     /* code value */
    int dist;     /* distance index */
        
    if (static_dtree[0].Len != 0) return; /* ct_init already called */

    /* Initialize the mapping length (0..255) -> length code (0..28) */
    length = 0;
    for (code = 0; code < LENGTH_CODES-1; code++) {
        base_length[code] = length;
        for (n = 0; n < (1<<extra_lbits[code]); n++) {
            length_code[length++] = (u8)code;
        }
    }
    // Assert (length == 256, "ct_init: length != 256");
    /* Note that the length 255 (match length 258) can be represented
     * in two different ways: code 284 + 5 bits or code 285, so we
     * overwrite length_code[255] to use the best encoding:
     */
    length_code[length-1] = (u8)code;

    /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
    dist = 0;
    for (code = 0 ; code < 16; code++) {
        base_dist[code] = dist;
        for (n = 0; n < (1<<extra_dbits[code]); n++) {
            dist_code[dist++] = (u8)code;
        }
    }
    // Assert (dist == 256, "ct_init: dist != 256");
    dist >>= 7; /* from now on, all distances are divided by 128 */
    for ( ; code < D_CODES; code++) {
        base_dist[code] = dist << 7;
        for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
            dist_code[256 + dist++] = (u8)code;
        }
    }
    // Assert (dist == 256, "ct_init: 256+dist != 512");

    /* Construct the codes of the static literal tree */
    for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
    n = 0;
    while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
    while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
    while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
    while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
    /* Codes 286 and 287 do not exist, but we must include them in the
     * tree construction to get a canonical Huffman tree (longest code
     * all ones)
     */
    gen_codes((ct_data *)static_ltree, L_CODES+1);

    /* The static distance tree is trivial: */
    for (n = 0; n < D_CODES; n++) {
        static_dtree[n].Len = 5;
        static_dtree[n].Code = bi_reverse(n, 5);
    }

    /* Initialize the first block of the first file: */
    init_block();
}

// Assembly:
cmpw $0x0, 0x56ea(%rip)      # 0xba62
je 0x637b
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
leaq 0x664e(%rip), %r15      # 0xc9e0
leaq 0x40a7(%rip), %r13      # 0xa440
xorl %r12d, %r12d
movl %r12d, (%r15,%rbx,4)
movl (%r13,%rbx,4), %ecx
cmpq $0x1f, %rcx
je 0x63da
movl $0x1, %r14d
shlq %cl, %r14
movslq %r12d, %rdi
leaq 0x6322(%rip), %rax      # 0xc6e0
addq %rax, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x20f0
negl %r14d
xorl %eax, %eax
decl %eax
cmpl %eax, %r14d
jne 0x63d0
subl %eax, %r12d
incq %rbx
cmpq $0x1c, %rbx
jne 0x639c
movslq %r12d, %rax
leaq 0x62f3(%rip), %rcx      # 0xc6e0
movb $0x1c, -0x1(%rax,%rcx)
xorl %ebx, %ebx
leaq 0x6665(%rip), %r15      # 0xca60
leaq 0x40be(%rip), %r12      # 0xa4c0
xorl %r13d, %r13d
movl %r13d, (%r15,%rbx,4)
movl (%r12,%rbx,4), %ecx
cmpq $0x1f, %rcx
je 0x6442
movl $0x1, %r14d
shlq %cl, %r14
movslq %r13d, %rdi
leaq 0x63ba(%rip), %rax      # 0xc7e0
addq %rax, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x20f0
negl %r14d
xorl %eax, %eax
decl %eax
cmpl %eax, %r14d
jne 0x6438
subl %eax, %r13d
incq %rbx
cmpq $0x10, %rbx
jne 0x6405
sarl $0x7, %r13d
movl $0x10, %ebx
movl %r13d, %eax
shll $0x7, %eax
movl %eax, (%r15,%rbx,4)
movl (%r12,%rbx,4), %ecx
addl $-0x7, %ecx
cmpl $0x1f, %ecx
je 0x64ad
movl $0x1, %r14d
shll %cl, %r14d
leal 0x100(%r13), %eax
movslq %eax, %rdi
leaq 0x635c(%rip), %rax      # 0xc7e0
addq %rax, %rdi
cmpl $0x2, %r14d
movl $0x1, %eax
cmovll %eax, %r14d
movl %ebx, %esi
movq %r14, %rdx
callq 0x20f0
negl %r14d
xorl %eax, %eax
decl %eax
cmpl %eax, %r14d
jne 0x64a3
subl %eax, %r13d
incq %rbx
cmpq $0x1e, %rbx
jne 0x6454
xorps %xmm0, %xmm0
movaps %xmm0, 0x56d0(%rip)     # 0xbb90
movaps %xmm0, 0x56b9(%rip)     # 0xbb80
xorl %ecx, %ecx
leaq 0x5110(%rip), %rax      # 0xb5e0
movw $0x8, 0x2(%rax,%rcx,4)
incq %rcx
cmpq $0x90, %rcx
jne 0x64d0
xorl %ecx, %ecx
movw $0x9, 0x242(%rax,%rcx,4)
incq %rcx
cmpq $0x70, %rcx
jne 0x64e5
movw $0x70, 0x5691(%rip)     # 0xbb92
xorl %ecx, %ecx
movw $0x7, 0x402(%rax,%rcx,4)
incq %rcx
cmpq $0x18, %rcx
jne 0x6503
movw $0x18, 0x566f(%rip)     # 0xbb8e
xorl %ecx, %ecx
movw $0x8, 0x462(%rax,%rcx,4)
incq %rcx
cmpq $0x8, %rcx
jne 0x6521
movw $0x98, 0x5653(%rip)     # 0xbb90
leaq 0x509c(%rip), %rdi      # 0xb5e0
movl $0x11f, %esi            # imm = 0x11F
callq 0x4eda
xorl %eax, %eax
leaq 0x5509(%rip), %rcx      # 0xba60
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movw $0x5, 0x2(%rcx,%rax,4)
movl $0x6, %edx
movl %eax, %esi
xorl %r8d, %r8d
movl %esi, %edi
andl $0x1, %edi
orl %r8d, %edi
shrl %esi
leal (%rdi,%rdi), %r8d
decl %edx
cmpl $0x1, %edx
ja 0x6576
movw %di, (%rcx,%rax,4)
incq %rax
cmpq $0x1e, %rax
jne 0x6565
jmp 0x4f55