// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/rANS_static.c
// Function: rans_compress_O0
static
unsigned char *rans_compress_O0(unsigned char *in, unsigned int in_size,
                                unsigned int *out_size) {
    unsigned char *out_buf = malloc(1.05*in_size + 257*257*3 + 9);
    unsigned char *cp, *out_end;
    RansEncSymbol syms[256];
    RansState rans0;
    RansState rans2;
    RansState rans1;
    RansState rans3;
    uint8_t* ptr;
    int F[256+MAGIC] = {0}, i, j, tab_size, rle, x, fsum = 0;
    int m = 0, M = 0;
    uint64_t tr;

    if (!out_buf)
        return NULL;

    ptr = out_end = out_buf + (uint32_t)(1.05*in_size) + 257*257*3 + 9;

    // Compute statistics
    if (hist8(in, in_size, (uint32_t *)F) < 0) {
        free(out_buf);
        return NULL;
    }
    tr = in_size ? ((uint64_t)TOTFREQ<<31)/in_size + (1<<30)/in_size : 0;

 normalise_harder:
    // Normalise so T[i] == TOTFREQ
    for (fsum = 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;
        fsum += F[j];
    }

    fsum++;
    if (fsum < TOTFREQ) {
        F[M] += TOTFREQ-fsum;
    } else if (fsum-TOTFREQ > F[M]/2) {
        // Corner case to avoid excessive frequency reduction
        tr = 2104533975; goto normalise_harder; // equiv to *0.98.
    } else {
        F[M] -= fsum-TOTFREQ;
    }

    //printf("F[%d]=%d\n", M, F[M]);
    assert(F[M]>0);

    // Encode statistics.
    cp = out_buf+9;

    for (x = rle = j = 0; j < 256; j++) {
        if (F[j]) {
            // j
            if (rle) {
                rle--;
            } else {
                *cp++ = j;
                if (!rle && j && F[j-1])  {
                    for(rle=j+1; rle<256 && F[rle]; rle++)
                        ;
                    rle -= j+1;
                    *cp++ = rle;
                }
                //fprintf(stderr, "%d: %d %d\n", j, rle, N[j]);
            }
            
            // F[j]
            if (F[j]<128) {
                *cp++ = F[j];
            } else {
                *cp++ = 128 | (F[j]>>8);
                *cp++ = F[j]&0xff;
            }
            RansEncSymbolInit(&syms[j], x, F[j], TF_SHIFT);
            x += F[j];
        }
    }
    *cp++ = 0;

    //write(2, out_buf+4, cp-(out_buf+4));
    tab_size = cp-out_buf;

    RansEncInit(&rans0);
    RansEncInit(&rans1);
    RansEncInit(&rans2);
    RansEncInit(&rans3);

    switch (i=(in_size&3)) {
    case 3: RansEncPutSymbol(&rans2, &ptr, &syms[in[in_size-(i-2)]]);
        // fall-through
    case 2: RansEncPutSymbol(&rans1, &ptr, &syms[in[in_size-(i-1)]]);
        // fall-through
    case 1: RansEncPutSymbol(&rans0, &ptr, &syms[in[in_size-(i-0)]]);
        // fall-through
    case 0:
        break;
    }
    for (i=(in_size &~3); likely(i>0); i-=4) {
        RansEncSymbol *s3 = &syms[in[i-1]];
        RansEncSymbol *s2 = &syms[in[i-2]];
        RansEncSymbol *s1 = &syms[in[i-3]];
        RansEncSymbol *s0 = &syms[in[i-4]];

        RansEncPutSymbol(&rans3, &ptr, s3);
        RansEncPutSymbol(&rans2, &ptr, s2);
        RansEncPutSymbol(&rans1, &ptr, s1);
        RansEncPutSymbol(&rans0, &ptr, s0);
    }

    RansEncFlush(&rans3, &ptr);
    RansEncFlush(&rans2, &ptr);
    RansEncFlush(&rans1, &ptr);
    RansEncFlush(&rans0, &ptr);

    // Finalise block size and return it
    *out_size = (out_end - ptr) + tab_size;

    cp = out_buf;

    *cp++ = 0; // order
    *cp++ = ((*out_size-9)>> 0) & 0xff;
    *cp++ = ((*out_size-9)>> 8) & 0xff;
    *cp++ = ((*out_size-9)>>16) & 0xff;
    *cp++ = ((*out_size-9)>>24) & 0xff;

    *cp++ = (in_size>> 0) & 0xff;
    *cp++ = (in_size>> 8) & 0xff;
    *cp++ = (in_size>>16) & 0xff;
    *cp++ = (in_size>>24) & 0xff;

    memmove(out_buf + tab_size, ptr, out_end-ptr);

    return out_buf;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x14f0, %rsp           # imm = 0x14F0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl -0x14(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x30baa(%rip), %xmm1    # 0xf5580
mulsd %xmm1, %xmm0
movsd 0x31806(%rip), %xmm1    # 0xf61e8
addsd %xmm1, %xmm0
movsd 0x31e92(%rip), %xmm1    # 0xf6880
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movq %rdi, %rcx
sarq $0x3f, %rcx
movsd 0x2aed7(%rip), %xmm1    # 0xef8e0
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
andq %rcx, %rax
orq %rax, %rdi
callq 0x4650
movq %rax, -0x28(%rbp)
leaq -0x1480(%rbp), %rdi
xorl %esi, %esi
movl $0x420, %edx            # imm = 0x420
callq 0x4250
movl $0x0, -0x1498(%rbp)
movl $0x0, -0x149c(%rbp)
movl $0x0, -0x14a0(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xc4a66
movq $0x0, -0x8(%rbp)
jmp 0xc535a
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
cvtsi2sd %rcx, %xmm0
movsd 0x30b06(%rip), %xmm1    # 0xf5580
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
movl %ecx, %ecx
addq %rcx, %rax
addq $0x30603, %rax          # imm = 0x30603
addq $0x9, %rax
movq %rax, -0x38(%rbp)
movq %rax, -0x1058(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x1480(%rbp), %rdx
callq 0xc72d0
cmpl $0x0, %eax
jge 0xc4acb
movq -0x28(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0xc535a
cmpl $0x0, -0x14(%rbp)
je 0xc4b0d
movl -0x14(%rbp), %eax
movl %eax, %ecx
movabsq $0x80000000000, %rax    # imm = 0x80000000000
xorl %edx, %edx
divq %rcx
movq %rax, -0x14d8(%rbp)
movl $0x40000000, %eax       # imm = 0x40000000
xorl %edx, %edx
divl -0x14(%rbp)
movl %eax, %ecx
movq -0x14d8(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x14d0(%rbp)
jmp 0xc4b18
xorl %eax, %eax
movq %rax, -0x14d0(%rbp)
jmp 0xc4b18
movq -0x14d0(%rbp), %rax
movq %rax, -0x14a8(%rbp)
movl $0x0, -0x1488(%rbp)
movl $0x0, -0x14a0(%rbp)
movl $0x0, -0x149c(%rbp)
movl $0x0, -0x1498(%rbp)
cmpl $0x100, -0x1488(%rbp)   # imm = 0x100
jge 0xc4c18
movslq -0x1488(%rbp), %rax
cmpl $0x0, -0x1480(%rbp,%rax,4)
jne 0xc4b74
jmp 0xc4c04
movl -0x149c(%rbp), %eax
movslq -0x1488(%rbp), %rcx
cmpl -0x1480(%rbp,%rcx,4), %eax
jge 0xc4baa
movslq -0x1488(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %eax
movl %eax, -0x149c(%rbp)
movl -0x1488(%rbp), %eax
movl %eax, -0x14a0(%rbp)
movslq -0x1488(%rbp), %rax
movslq -0x1480(%rbp,%rax,4), %rax
imulq -0x14a8(%rbp), %rax
shrq $0x1f, %rax
movslq -0x1488(%rbp), %rcx
movl %eax, -0x1480(%rbp,%rcx,4)
cmpl $0x0, %eax
jne 0xc4bea
movslq -0x1488(%rbp), %rax
movl $0x1, -0x1480(%rbp,%rax,4)
movslq -0x1488(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %eax
addl -0x1498(%rbp), %eax
movl %eax, -0x1498(%rbp)
movl -0x1488(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1488(%rbp)
jmp 0xc4b4e
movl -0x1498(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1498(%rbp)
cmpl $0x1000, -0x1498(%rbp)  # imm = 0x1000
jge 0xc4c55
movl $0x1000, %ecx           # imm = 0x1000
subl -0x1498(%rbp), %ecx
movslq -0x14a0(%rbp), %rax
addl -0x1480(%rbp,%rax,4), %ecx
movl %ecx, -0x1480(%rbp,%rax,4)
jmp 0xc4cbd
movl -0x1498(%rbp), %eax
subl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x14dc(%rbp)
movslq -0x14a0(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x14dc(%rbp), %eax
cmpl %ecx, %eax
jle 0xc4c98
movq $0x7d70a3d7, -0x14a8(%rbp) # imm = 0x7D70A3D7
jmp 0xc4b26
movl -0x1498(%rbp), %edx
subl $0x1000, %edx           # imm = 0x1000
movslq -0x14a0(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %ecx
subl %edx, %ecx
movl %ecx, -0x1480(%rbp,%rax,4)
jmp 0xc4cbd
movslq -0x14a0(%rbp), %rax
cmpl $0x0, -0x1480(%rbp,%rax,4)
jle 0xc4cd0
jmp 0xc4cef
leaq 0x31db4(%rip), %rdi     # 0xf6a8b
leaq 0x31bcf(%rip), %rsi     # 0xf68ad
movl $0x7e, %edx
leaq 0x31da8(%rip), %rcx     # 0xf6a92
callq 0x42e0
movq -0x28(%rbp), %rax
addq $0x9, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x1488(%rbp)
movl $0x0, -0x1490(%rbp)
movl $0x0, -0x1494(%rbp)
cmpl $0x100, -0x1488(%rbp)   # imm = 0x100
jge 0xc4f1c
movslq -0x1488(%rbp), %rax
cmpl $0x0, -0x1480(%rbp,%rax,4)
je 0xc4f06
cmpl $0x0, -0x1490(%rbp)
je 0xc4d5b
movl -0x1490(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1490(%rbp)
jmp 0xc4e33
movl -0x1488(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
cmpl $0x0, -0x1490(%rbp)
jne 0xc4e31
cmpl $0x0, -0x1488(%rbp)
je 0xc4e31
movl -0x1488(%rbp), %eax
subl $0x1, %eax
cltq
cmpl $0x0, -0x1480(%rbp,%rax,4)
je 0xc4e31
movl -0x1488(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1490(%rbp)
xorl %eax, %eax
cmpl $0x100, -0x1490(%rbp)   # imm = 0x100
movb %al, -0x14dd(%rbp)
jge 0xc4de2
movslq -0x1490(%rbp), %rax
cmpl $0x0, -0x1480(%rbp,%rax,4)
setne %al
movb %al, -0x14dd(%rbp)
movb -0x14dd(%rbp), %al
testb $0x1, %al
jne 0xc4dee
jmp 0xc4e01
jmp 0xc4df0
movl -0x1490(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1490(%rbp)
jmp 0xc4db6
movl -0x1488(%rbp), %ecx
addl $0x1, %ecx
movl -0x1490(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1490(%rbp)
movl -0x1490(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
jmp 0xc4e33
movslq -0x1488(%rbp), %rax
cmpl $0x80, -0x1480(%rbp,%rax,4)
jge 0xc4e6a
movslq -0x1488(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
jmp 0xc4eb9
movslq -0x1488(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %eax
sarl $0x8, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movslq -0x1488(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movslq -0x1488(%rbp), %rax
leaq -0x1040(%rbp), %rdi
shlq $0x4, %rax
addq %rax, %rdi
movl -0x1494(%rbp), %esi
movslq -0x1488(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %edx
movl $0xc, %ecx
callq 0xc6b70
movslq -0x1488(%rbp), %rax
movl -0x1480(%rbp,%rax,4), %eax
addl -0x1494(%rbp), %eax
movl %eax, -0x1494(%rbp)
jmp 0xc4f08
movl -0x1488(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1488(%rbp)
jmp 0xc4d19
movq -0x30(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x30(%rbp)
movb $0x0, (%rax)
movl -0x30(%rbp), %eax
movl -0x28(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x148c(%rbp)
leaq -0x1044(%rbp), %rdi
callq 0xc6d10
leaq -0x104c(%rbp), %rdi
callq 0xc6d10
leaq -0x1048(%rbp), %rdi
callq 0xc6d10
leaq -0x1050(%rbp), %rdi
callq 0xc6d10
movl -0x14(%rbp), %eax
andl $0x3, %eax
movl %eax, -0x1484(%rbp)
movl %eax, %ecx
movq %rcx, -0x14e8(%rbp)
subl $0x3, %eax
ja 0xc504d
movq -0x14e8(%rbp), %rax
leaq 0x318f1(%rip), %rcx     # 0xf6888
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl -0x1484(%rbp), %edx
subl $0x2, %edx
subl %edx, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
leaq -0x1040(%rbp), %rdx
shlq $0x4, %rax
addq %rax, %rdx
leaq -0x1048(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc6d30
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl -0x1484(%rbp), %edx
subl $0x1, %edx
subl %edx, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
leaq -0x1040(%rbp), %rdx
shlq $0x4, %rax
addq %rax, %rdx
leaq -0x104c(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc6d30
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl -0x1484(%rbp), %edx
subl $0x0, %edx
subl %edx, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
leaq -0x1040(%rbp), %rdx
shlq $0x4, %rax
addq %rax, %rdx
leaq -0x1044(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc6d30
jmp 0xc504d
movl -0x14(%rbp), %eax
andl $-0x4, %eax
movl %eax, -0x1484(%rbp)
cmpl $0x0, -0x1484(%rbp)
setg %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0xc519c
movq -0x10(%rbp), %rax
movl -0x1484(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq -0x1040(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x14b0(%rbp)
movq -0x10(%rbp), %rax
movl -0x1484(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq -0x1040(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x14b8(%rbp)
movq -0x10(%rbp), %rax
movl -0x1484(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq -0x1040(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x14c0(%rbp)
movq -0x10(%rbp), %rax
movl -0x1484(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq -0x1040(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x14c8(%rbp)
movq -0x14b0(%rbp), %rdx
leaq -0x1050(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc6d30
movq -0x14b8(%rbp), %rdx
leaq -0x1048(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc6d30
movq -0x14c0(%rbp), %rdx
leaq -0x104c(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc6d30
movq -0x14c8(%rbp), %rdx
leaq -0x1044(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc6d30
movl -0x1484(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x1484(%rbp)
jmp 0xc5059
leaq -0x1050(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc7250
leaq -0x1048(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc7250
leaq -0x104c(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc7250
leaq -0x1044(%rbp), %rdi
leaq -0x1058(%rbp), %rsi
callq 0xc7250
movq -0x38(%rbp), %rax
movq -0x1058(%rbp), %rcx
subq %rcx, %rax
movslq -0x148c(%rbp), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
subl $0x9, %eax
shrl $0x0, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
subl $0x9, %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
subl $0x9, %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
subl $0x9, %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movl -0x14(%rbp), %eax
shrl $0x0, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movl -0x14(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movl -0x14(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movl -0x14(%rbp), %eax
shrl $0x18, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x28(%rbp), %rdi
movslq -0x148c(%rbp), %rax
addq %rax, %rdi
movq -0x1058(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x1058(%rbp), %rax
subq %rax, %rdx
callq 0x4810
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x14f0, %rsp           # imm = 0x14F0
popq %rbp
retq
nopw (%rax,%rax)