// File: /workspace/github_c_makefile_star2_O2/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, 0x5c8f(%rip)      # 0xba52
je 0x5dc6
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %edx, %edx
leaq 0x6bf7(%rip), %rsi      # 0xc9d0
leaq 0x4650(%rip), %r8       # 0xa430
pushq $0x1
popq %rax
leaq 0x68e6(%rip), %rdi      # 0xc6d0
xorl %r10d, %r10d
xorl %r9d, %r9d
cmpq $0x1c, %r10
je 0x5e23
movslq %r9d, %r11
movl %r11d, (%rsi,%r10,4)
movb (%r8,%r10,4), %cl
movl %eax, %ebx
shll %cl, %ebx
testl %ebx, %ebx
cmovlel %edx, %ebx
addl %ebx, %r9d
movslq %r9d, %rcx
cmpq %r11, %rcx
je 0x5e1e
movb %r10b, (%r11,%rdi)
incq %r11
jmp 0x5e10
incq %r10
jmp 0x5df0
movslq %r9d, %rcx
movb $0x1c, -0x1(%rcx,%rdi)
xorl %r9d, %r9d
leaq 0x6c1b(%rip), %rdx      # 0xca50
leaq 0x4674(%rip), %rsi      # 0xa4b0
leaq 0x698d(%rip), %rdi      # 0xc7d0
xorl %r10d, %r10d
xorl %r8d, %r8d
cmpq $0x10, %r10
je 0x5e80
movb (%rsi,%r10,4), %cl
movl %eax, %r11d
shll %cl, %r11d
movl %r8d, (%rdx,%r10,4)
movslq %r8d, %rcx
testl %r11d, %r11d
cmovlel %r9d, %r11d
addl %r11d, %r8d
movslq %r8d, %r11
cmpq %rcx, %r11
je 0x5e7b
movb %r10b, (%rcx,%rdi)
incq %rcx
jmp 0x5e6d
incq %r10
jmp 0x5e49
sarl $0x7, %r8d
pushq $0x10
popq %r9
xorl %r10d, %r10d
cmpq $0x1e, %r9
je 0x5ed4
movl %r8d, %ebx
movb (%rsi,%r9,4), %cl
addb $-0x7, %cl
movl %eax, %r11d
shll %cl, %r11d
shll $0x7, %ebx
movl %ebx, (%rdx,%r9,4)
movslq %r8d, %rcx
testl %r11d, %r11d
cmovlel %r10d, %r11d
addq %rdi, %rcx
addq $0x100, %rcx            # imm = 0x100
xorl %ebx, %ebx
cmpl %ebx, %r11d
je 0x5ecc
movb %r9b, (%rcx,%rbx)
incq %rbx
jmp 0x5ebe
addl %ebx, %r8d
incq %r9
jmp 0x5e8b
xorl %eax, %eax
leaq 0x5c93(%rip), %rcx      # 0xbb70
cmpq $0x20, %rax
je 0x5eee
andw $0x0, (%rax,%rcx)
addq $0x2, %rax
jmp 0x5edd
movzwl 0x5c8b(%rip), %eax      # 0xbb80
xorl %edx, %edx
leaq 0x56d2(%rip), %rcx      # 0xb5d0
cmpq $0x90, %rdx
je 0x5f13
movw $0x8, 0x2(%rcx,%rdx,4)
incq %rdx
jmp 0x5efe
addl $0x90, %eax
movw %ax, 0x5c61(%rip)       # 0xbb80
movzwl 0x5c5c(%rip), %edx      # 0xbb82
xorl %esi, %esi
cmpq $0x70, %rsi
je 0x5f3f
movw $0x9, 0x242(%rcx,%rsi,4)
incl %edx
incq %rsi
jmp 0x5f28
movw %dx, 0x5c3c(%rip)       # 0xbb82
movzwl 0x5c31(%rip), %edx      # 0xbb7e
xorl %esi, %esi
cmpq $0x18, %rsi
je 0x5f66
movw $0x7, 0x402(%rcx,%rsi,4)
incl %edx
incq %rsi
jmp 0x5f4f
movw %dx, 0x5c11(%rip)       # 0xbb7e
xorl %edx, %edx
cmpq $0x8, %rdx
je 0x5f86
movw $0x8, 0x462(%rcx,%rdx,4)
incl %eax
incq %rdx
jmp 0x5f6f
movw %ax, 0x5bf3(%rip)       # 0xbb80
leaq 0x563c(%rip), %rdi      # 0xb5d0
movl $0x11f, %esi            # imm = 0x11F
callq 0x49fe
xorl %ebx, %ebx
leaq 0x5aa9(%rip), %r15      # 0xba50
pushq $0x5
popq %r14
cmpq $0x1e, %rbx
je 0x5fcd
movw $0x5, 0x2(%r15,%rbx,4)
movl %ebx, %edi
movl %r14d, %esi
callq 0x49dc
movw %ax, (%r15,%rbx,4)
incq %rbx
jmp 0x5fab
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4a6e