// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/htslib/cram/rANS_static.c
// Function: rans_compress_O0
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, rans1, rans2, rans3;
    uint8_t* ptr;
    int F[256] = {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 + (int)(1.05*in_size) + 257*257*3 + 9;

    // Compute statistics
    for (i = 0; i < in_size; i++) {
	F[in[i]]++;
    }
    tr = ((uint64_t)TOTFREQ<<31)/in_size + (1<<30)/in_size;

    // Normalise so T[i] == TOTFREQ
    for (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
	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(1, 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)]]);
    case 2: RansEncPutSymbol(&rans1, &ptr, &syms[in[in_size-(i-1)]]);
    case 1: RansEncPutSymbol(&rans0, &ptr, &syms[in[in_size-(i-0)]]);
    case 0:
	break;
    }
    for (i=(in_size &~3); 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 $0x1438, %rsp           # imm = 0x1438
movq %rdx, 0x28(%rsp)
movl %esi, %r14d
movq %rdi, %r13
movl %esi, %ebx
cvtsi2sd %rbx, %xmm1
mulsd 0x336fd(%rip), %xmm1    # 0x92cd0
movsd 0x39ec5(%rip), %xmm0    # 0x994a0
movsd %xmm1, 0x18(%rsp)
addsd %xmm1, %xmm0
addsd 0x39ebb(%rip), %xmm0    # 0x994a8
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x38b17(%rip), %xmm0    # 0x98118
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
callq 0x69d0
movq %rax, %r12
leaq 0x30(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x63b0
movq %r12, 0x10(%rsp)
testq %r12, %r12
je 0x5fc3f
cvttsd2si 0x18(%rsp), %eax
cltq
movq %r14, (%rsp)
testl %r14d, %r14d
je 0x5f658
xorl %ecx, %ecx
movzbl (%r13,%rcx), %edx
incl 0x30(%rsp,%rdx,4)
incq %rcx
cmpq %rcx, %rbx
jne 0x5f646
movq 0x10(%rsp), %rcx
addq %rcx, %rax
addq $0x3060c, %rax          # imm = 0x3060C
movq %rax, 0x8(%rsp)
xorl %esi, %esi
movabsq $0x80000000000, %rax    # imm = 0x80000000000
xorl %edx, %edx
divq %rbx
movq %rax, %rcx
movl $0x40000000, %eax       # imm = 0x40000000
xorl %edx, %edx
divl (%rsp)
addq %rcx, %rax
movl $0x1, %ecx
xorl %edx, %edx
xorl %r8d, %r8d
xorl %edi, %edi
movslq 0x30(%rsp,%rsi,4), %r9
testq %r9, %r9
je 0x5f6c7
cmpl %r9d, %r8d
cmovlel %r9d, %r8d
cmovll %esi, %edx
imulq %rax, %r9
shrq $0x1f, %r9
cmpl $0x2, %r9d
cmovbl %ecx, %r9d
movl %r9d, 0x30(%rsp,%rsi,4)
addl %edi, %r9d
movl %r9d, %edi
incq %rsi
cmpq $0x100, %rsi            # imm = 0x100
jne 0x5f698
movslq %edx, %rax
movl 0x30(%rsp,%rax,4), %ecx
subl %edi, %ecx
addl $0xfff, %ecx            # imm = 0xFFF
movl %ecx, 0x30(%rsp,%rax,4)
testl %ecx, %ecx
jle 0x5fcb3
movq 0x10(%rsp), %rax
leaq 0x9(%rax), %r14
xorl %edi, %edi
movl $0x1, %r10d
xorl %ebx, %ebx
xorl %r11d, %r11d
cmpl $0x0, 0x30(%rsp,%rdi,4)
je 0x5f805
testl %ebx, %ebx
je 0x5f81a
decl %ebx
movq %r14, %r12
movl 0x30(%rsp,%rdi,4), %eax
movl $0x1, %r9d
cmpl $0x80, %eax
jge 0x5f732
movq %r12, %rcx
jmp 0x5f74a
shrl $0x8, %eax
orb $-0x80, %al
leaq 0x1(%r12), %rcx
movb %al, (%r12)
movl 0x30(%rsp,%rdi,4), %eax
movl $0x2, %r9d
movb %al, (%rcx)
cmpl $0x1001, %r11d          # imm = 0x1001
jae 0x5fc94
movl 0x30(%rsp,%rdi,4), %r14d
movl $0x1000, %eax           # imm = 0x1000
subl %r11d, %eax
cmpl %r14d, %eax
jb 0x5fc75
movq %rdi, %rax
shlq $0x4, %rax
leaq (%rsp,%rax), %r8
addq $0x430, %r8             # imm = 0x430
movl %r14d, %eax
shll $0x13, %eax
movl %eax, (%r8)
movl $0x1000, %eax           # imm = 0x1000
subl %r14d, %eax
movw %ax, 0xc(%r8)
cmpl $0x2, %r14d
jae 0x5f7b5
movl $0xffffffff, 0x4(%r8)   # imm = 0xFFFFFFFF
movw $0x0, 0xe(%r8)
leal 0xfff(%r11), %eax
jmp 0x5f7ef
movl $0x1e, %esi
leal -0x1e(%rsi), %ecx
movl $0x1, %eax
shll %cl, %eax
incl %esi
cmpl %r14d, %eax
jb 0x5f7ba
movl $0x1, %eax
movl %esi, %ecx
shlq %cl, %rax
addq %r14, %rax
decq %rax
xorl %edx, %edx
divq %r14
movl %eax, 0x4(%r8)
addl $-0x20, %esi
movw %si, 0xe(%r8)
movl %r11d, %eax
movl %eax, 0x8(%r8)
addw $0x20, 0xe(%r8)
addq %r9, %r12
addl %r11d, %r14d
movl %r14d, %r11d
movq %r12, %r14
incq %rdi
incq %r10
cmpq $0x100, %rdi            # imm = 0x100
jne 0x5f704
jmp 0x5f870
leaq 0x1(%r14), %r12
movb %dil, (%r14)
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x5f71c
cmpl $0x0, 0x2c(%rsp,%rdi,4)
je 0x5f71c
leaq 0x1(%rdi), %rax
movl %eax, %ebx
cmpq $0xff, %rdi
je 0x5f861
movq %r10, %rbx
cmpl $0x0, 0x30(%rsp,%rbx,4)
je 0x5f861
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x5f849
movl $0x100, %ebx            # imm = 0x100
subl %eax, %ebx
movb %bl, 0x1(%r14)
addq $0x2, %r14
jmp 0x5f719
movb $0x0, (%r14)
movq (%rsp), %r12
movl %r12d, %edi
andl $0x3, %edi
movl $0x800000, %esi         # imm = 0x800000
leaq 0x39c2e(%rip), %rax     # 0x994b8
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
movl $0x800000, %r10d        # imm = 0x800000
movq 0x8(%rsp), %rdx
movl $0x800000, %r11d        # imm = 0x800000
movl $0x800000, %r8d         # imm = 0x800000
movl $0x800000, %r15d        # imm = 0x800000
movl $0x800000, %eax         # imm = 0x800000
movl $0x800000, %ebx         # imm = 0x800000
jmpq *%rcx
leal -0x1(%r12), %eax
movzbl (%r13,%rax), %eax
shll $0x4, %eax
movl 0x430(%rsp,%rax), %ecx
testl %ecx, %ecx
je 0x5fc56
leaq (%rsp,%rax), %r8
addq $0x430, %r8             # imm = 0x430
movl $0x800000, %eax         # imm = 0x800000
movq 0x8(%rsp), %rdx
cmpl $0x800000, %ecx         # imm = 0x800000
ja 0x5f906
movq 0x8(%rsp), %rdx
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
cmpl %ecx, %eax
jae 0x5f8f9
movl %eax, %ecx
movl 0x4(%r8), %r11d
imulq %rcx, %r11
movb 0xe(%r8), %cl
shrq %cl, %r11
addl 0x8(%r8), %eax
movzwl 0xc(%r8), %r10d
imull %r11d, %r10d
addl %eax, %r10d
movq (%rsp), %r12
movl %r12d, %eax
subl %edi, %eax
incl %eax
movzbl (%r13,%rax), %eax
shll $0x4, %eax
movl 0x430(%rsp,%rax), %ecx
testl %ecx, %ecx
je 0x5fc56
leaq (%rsp,%rax), %rdi
addq $0x430, %rdi            # imm = 0x430
movl $0x800000, %eax         # imm = 0x800000
cmpl $0x800000, %ecx         # imm = 0x800000
ja 0x5f96f
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
cmpl %ecx, %eax
jae 0x5f962
movl %eax, %ecx
movl 0x4(%rdi), %r8d
imulq %rcx, %r8
movb 0xe(%rdi), %cl
shrq %cl, %r8
addl 0x8(%rdi), %eax
movzwl 0xc(%rdi), %r11d
imull %r8d, %r11d
addl %eax, %r11d
movl %r10d, %r8d
movq (%rsp), %r12
movl %r12d, %eax
andl $-0x4, %eax
movzbl (%r13,%rax), %eax
shll $0x4, %eax
movl 0x430(%rsp,%rax), %ecx
testl %ecx, %ecx
je 0x5fc56
leaq (%rsp,%rax), %rdi
addq $0x430, %rdi            # imm = 0x430
movl $0x800000, %eax         # imm = 0x800000
cmpl $0x800000, %ecx         # imm = 0x800000
ja 0x5f9d8
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
cmpl %ecx, %eax
jae 0x5f9cb
movl %eax, %ecx
movl 0x4(%rdi), %r10d
imulq %rcx, %r10
movb 0xe(%rdi), %cl
shrq %cl, %r10
addl 0x8(%rdi), %eax
movzwl 0xc(%rdi), %r15d
imull %r10d, %r15d
addl %eax, %r15d
movl %r11d, %eax
movl %r8d, %ebx
movq (%rsp), %r12
movq %r14, 0x20(%rsp)
movl %r12d, %ecx
andl $-0x4, %ecx
jle 0x5fb88
movl %ecx, %edi
movl $0x800000, %esi         # imm = 0x800000
movq %r13, 0x18(%rsp)
movzbl -0x1(%r13,%rdi), %ecx
shll $0x4, %ecx
movl 0x430(%rsp,%rcx), %r10d
testl %r10d, %r10d
je 0x5fc56
movzbl -0x2(%r13,%rdi), %r8d
movzbl -0x3(%r13,%rdi), %r14d
movzbl -0x4(%r13,%rdi), %r12d
cmpl %r10d, %esi
jb 0x5fa5b
movb %sil, -0x1(%rdx)
decq %rdx
shrl $0x8, %esi
jmp 0x5fa4a
leaq (%rsp,%rcx), %r11
addq $0x430, %r11            # imm = 0x430
movl %esi, %ecx
movl 0x4(%r11), %r10d
imulq %rcx, %r10
movb 0xe(%r11), %cl
shrq %cl, %r10
shll $0x4, %r8d
addq %rsp, %r8
addq $0x430, %r8             # imm = 0x430
movl (%r8), %ecx
testl %ecx, %ecx
je 0x5fc56
addl 0x8(%r11), %esi
movzwl 0xc(%r11), %r11d
cmpl %ecx, %ebx
jb 0x5faa8
movb %bl, -0x1(%rdx)
decq %rdx
shrl $0x8, %ebx
jmp 0x5fa99
movl %ebx, %ecx
movl 0x4(%r8), %r13d
imulq %rcx, %r13
movb 0xe(%r8), %cl
shrq %cl, %r13
shll $0x4, %r14d
leaq (%rsp,%r14), %rbp
addq $0x430, %rbp            # imm = 0x430
movl (%rbp), %ecx
testl %ecx, %ecx
je 0x5fc56
addl 0x8(%r8), %ebx
movzwl 0xc(%r8), %r14d
cmpl %ecx, %eax
jb 0x5faeb
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
jmp 0x5fadc
movl %eax, %ecx
movl 0x4(%rbp), %r8d
imulq %rcx, %r8
movb 0xe(%rbp), %cl
shrq %cl, %r8
shll $0x4, %r12d
addq %rsp, %r12
addq $0x430, %r12            # imm = 0x430
movl (%r12), %ecx
testl %ecx, %ecx
je 0x5fc56
addl 0x8(%rbp), %eax
movzwl 0xc(%rbp), %ebp
movl %r15d, %r9d
cmpl %ecx, %r15d
jb 0x5fb34
movb %r9b, -0x1(%rdx)
decq %rdx
shrl $0x8, %r9d
cmpl %ecx, %r9d
jae 0x5fb24
movl %r9d, %ecx
movl 0x4(%r12), %r15d
imulq %rcx, %r15
movb 0xe(%r12), %cl
shrq %cl, %r15
imull %r11d, %r10d
leaq -0x4(%rdi), %rcx
addl %r10d, %esi
imull %r14d, %r13d
addl %r13d, %ebx
imull %ebp, %r8d
addl %r8d, %eax
addl 0x8(%r12), %r9d
movzwl 0xc(%r12), %r8d
imull %r15d, %r8d
addl %r8d, %r9d
movl %r9d, %r15d
cmpq $0x4, %rdi
movq %rcx, %rdi
movq 0x18(%rsp), %r13
jg 0x5fa1e
movl %esi, -0x4(%rdx)
movb %bl, -0x8(%rdx)
movb %bh, -0x7(%rdx)
movl %ebx, %ecx
shrl $0x10, %ecx
movb %cl, -0x6(%rdx)
shrl $0x18, %ebx
movb %bl, -0x5(%rdx)
movb %al, -0xc(%rdx)
movb %ah, -0xb(%rdx)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, -0xa(%rdx)
shrl $0x18, %eax
movb %al, -0x9(%rdx)
movq 0x10(%rsp), %rbp
movq 0x20(%rsp), %rcx
subq %rbp, %rcx
incq %rcx
leaq -0x10(%rdx), %rsi
movl %r15d, %ebx
movb %bl, -0x10(%rdx)
movb %bh, -0xf(%rdx)
movl %r15d, %eax
shrl $0x10, %eax
movb %al, -0xe(%rdx)
shrl $0x18, %ebx
movb %bl, -0xd(%rdx)
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
movslq %ecx, %rdi
addq %rdx, %rcx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
movb $0x0, (%rbp)
movl %ecx, %eax
addb $-0x9, %al
movb %al, 0x1(%rbp)
leal 0xfff7(%rcx), %eax
movb %ah, 0x2(%rbp)
leal 0xfffff7(%rcx), %eax
shrl $0x10, %eax
movb %al, 0x3(%rbp)
leal -0x9(%rcx), %eax
shrl $0x18, %eax
movb %al, 0x4(%rbp)
movq (%rsp), %rcx
movb %cl, 0x5(%rbp)
movb %ch, 0x6(%rbp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x7(%rbp)
shrl $0x18, %ecx
movb %cl, 0x8(%rbp)
addq %rbp, %rdi
callq 0x6c60
jmp 0x5fc41
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39a9b(%rip), %rdi     # 0x996f8
leaq 0x399fc(%rip), %rsi     # 0x99660
leaq 0x39a9d(%rip), %rcx     # 0x99708
movl $0x10f, %edx            # imm = 0x10F
callq 0x6460
leaq 0x39a59(%rip), %rdi     # 0x996d5
leaq 0x399dd(%rip), %rsi     # 0x99660
leaq 0x399e9(%rip), %rcx     # 0x99673
movl $0xbb, %edx
callq 0x6460
leaq 0x39a1e(%rip), %rdi     # 0x996b9
leaq 0x399be(%rip), %rsi     # 0x99660
leaq 0x399ca(%rip), %rcx     # 0x99673
movl $0xba, %edx
callq 0x6460
leaq 0x3981e(%rip), %rdi     # 0x994d8
leaq 0x3981e(%rip), %rsi     # 0x994df
leaq 0x3982a(%rip), %rcx     # 0x994f2
movl $0x6f, %edx
callq 0x6460