// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1cb8, %rsp           # imm = 0x1CB8
movq %rdx, %r13
movl %esi, %r15d
movq %rdi, 0x10(%rsp)
cvtsi2sd %esi, %xmm1
mulsd 0x1cfb3(%rip), %xmm1    # 0x7cba8
movsd 0x1dc0b(%rip), %xmm0    # 0x7d808
movsd %xmm1, 0x8(%rsp)
addsd %xmm1, %xmm0
addsd 0x222f1(%rip), %xmm0    # 0x81f00
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x17a9d(%rip), %xmm0    # 0x776c0
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
callq 0x4680
movq %rax, %r12
leaq 0x50(%rsp), %rdi
movl $0x420, %edx            # imm = 0x420
xorl %esi, %esi
callq 0x4260
testq %r12, %r12
je 0x6023a
cvttsd2si 0x8(%rsp), %rax
movl %eax, %eax
leaq (%r12,%rax), %rbp
addq $0x3060c, %rbp          # imm = 0x3060C
movq %rbp, 0x20(%rsp)
movl %r15d, %ebx
cmpl $0x7a121, %r15d         # imm = 0x7A121
movq %r15, 0x8(%rsp)
jb 0x5fd57
pushq $0x4
popq %rsi
movl $0x3006f, %edi          # imm = 0x3006F
callq 0x6426c
testq %rax, %rax
je 0x60232
movq 0x8(%rsp), %rdx
andl $-0x10, %edx
xorl %ecx, %ecx
movq 0x10(%rsp), %r10
cmpq %rdx, %rcx
jae 0x5fd1d
movzwl (%r10,%rcx), %esi
movzwl 0x2(%r10,%rcx), %edi
movzwl 0x4(%r10,%rcx), %r8d
movzwl 0x6(%r10,%rcx), %r9d
incl (%rax,%rsi,4)
incl 0x40094(%rax,%rdi,4)
incl 0x80128(%rax,%r8,4)
incl (%rax,%r9,4)
movzwl 0x8(%r10,%rcx), %esi
movzwl 0xa(%r10,%rcx), %edi
movzwl 0xc(%r10,%rcx), %r8d
movzwl 0xe(%r10,%rcx), %r9d
incl 0x40094(%rax,%rsi,4)
incl (%rax,%rdi,4)
incl 0x40094(%rax,%r8,4)
incl 0x80128(%rax,%r9,4)
addq $0x10, %rcx
jmp 0x5fca3
movq 0x10(%rsp), %rdx
movzbl (%rdx,%rcx), %edx
incq %rcx
incl 0x50(%rsp,%rdx,4)
cmpq %rbx, %rcx
jb 0x5fd0d
xorl %ecx, %ecx
cmpq $0x10000, %rcx          # imm = 0x10000
je 0x5fe4d
movl 0x40094(%rax,%rcx,4), %edx
addl (%rax,%rcx,4), %edx
addl 0x80128(%rax,%rcx,4), %edx
movzbl %cl, %esi
addl %edx, 0x50(%rsp,%rsi,4)
movl %ecx, %esi
shrl $0x8, %esi
addl %edx, 0x50(%rsp,%rsi,4)
incq %rcx
jmp 0x5fd24
leaq 0xcb0(%rsp), %rdi
xorl %r14d, %r14d
movl $0x420, %edx            # imm = 0x420
xorl %esi, %esi
callq 0x4260
leaq 0x890(%rsp), %rdi
movl $0x420, %edx            # imm = 0x420
xorl %esi, %esi
callq 0x4260
leaq 0x470(%rsp), %rdi
movl $0x420, %edx            # imm = 0x420
xorl %esi, %esi
callq 0x4260
movl %r15d, %eax
andl $0x7fff8, %eax          # imm = 0x7FFF8
movq 0x10(%rsp), %rdx
cmpq %rax, %r14
jae 0x5fe20
movzbl (%rdx,%r14), %ecx
incl 0x50(%rsp,%rcx,4)
movzbl 0x1(%rdx,%r14), %ecx
incl 0xcb0(%rsp,%rcx,4)
movzbl 0x2(%rdx,%r14), %ecx
incl 0x890(%rsp,%rcx,4)
movzbl 0x3(%rdx,%r14), %ecx
incl 0x470(%rsp,%rcx,4)
movzbl 0x4(%rdx,%r14), %ecx
incl 0x50(%rsp,%rcx,4)
movzbl 0x5(%rdx,%r14), %ecx
incl 0xcb0(%rsp,%rcx,4)
movzbl 0x6(%rdx,%r14), %ecx
incl 0x890(%rsp,%rcx,4)
movzbl 0x7(%rdx,%r14), %ecx
incl 0x470(%rsp,%rcx,4)
addq $0x8, %r14
jmp 0x5fda3
movq 0x10(%rsp), %rax
movzbl (%rax,%r14), %eax
incq %r14
incl 0x50(%rsp,%rax,4)
cmpq %rbx, %r14
jb 0x5fe0f
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x5fe5a
movl 0x890(%rsp,%rax,4), %ecx
addl 0xcb0(%rsp,%rax,4), %ecx
addl 0x470(%rsp,%rax,4), %ecx
addl %ecx, 0x50(%rsp,%rax,4)
incq %rax
jmp 0x5fe27
movq %rax, %rdi
callq 0x64291
movq 0x8(%rsp), %r15
testl %r15d, %r15d
je 0x5fe80
movabsq $0x80000000000, %rax    # imm = 0x80000000000
xorl %edx, %edx
divq %rbx
movq %rax, %rcx
movl $0x40000000, %eax       # imm = 0x40000000
xorl %edx, %edx
divl %r15d
addq %rcx, %rax
jmp 0x5fe82
xorl %eax, %eax
pushq $0x2
popq %rsi
pushq $0x1
popq %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %edx, %edx
cmpq $0x100, %rcx            # imm = 0x100
je 0x5fecf
movslq 0x50(%rsp,%rcx,4), %r10
testq %r10, %r10
je 0x5feca
cmpl %r10d, %r9d
cmovlel %r10d, %r9d
cmovll %ecx, %edx
imulq %rax, %r10
shrq $0x1f, %r10
cmpl $0x2, %r10d
cmovbl %edi, %r10d
movl %r10d, 0x50(%rsp,%rcx,4)
addl %r8d, %r10d
movl %r10d, %r8d
incq %rcx
jmp 0x5fe92
movslq %edx, %r9
cmpl $0xffe, %r8d            # imm = 0xFFE
jle 0x5fefd
addl $0xfffff001, %r8d       # imm = 0xFFFFF001
movl 0x50(%rsp,%r9,4), %ecx
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %edx
movl $0x7d70a3d7, %eax       # imm = 0x7D70A3D7
cmpl %edx, %r8d
jg 0x5fe88
subl %r8d, %ecx
jmp 0x5ff0b
movl 0x50(%rsp,%r9,4), %ecx
subl %r8d, %ecx
addl $0xfff, %ecx            # imm = 0xFFF
movl %ecx, 0x50(%rsp,%r9,4)
movq %rbp, 0x40(%rsp)
movq %r13, 0x48(%rsp)
testl %ecx, %ecx
movq 0x8(%rsp), %rdx
jle 0x60251
movq %r12, 0x38(%rsp)
leaq 0x9(%r12), %rcx
xorl %r14d, %r14d
pushq $0x1
popq %r13
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq $0x100, %r14            # imm = 0x100
je 0x60005
cmpl $0x0, 0x50(%rsp,%r14,4)
je 0x5ffb4
testl %r12d, %r12d
je 0x5ffbc
decl %r12d
movq %rcx, %r15
movl 0x50(%rsp,%r14,4), %eax
cmpl $0x80, %eax
jge 0x5ff71
pushq $0x1
popq %rdx
movq %r15, %rcx
jmp 0x5ff85
shrl $0x8, %eax
orb $-0x80, %al
leaq 0x1(%r15), %rcx
movb %al, (%r15)
movl 0x50(%rsp,%r14,4), %eax
pushq $0x2
popq %rdx
addq %rdx, %r15
movb %al, (%rcx)
movq %r14, %rax
shlq $0x4, %rax
leaq (%rsp,%rax), %rdi
addq $0xcb0, %rdi            # imm = 0xCB0
movl 0x50(%rsp,%r14,4), %ebx
movl %ebp, %esi
movl %ebx, %edx
callq 0x60ec8
addl %ebx, %ebp
movq %r15, %rcx
movq 0x8(%rsp), %rdx
incq %r14
incq %r13
jmp 0x5ff3d
leaq 0x1(%rcx), %r15
movb %r14b, (%rcx)
xorl %r12d, %r12d
testq %r14, %r14
je 0x5ff5d
cmpl $0x0, 0x4c(%rsp,%r14,4)
je 0x5ff5d
movq %r13, %rax
cmpq $0x100, %rax            # imm = 0x100
je 0x5ffea
cmpl $0x0, 0x50(%rsp,%rax,4)
je 0x5ffef
incq %rax
jmp 0x5ffd6
movl $0x100, %eax            # imm = 0x100
movl %r14d, %r12d
notl %r12d
addl %eax, %r12d
movb %r12b, 0x1(%rcx)
addq $0x2, %rcx
jmp 0x5ff5a
movb $0x0, (%rcx)
subq 0x38(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movl $0x800000, %eax         # imm = 0x800000
movl %eax, 0x890(%rsp)
movl %eax, 0x1c(%rsp)
movl %eax, 0x470(%rsp)
movl %eax, 0x2c(%rsp)
movl %edx, %ebx
andl $0x3, %ebx
leaq 0x21edf(%rip), %rax     # 0x81f18
movslq (%rax,%rbx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl %edx, %ebx
andl $-0x4, %ebx
jmp 0x600dc
leal -0x1(%rdx), %eax
movq 0x10(%rsp), %rcx
movzbl (%rcx,%rax), %eax
shll $0x4, %eax
leaq (%rsp,%rax), %rdx
addq $0xcb0, %rdx            # imm = 0xCB0
leaq 0x470(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x60f85
movq 0x8(%rsp), %rdx
movl %edx, %eax
subl %ebx, %eax
incl %eax
movq 0x10(%rsp), %rcx
movzbl (%rcx,%rax), %eax
shll $0x4, %eax
leaq (%rsp,%rax), %rdx
addq $0xcb0, %rdx            # imm = 0xCB0
leaq 0x1c(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x60f85
movq 0x8(%rsp), %rdx
movl %edx, %ebx
andl $-0x4, %ebx
movq 0x10(%rsp), %rax
movzbl (%rax,%rbx), %eax
shll $0x4, %eax
leaq (%rsp,%rax), %rdx
addq $0xcb0, %rdx            # imm = 0xCB0
leaq 0x890(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x60f85
incq 0x30(%rsp)
movslq %ebx, %r15
leaq 0x20(%rsp), %rbp
leaq 0x890(%rsp), %rbx
testq %r15, %r15
jle 0x60196
movq 0x10(%rsp), %rcx
movzbl -0x1(%rcx,%r15), %eax
shll $0x4, %eax
leaq (%rsp,%rax), %rdx
addq $0xcb0, %rdx            # imm = 0xCB0
movzbl -0x2(%rcx,%r15), %eax
shll $0x4, %eax
leaq (%rsp,%rax), %r12
addq $0xcb0, %r12            # imm = 0xCB0
movzbl -0x3(%rcx,%r15), %eax
shll $0x4, %eax
leaq (%rsp,%rax), %r13
addq $0xcb0, %r13            # imm = 0xCB0
movzbl -0x4(%rcx,%r15), %eax
addq $-0x4, %r15
shll $0x4, %eax
leaq (%rsp,%rax), %r14
addq $0xcb0, %r14            # imm = 0xCB0
leaq 0x2c(%rsp), %rdi
movq %rbp, %rsi
callq 0x60f85
leaq 0x470(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x60f85
leaq 0x1c(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x60f85
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x60f85
jmp 0x600f1
movl 0x2c(%rsp), %eax
movq 0x20(%rsp), %rsi
movl %eax, -0x4(%rsi)
movl 0x470(%rsp), %eax
movl %eax, -0x8(%rsi)
movl 0x1c(%rsp), %eax
movl %eax, -0xc(%rsi)
movl 0x890(%rsp), %eax
movl %eax, -0x10(%rsi)
addq $-0x10, %rsi
movq 0x40(%rsp), %r8
subq %rsi, %r8
movq 0x30(%rsp), %rdx
movslq %edx, %rax
addq %r8, %rdx
movq 0x48(%rsp), %rcx
movl %edx, (%rcx)
movq 0x38(%rsp), %rbx
movb $0x0, (%rbx)
movl %edx, %ecx
addb $-0x9, %cl
movb %cl, 0x1(%rbx)
leal 0xfff7(%rdx), %ecx
movb %ch, 0x2(%rbx)
leal 0xfffff7(%rdx), %ecx
shrl $0x10, %ecx
movb %cl, 0x3(%rbx)
leal -0x9(%rdx), %ecx
shrl $0x18, %ecx
movb %cl, 0x4(%rbx)
movq 0x8(%rsp), %rdx
movb %dl, 0x5(%rbx)
movb %dh, 0x6(%rbx)
movl %edx, %ecx
shrl $0x10, %ecx
movb %cl, 0x7(%rbx)
shrl $0x18, %edx
movb %dl, 0x8(%rbx)
movq %rbx, %rdi
addq %rax, %rdi
movq %r8, %rdx
callq 0x4830
jmp 0x6023c
movq %r12, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x1cb8, %rsp           # imm = 0x1CB8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21ed3(%rip), %rdi     # 0x8212b
leaq 0x21cee(%rip), %rsi     # 0x81f4d
leaq 0x21ecc(%rip), %rcx     # 0x82132
pushq $0x7e
popq %rdx
callq 0x42f0