// File: /workspace/github_c_makefile_star2_O1/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, 0x55e7(%rip)      # 0xba62
je 0x647e
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
leaq 0x654b(%rip), %r15      # 0xc9e0
leaq 0x3fa4(%rip), %r13      # 0xa440
xorl %r12d, %r12d
movl %r12d, (%r15,%rbx,4)
movl (%r13,%rbx,4), %ecx
cmpl $0x1f, %ecx
je 0x64e9
movl $0x1, %r14d
shll %cl, %r14d
movslq %r12d, %rdi
leaq 0x6220(%rip), %rax      # 0xc6e0
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 0x64df
subl %eax, %r12d
incq %rbx
cmpq $0x1c, %rbx
jne 0x649f
movslq %r12d, %rax
leaq 0x61e4(%rip), %rcx      # 0xc6e0
movb $0x1c, -0x1(%rax,%rcx)
xorl %ebx, %ebx
leaq 0x6556(%rip), %r15      # 0xca60
leaq 0x3faf(%rip), %r12      # 0xa4c0
xorl %r13d, %r13d
movl %r13d, (%r15,%rbx,4)
movl (%r12,%rbx,4), %ecx
cmpl $0x1f, %ecx
je 0x655d
movl $0x1, %r14d
shll %cl, %r14d
movslq %r13d, %rdi
leaq 0x62ac(%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 0x6553
subl %eax, %r13d
incq %rbx
cmpq $0x10, %rbx
jne 0x6514
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 0x65c8
movl $0x1, %r14d
shll %cl, %r14d
leal 0x100(%r13), %eax
movslq %eax, %rdi
leaq 0x6241(%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 0x65be
subl %eax, %r13d
incq %rbx
cmpq $0x1e, %rbx
jne 0x656f
xorps %xmm0, %xmm0
movaps %xmm0, 0x55b5(%rip)     # 0xbb90
movaps %xmm0, 0x559e(%rip)     # 0xbb80
xorl %edx, %edx
movzwl 0x55a5(%rip), %ecx      # 0xbb90
leaq 0x4fee(%rip), %rax      # 0xb5e0
movw $0x8, 0x2(%rax,%rdx,4)
incq %rdx
cmpq $0x90, %rdx
jne 0x65f2
addl $0x90, %ecx
movw %cx, 0x557e(%rip)       # 0xbb90
movzwl 0x5579(%rip), %ecx      # 0xbb92
xorl %edx, %edx
movw $0x9, 0x242(%rax,%rdx,4)
incq %rdx
cmpq $0x70, %rdx
jne 0x661b
addl $0x70, %ecx
movw %cx, 0x555a(%rip)       # 0xbb92
movzwl 0x554f(%rip), %ecx      # 0xbb8e
xorl %edx, %edx
movw $0x7, 0x402(%rax,%rdx,4)
incq %rdx
cmpq $0x18, %rdx
jne 0x6641
addl $0x18, %ecx
movw %cx, 0x5530(%rip)       # 0xbb8e
movzwl 0x552b(%rip), %ecx      # 0xbb90
xorl %edx, %edx
movw $0x8, 0x462(%rax,%rdx,4)
incq %rdx
cmpq $0x8, %rdx
jne 0x6667
addl $0x8, %ecx
movw %cx, 0x550c(%rip)       # 0xbb90
leaq 0x4f55(%rip), %rdi      # 0xb5e0
movl $0x11f, %esi            # imm = 0x11F
callq 0x4ff4
xorl %eax, %eax
leaq 0x53c2(%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 0x66bd
movw %di, (%rcx,%rax,4)
incq %rax
cmpq $0x1e, %rax
jne 0x66ac
jmp 0x5076