// File: /workspace/github_c_makefile_star2_O2/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 0x100842e(%rip), %rax   # 0x100db08
movl 0x83f0(%rip), %ecx      # 0xdad0
leal 0x1(%rcx), %edx
movl %edx, 0x83e7(%rip)      # 0xdad0
movb %sil, (%rax,%rcx)
movslq %esi, %rax
testl %edi, %edi
je 0x5764
leaq 0x6fd5(%rip), %rcx      # 0xc6d0
movzbl (%rax,%rcx), %eax
leaq 0x54ca(%rip), %rcx      # 0xabd0
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 0x70a3(%rip), %rdx      # 0xc7d0
movzbl (%rax,%rdx), %eax
leaq 0x5d98(%rip), %rdx      # 0xb4d0
incw (%rdx,%rax,4)
movl 0x8392(%rip), %eax      # 0xdad4
leal 0x1(%rax), %edx
movl %edx, 0x8389(%rip)      # 0xdad4
leaq 0x10383de(%rip), %rdx   # 0x103db30
movw %cx, (%rdx,%rax,2)
movb 0x8381(%rip), %al       # 0xdadd
orb %al, 0x837a(%rip)       # 0xdadc
jmp 0x5775
leaq 0x5465(%rip), %rcx      # 0xabd0
incw (%rcx,%rax,4)
movb 0x8368(%rip), %al       # 0xdadd
addb %al, %al
movb %al, 0x8360(%rip)       # 0xdadd
movl 0x834d(%rip), %eax      # 0xdad0
testb $0x7, %al
jne 0x57b4
movb 0x834f(%rip), %cl       # 0xdadc
movl 0x8345(%rip), %edx      # 0xdad8
leal 0x1(%rdx), %esi
movl %esi, 0x833c(%rip)      # 0xdad8
leaq 0x732d(%rip), %rsi      # 0xcad0
movb %cl, (%rdx,%rsi)
movb $0x0, 0x832f(%rip)      # 0xdadc
movb $0x1, 0x8329(%rip)      # 0xdadd
testw $0xfff, %ax             # imm = 0xFFF
jne 0x5806
cmpl $0x2, 0x53af(%rip)      # 0xab70
jle 0x5806
leal (,%rax,8), %ecx
movl 0x53cc(%rip), %edx      # 0xab9c
movl 0x53ba(%rip), %esi      # 0xab90
xorl %edi, %edi
leaq 0x5cf1(%rip), %r8       # 0xb4d0
leaq 0x4cca(%rip), %r9       # 0xa4b0
cmpq $0x78, %rdi
je 0x580e
movzwl (%rdi,%r8), %r10d
movl (%rdi,%r9), %r11d
addl $0x5, %r11d
imull %r10d, %r11d
addl %r11d, %ecx
addq $0x4, %rdi
jmp 0x57e6
movl 0x82c8(%rip), %edi      # 0xdad4
jmp 0x5831
movl 0x82c0(%rip), %edi      # 0xdad4
movl %eax, %r8d
shrl %r8d
cmpl %r8d, %edi
jae 0x5831
subl %esi, %edx
shrl $0x3, %ecx
shrl %edx
cmpl %edx, %ecx
jae 0x5831
movl $0x1, %eax
jmp 0x5847
cmpl $0x7fff, %eax           # imm = 0x7FFF
sete %al
cmpl $0x8000, %edi           # imm = 0x8000
sete %cl
orb %al, %cl
movzbl %cl, %eax
popq %rbp
retq