// File: /workspace/github_c_makefile_star2_O0/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
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
movb %al, %dl
movq 0x10097b2(%rip), %rax   # 0x1013b78
movl 0x9774(%rip), %ecx      # 0x13b40
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x9769(%rip)      # 0x13b40
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
cmpl $0x0, -0x8(%rbp)
jne 0xa405
movslq -0xc(%rbp), %rcx
leaq 0x6853(%rip), %rax      # 0x10c40
movw (%rax,%rcx,4), %dx
addw $0x1, %dx
leaq 0x6844(%rip), %rax      # 0x10c40
movw %dx, (%rax,%rcx,4)
jmp 0xa4d7
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x8327(%rip), %rax      # 0x12740
movzbl (%rax,%rcx), %eax
addl $0x100, %eax            # imm = 0x100
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x6811(%rip), %rax      # 0x10c40
movw (%rax,%rcx,4), %dx
addw $0x1, %dx
leaq 0x6802(%rip), %rax      # 0x10c40
movw %dx, (%rax,%rcx,4)
cmpl $0x100, -0x8(%rbp)      # imm = 0x100
jge 0xa45e
movslq -0x8(%rbp), %rcx
leaq 0x83ea(%rip), %rax      # 0x12840
movb (%rax,%rcx), %al
movb %al, -0x19(%rbp)
jmp 0xa479
movl -0x8(%rbp), %eax
sarl $0x7, %eax
addl $0x100, %eax            # imm = 0x100
movslq %eax, %rcx
leaq 0x83cd(%rip), %rax      # 0x12840
movb (%rax,%rcx), %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
movzbl %al, %eax
movl %eax, %ecx
leaq 0x70b8(%rip), %rax      # 0x11540
movw (%rax,%rcx,4), %dx
addw $0x1, %dx
leaq 0x70a9(%rip), %rax      # 0x11540
movw %dx, (%rax,%rcx,4)
movl -0x8(%rbp), %eax
movw %ax, %dx
movl 0x969d(%rip), %eax      # 0x13b44
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x9692(%rip)      # 0x13b44
movl %eax, %eax
movl %eax, %ecx
leaq 0x10396e3(%rip), %rax   # 0x1043ba0
movw %dx, (%rax,%rcx,2)
movzbl 0x9685(%rip), %ecx      # 0x13b4d
movzbl 0x967d(%rip), %eax      # 0x13b4c
orl %ecx, %eax
movb %al, 0x9675(%rip)       # 0x13b4c
movzbl 0x966f(%rip), %eax      # 0x13b4d
shll %eax
movb %al, 0x9667(%rip)       # 0x13b4d
movl 0x9654(%rip), %eax      # 0x13b40
andl $0x7, %eax
cmpl $0x0, %eax
jne 0xa527
movb 0x9652(%rip), %dl       # 0x13b4c
movl 0x9648(%rip), %eax      # 0x13b48
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x963d(%rip)      # 0x13b48
movl %eax, %eax
movl %eax, %ecx
leaq 0x862a(%rip), %rax      # 0x12b40
movb %dl, (%rax,%rcx)
movb $0x0, 0x962c(%rip)      # 0x13b4c
movb $0x1, 0x9626(%rip)      # 0x13b4d
cmpl $0x2, 0x66b2(%rip)      # 0x10be0
jle 0xa5d6
movl 0x9606(%rip), %eax      # 0x13b40
andl $0xfff, %eax            # imm = 0xFFF
cmpl $0x0, %eax
jne 0xa5d6
movl 0x95f2(%rip), %eax      # 0x13b40
shll $0x3, %eax
movl %eax, -0x10(%rbp)
movl 0x66b2(%rip), %eax      # 0x10c0c
subl 0x66a0(%rip), %eax      # 0x10c00
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x1e, -0x18(%rbp)
jge 0xa5a4
movslq -0x18(%rbp), %rcx
leaq 0x6fc5(%rip), %rax      # 0x11540
movzwl (%rax,%rcx,4), %eax
movslq -0x18(%rbp), %rdx
leaq 0x5f96(%rip), %rcx      # 0x10520
movl (%rcx,%rdx,4), %ecx
addl $0x5, %ecx
imull %ecx, %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xa56a
movl -0x10(%rbp), %eax
shrl $0x3, %eax
movl %eax, -0x10(%rbp)
movl 0x9591(%rip), %eax      # 0x13b44
movl 0x9587(%rip), %ecx      # 0x13b40
shrl %ecx
cmpl %ecx, %eax
jae 0xa5d4
movl -0x10(%rbp), %eax
movl -0x14(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0xa5d4
movl $0x1, -0x4(%rbp)
jmp 0xa602
jmp 0xa5d6
movb $0x1, %al
cmpl $0x7fff, 0x955e(%rip)   # imm = 0x7FFF
movb %al, -0x1a(%rbp)
je 0xa5f7
cmpl $0x8000, 0x9553(%rip)   # imm = 0x8000
sete %al
movb %al, -0x1a(%rbp)
movb -0x1a(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)