// File: /workspace/github_c_makefile_star2_O1/DavidSM64[P]DKR-Decompressor/DKRGzip.c
// Function: ct_tally(int, int)
int ct_tally (int dist, int lc) {
    l_buf[last_lit++] = (u8)lc;
    if (dist == 0) {
        /* lc is the unmatched char */
        dyn_ltree[lc].Freq++;
    } else {
        /* Here, lc is the match length - MIN_MATCH */
        dist--;             /* dist = match distance - 1 */
        //Assert((u16)dist < (u16)MAX_DIST && (u16)lc <= (u16)(MAX_MATCH-MIN_MATCH) && (u16)d_code(dist) < (u16)D_CODES,  "ct_tally: bad match");

        dyn_ltree[length_code[lc]+LITERALS+1].Freq++;
        dyn_dtree[d_code(dist)].Freq++;

        d_buf[last_dist++] = (u16)dist;
        flags |= flag_bit;
    }
    flag_bit <<= 1;

    /* Output the flags if they fill a byte: */
    if ((last_lit & 7) == 0) {
        flag_buf[last_flags++] = flags;
        flags = 0, flag_bit = 1;
    }
    /* Try to guess if it is profitable to stop the current block here */
    if (level > 2 && (last_lit & 0xfff) == 0) {
        /* Compute an upper bound for the compressed length */
        u32 out_length = (u32)last_lit*8;
        u32 in_length = (u32)strstart-block_start;
        int dcode;
        for (dcode = 0; dcode < D_CODES; dcode++) {
            out_length += (u32)dyn_dtree[dcode].Freq*(5+extra_dbits[dcode]);
        }
        out_length >>= 3;
        // Trace((stderr,"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ", last_lit, last_dist, in_length, out_length, 100 - out_length*100/in_length));
        if (last_dist < last_lit/2 && out_length < in_length/2) return 1;
    }
    return (last_lit == IT_BUFSIZE-1 || last_dist == DIST_BUFSIZE);
    /* We avoid equality with IT_BUFSIZE because of wraparound at 64K
     * on 16 bit machines and because stored blocks are restricted to
     * 64K-1 bytes.
     */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x1007d98(%rip), %rax   # 0x100db18
movl 0x7d5a(%rip), %ecx      # 0xdae0
leal 0x1(%rcx), %edx
movl %edx, 0x7d51(%rip)      # 0xdae0
movb %sil, (%rax,%rcx)
movslq %esi, %rax
testl %edi, %edi
je 0x5e0a
leaq 0x693f(%rip), %rcx      # 0xc6e0
movzbl (%rax,%rcx), %eax
leaq 0x4e34(%rip), %rcx      # 0xabe0
incw 0x404(%rcx,%rax,4)
leal -0x1(%rdi), %eax
movslq %eax, %rcx
shrl $0x7, %eax
addl $0x100, %eax            # imm = 0x100
cmpl $0x101, %edi            # imm = 0x101
cmovlq %rcx, %rax
leaq 0x6a0d(%rip), %rdx      # 0xc7e0
movzbl (%rax,%rdx), %eax
leaq 0x5702(%rip), %rdx      # 0xb4e0
incw (%rdx,%rax,4)
movl 0x7cfc(%rip), %eax      # 0xdae4
leal 0x1(%rax), %edx
movl %edx, 0x7cf3(%rip)      # 0xdae4
leaq 0x1037d48(%rip), %rdx   # 0x103db40
movw %cx, (%rdx,%rax,2)
movb 0x7ceb(%rip), %al       # 0xdaed
orb %al, 0x7ce4(%rip)       # 0xdaec
jmp 0x5e15
leaq 0x4dcf(%rip), %rcx      # 0xabe0
incw (%rcx,%rax,4)
shlb 0x7cd2(%rip)            # 0xdaed
movl 0x7cbf(%rip), %ecx      # 0xdae0
testb $0x7, %cl
jne 0x5e53
movb 0x7cc0(%rip), %al       # 0xdaec
movl 0x7cb6(%rip), %edx      # 0xdae8
leal 0x1(%rdx), %esi
movl %esi, 0x7cad(%rip)      # 0xdae8
leaq 0x6c9e(%rip), %rsi      # 0xcae0
movb %al, (%rdx,%rsi)
movb $0x0, 0x7ca0(%rip)      # 0xdaec
movb $0x1, 0x7c9a(%rip)      # 0xdaed
testl $0xfff, %ecx            # imm = 0xFFF
jne 0x5ec1
cmpl $0x3, 0x4d1e(%rip)      # 0xab80
jl 0x5ec1
leal (,%rcx,8), %edx
movl 0x4d3b(%rip), %esi      # 0xabac
movl 0x4d29(%rip), %eax      # 0xaba0
xorl %edi, %edi
leaq 0x5660(%rip), %r8       # 0xb4e0
leaq 0x4639(%rip), %r9       # 0xa4c0
movzwl (%rdi,%r8), %r10d
movl (%rdi,%r9), %r11d
addl $0x5, %r11d
imull %r10d, %r11d
addl %r11d, %edx
addq $0x4, %rdi
cmpq $0x78, %rdi
jne 0x5e87
movl %ecx, %edi
shrl %edi
cmpl %edi, 0x7c35(%rip)      # 0xdae4
jae 0x5ec1
subl %eax, %esi
shrl $0x3, %edx
shrl %esi
movl $0x1, %eax
cmpl %esi, %edx
jb 0x5edc
cmpl $0x7fff, %ecx           # imm = 0x7FFF
sete %al
cmpl $0x8000, 0x7c10(%rip)   # imm = 0x8000
sete %cl
orb %al, %cl
movzbl %cl, %eax
popq %rbp
retq