// File: /workspace/github_c_makefile_star2_O0/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
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpl $0x1, 0x5a2d(%rip)      # 0x10be0
jl 0xb1be
cmpl $0x9, 0x5a24(%rip)      # 0x10be0
jle 0xb1d1
leaq 0x104a(%rip), %rdi      # 0xc20f
movb $0x0, %al
callq 0x2050
jmp 0xb353
movl 0x5a09(%rip), %eax      # 0x10be0
movl %eax, 0x5a43(%rip)      # 0x10c20
leaq 0x10189bc(%rip), %rdi   # 0x1023ba0
addq $0x10000, %rdi          # imm = 0x10000
xorl %esi, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x2100
movl $0xffffffff, 0x5a2b(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x5a1d(%rip)      # 0x10c28
movslq 0x59ce(%rip), %rcx      # 0x10be0
leaq 0x5237(%rip), %rax      # 0x10450
movzwl 0x2(%rax,%rcx,8), %eax
movl %eax, 0x59f8(%rip)      # 0x10c1c
movslq 0x59b5(%rip), %rcx      # 0x10be0
leaq 0x521e(%rip), %rax      # 0x10450
movzwl (%rax,%rcx,8), %eax
movl %eax, 0x59e8(%rip)      # 0x10c24
movslq 0x599d(%rip), %rcx      # 0x10be0
leaq 0x5206(%rip), %rax      # 0x10450
movzwl 0x4(%rax,%rcx,8), %eax
movl %eax, 0x59db(%rip)      # 0x10c30
movslq 0x5984(%rip), %rcx      # 0x10be0
leaq 0x51ed(%rip), %rax      # 0x10450
movzwl 0x6(%rax,%rcx,8), %eax
movl %eax, 0x59aa(%rip)      # 0x10c18
cmpl $0x1, 0x596b(%rip)      # 0x10be0
jne 0xb286
movq -0x8(%rbp), %rax
movzwl (%rax), %ecx
orl $0x4, %ecx
movw %cx, (%rax)
jmp 0xb29e
cmpl $0x9, 0x5953(%rip)      # 0x10be0
jne 0xb29c
movq -0x8(%rbp), %rax
movzwl (%rax), %ecx
orl $0x2, %ecx
movw %cx, (%rax)
jmp 0xb29e
movl $0x0, 0x5964(%rip)      # 0x10c0c
movl $0x0, 0x594e(%rip)      # 0x10c00
leaq 0x10088e7(%rip), %rdi   # 0x1013ba0
movl $0x10000, %esi          # imm = 0x10000
callq 0x8ab0
movl %eax, 0x594b(%rip)      # 0x10c14
cmpl $0x0, 0x5944(%rip)      # 0x10c14
jne 0xb2d4
jmp 0xb353
jmp 0xb2d6
xorl %eax, %eax
cmpl $0x106, 0x5932(%rip)    # imm = 0x106
movb %al, -0xd(%rbp)
jae 0xb2fb
movl 0x1008897(%rip), %eax   # 0x1013b84
cmpl 0x100888d(%rip), %eax   # 0x1013b80
sete %al
xorb $-0x1, %al
movb %al, -0xd(%rbp)
movb -0xd(%rbp), %al
testb $0x1, %al
jne 0xb304
jmp 0xb30b
callq 0xa610
jmp 0xb2d6
movl $0x0, 0x58ef(%rip)      # 0x10c04
movl $0x0, -0xc(%rbp)
cmpl $0x2, -0xc(%rbp)
jae 0xb353
movl 0x58dc(%rip), %eax      # 0x10c04
shll $0x5, %eax
movl -0xc(%rbp), %ecx
movl %ecx, %edx
leaq 0x1008869(%rip), %rcx   # 0x1013ba0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
andl $0x7fff, %eax           # imm = 0x7FFF
movl %eax, 0x58bc(%rip)      # 0x10c04
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xb31c
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)