// File: /workspace/github_c_makefile_star2_O3/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 0x1007eaf(%rip), %rax   # 0x100db18
movl 0x7e71(%rip), %ecx      # 0xdae0
leal 0x1(%rcx), %edx
movl %edx, 0x7e68(%rip)      # 0xdae0
movb %sil, (%rax,%rcx)
movslq %esi, %rax
testl %edi, %edi
je 0x5cf3
leaq 0x6a56(%rip), %rcx      # 0xc6e0
movzbl (%rax,%rcx), %eax
leaq 0x4f4b(%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 0x6b24(%rip), %rdx      # 0xc7e0
movzbl (%rax,%rdx), %eax
leaq 0x5819(%rip), %rdx      # 0xb4e0
incw (%rdx,%rax,4)
movl 0x7e13(%rip), %eax      # 0xdae4
leal 0x1(%rax), %edx
movl %edx, 0x7e0a(%rip)      # 0xdae4
leaq 0x1037e5f(%rip), %rdx   # 0x103db40
movw %cx, (%rdx,%rax,2)
movb 0x7e02(%rip), %al       # 0xdaed
orb %al, 0x7dfb(%rip)       # 0xdaec
jmp 0x5d04
leaq 0x4ee6(%rip), %rcx      # 0xabe0
incw (%rcx,%rax,4)
movb 0x7de9(%rip), %al       # 0xdaed
addb %al, %al
movb %al, 0x7de1(%rip)       # 0xdaed
movl 0x7dce(%rip), %ecx      # 0xdae0
testb $0x7, %cl
jne 0x5d44
movb 0x7dcf(%rip), %al       # 0xdaec
movl 0x7dc5(%rip), %edx      # 0xdae8
leal 0x1(%rdx), %esi
movl %esi, 0x7dbc(%rip)      # 0xdae8
leaq 0x6dad(%rip), %rsi      # 0xcae0
movb %al, (%rdx,%rsi)
movb $0x0, 0x7daf(%rip)      # 0xdaec
movb $0x1, 0x7da9(%rip)      # 0xdaed
testl $0xfff, %ecx            # imm = 0xFFF
jne 0x5db9
cmpl $0x2, 0x4e2d(%rip)      # 0xab80
jle 0x5db9
leal (,%rcx,8), %edx
movl 0x4e4a(%rip), %esi      # 0xabac
movl 0x4e38(%rip), %eax      # 0xaba0
xorl %edi, %edi
leaq 0x576f(%rip), %r8       # 0xb4e0
leaq 0x4748(%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 0x5d78
movl 0x7d48(%rip), %edi      # 0xdae4
movl %ecx, %r8d
shrl %r8d
cmpl %r8d, %edi
jae 0x5dbf
subl %eax, %esi
shrl $0x3, %edx
shrl %esi
movl $0x1, %eax
cmpl %esi, %edx
jae 0x5dbf
jmp 0x5dd6
movl 0x7d25(%rip), %edi      # 0xdae4
cmpl $0x7fff, %ecx           # imm = 0x7FFF
sete %al
cmpl $0x8000, %edi           # imm = 0x8000
sete %cl
orb %al, %cl
movzbl %cl, %eax
popq %rbp
retq