// File: /workspace/github_c_makefile_star2_O1/DavidSM64[P]DKR-Decompressor/DKRGzip.c
// Function: lm_init(unsigned short*)
void lm_init(u16* flags) {
    u32 j;

    if (level < 1 || level > 9) { 
        printf("bad pack level\n");
        return;
    }
    compr_level = level;

    /* Initialize the hash table. */
#if defined(MAXSEG_64K) && HASH_BITS == 15
    for (j = 0;  j < HASH_SIZE; j++) head[j] = 0;
#else
    bzero((char*)head, HASH_SIZE*sizeof(*head));
#endif
    /* prev will be initialized on the fly */

    /* rsync params */
    rsync_chunk_end = 0xFFFFFFFF;
    rsync_sum = 0;

    /* Set the default configuration parameters:
     */
    max_lazy_match   = configuration_table[level].max_lazy;
    good_match       = configuration_table[level].good_length;
#ifndef FU_SEARCH
    nice_match       = configuration_table[level].nice_length;
#endif
    max_chain_length = configuration_table[level].max_chain;
    if (level == 1) {
       *flags |= FAST;
    } else if (level == 9) {
       *flags |= SOW;
    }
    /* ??? reduce max_chain_length for binary files */

    strstart = 0;
    block_start = 0;

    lookahead = read_buf((char*)window, sizeof(int) <= 2 ? (unsigned)WSIZE : 2*WSIZE);

    if (lookahead == 0) {
       return;
    }
    
    /* Make sure that we always have enough lookahead. This is important
     * if input comes from a device su8 as a tty.
     */
    while (lookahead < MIN_LOOKAHEAD && !NO_MORE_INPUT){ 
        fill_window();
    }

    ins_h = 0;
    for (j=0; j<MIN_MATCH-1; j++) { 
        UPDATE_HASH(ins_h, window[j]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movl 0x448e(%rip), %r14d     # 0xab80
leal -0xa(%r14), %eax
cmpl $-0xa, %eax
ja 0x670b
leaq 0xc09(%rip), %rdi       # 0x730b
popq %rbx
popq %r14
popq %rbp
jmp 0x2260
movq %rdi, %rbx
movl %r14d, 0x44ab(%rip)     # 0xabc0
leaq 0x1027424(%rip), %rdi   # 0x102db40
movl $0x10000, %edx          # imm = 0x10000
xorl %esi, %esi
callq 0x20f0
movl $0xffffffff, 0x449a(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x448c(%rip)      # 0xabc8
leaq 0x3cad(%rip), %rax      # 0xa3f0
movzwl 0x2(%rax,%r14,8), %ecx
movl %ecx, 0x446d(%rip)      # 0xabbc
movzwl (%rax,%r14,8), %ecx
movl %ecx, 0x446a(%rip)      # 0xabc4
movzwl 0x4(%rax,%r14,8), %ecx
movl %ecx, 0x446a(%rip)      # 0xabd0
movzwl 0x6(%rax,%r14,8), %eax
movl %eax, 0x4446(%rip)      # 0xabb8
cmpl $0x1, %r14d
je 0x6784
cmpl $0x9, %r14d
jne 0x678b
movw $0x2, %ax
jmp 0x6788
movw $0x4, %ax
orw %ax, (%rbx)
xorl %eax, %eax
movl %eax, 0x4419(%rip)      # 0xabac
movl %eax, 0x4407(%rip)      # 0xaba0
leaq 0x10073a0(%rip), %rbx   # 0x100db40
movq %rbx, %rdi
movl $0x10000, %esi          # imm = 0x10000
callq 0x4d0e
movl %eax, 0x4401(%rip)      # 0xabb4
testl %eax, %eax
je 0x6804
cmpl $0x105, 0x43f3(%rip)    # imm = 0x105
ja 0x67d8
movl 0x1007357(%rip), %eax   # 0x100db20
cmpl %eax, 0x1007355(%rip)   # 0x100db24
je 0x67d8
callq 0x5ede
jmp 0x67b7
movl $0x0, 0x43c2(%rip)      # 0xaba4
xorl %eax, %eax
xorl %ecx, %ecx
shll $0x5, %ecx
movzbl (%rax,%rbx), %edx
andl $0x7fe0, %ecx           # imm = 0x7FE0
xorl %edx, %ecx
incq %rax
cmpq $0x1, %rax
je 0x67e6
movl %ecx, 0x43a0(%rip)      # 0xaba4
popq %rbx
popq %r14
popq %rbp
retq