// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/rANS_static16_int.h
// Function: normalise_freq
static inline int normalise_freq(uint32_t *F, int size, uint32_t tot) {
    int m, M, j, loop = 0;
    uint64_t tr;
    if (!size)
        return 0;

 again:
    tr = ((uint64_t)tot<<31)/size + (1<<30)/size;

    for (size = m = M = j = 0; j < 256; j++) {
        if (!F[j])
            continue;

        if (m < F[j])
            m = F[j], M = j;

        if ((F[j] = (F[j]*tr)>>31) == 0)
            F[j] = 1;
        size += F[j];
//      if (F[j] == tot)
//          F[j]--;
    }

    int adjust = tot - size;
    if (adjust > 0) {
        F[M] += adjust;
    } else if (adjust < 0) {
        if (F[M] > -adjust && (loop == 1 || F[M]/2 >= -adjust)) {
            F[M] += adjust;
        } else {
            if (loop < 1) {
                loop++;
                goto again;
            }
            adjust += F[M]-1;
            F[M] = 1;
            for (j = 0; adjust && j < 256; j++) {
                if (F[j] < 2) continue;

                int d = F[j] > -adjust;
                int m = d ? adjust : 1-F[j];
                F[j]   += m;
                adjust -= m;
            }
        }
    }

    //printf("F[%d]=%d\n", M, F[M]);
    return F[M]>0 ? 0 : -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x8ee67
movl $0x0, -0x4(%rbp)
jmp 0x8f0b8
jmp 0x8ee69
movl -0x18(%rbp), %eax
shlq $0x1f, %rax
movslq -0x14(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, -0x48(%rbp)
movl $0x40000000, %eax       # imm = 0x40000000
cltd
idivl -0x14(%rbp)
movl %eax, %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jge 0x8ef45
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x8eecf
jmp 0x8ef37
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
movslq -0x24(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x8eef3
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
imulq -0x30(%rbp), %rax
shrq $0x1f, %rax
movq -0x10(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movl %eax, (%rcx,%rdx,4)
cmpl $0x0, %eax
jne 0x8ef26
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8eeb2
movl -0x18(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x8ef6a
movl -0x34(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x8f09d
cmpl $0x0, -0x34(%rbp)
jge 0x8f09b
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
xorl %ecx, %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x8efba
cmpl $0x1, -0x28(%rbp)
je 0x8efa4
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl %eax
xorl %ecx, %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jb 0x8efba
movl -0x34(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x8f099
cmpl $0x1, -0x28(%rbp)
jge 0x8efce
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x8ee69
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl $0x0, -0x24(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x34(%rbp)
movb %al, -0x49(%rbp)
je 0x8f010
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
setl %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x8f019
jmp 0x8f097
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpl $0x2, (%rax,%rcx,4)
jae 0x8f029
jmp 0x8f089
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
xorl %ecx, %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x8f054
movl -0x34(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x8f067
movq -0x10(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movl $0x1, %eax
subl (%rcx,%rdx,4), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %edx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x8eff8
jmp 0x8f099
jmp 0x8f09b
jmp 0x8f09d
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpl $0x0, %edx
cmoval %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)