// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/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 0x186f9(%rip), %xmm1    # 0x548c8
movsd 0x19131(%rip), %xmm0    # 0x55308
movsd %xmm1, 0x18(%rsp)
addsd %xmm1, %xmm0
addsd 0x19127(%rip), %xmm0    # 0x55310
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x1670b(%rip), %xmm0    # 0x52908
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
callq 0x4700
movq %rax, %r12
leaq 0x30(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x42d0
movq %r12, 0x10(%rsp)
testq %r12, %r12
je 0x3c83b
cvttsd2si 0x18(%rsp), %eax
cltq
movq %r14, (%rsp)
testl %r14d, %r14d
je 0x3c254
xorl %ecx, %ecx
movzbl (%r13,%rcx), %edx
incl 0x30(%rsp,%rdx,4)
incq %rcx
cmpq %rcx, %rbx
jne 0x3c242
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 0x3c2c3
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 0x3c294
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 0x3c8af
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 0x3c401
testl %ebx, %ebx
je 0x3c416
decl %ebx
movq %r14, %r12
movl 0x30(%rsp,%rdi,4), %eax
movl $0x1, %r9d
cmpl $0x80, %eax
jge 0x3c32e
movq %r12, %rcx
jmp 0x3c346
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 0x3c890
movl 0x30(%rsp,%rdi,4), %r14d
movl $0x1000, %eax           # imm = 0x1000
subl %r11d, %eax
cmpl %r14d, %eax
jb 0x3c871
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 0x3c3b1
movl $0xffffffff, 0x4(%r8)   # imm = 0xFFFFFFFF
movw $0x0, 0xe(%r8)
leal 0xfff(%r11), %eax
jmp 0x3c3eb
movl $0x1e, %esi
leal -0x1e(%rsi), %ecx
movl $0x1, %eax
shll %cl, %eax
incl %esi
cmpl %r14d, %eax
jb 0x3c3b6
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 0x3c300
jmp 0x3c46c
leaq 0x1(%r14), %r12
movb %dil, (%r14)
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x3c318
cmpl $0x0, 0x2c(%rsp,%rdi,4)
je 0x3c318
leaq 0x1(%rdi), %rax
movl %eax, %ebx
cmpq $0xff, %rdi
je 0x3c45d
movq %r10, %rbx
cmpl $0x0, 0x30(%rsp,%rbx,4)
je 0x3c45d
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x3c445
movl $0x100, %ebx            # imm = 0x100
subl %eax, %ebx
movb %bl, 0x1(%r14)
addq $0x2, %r14
jmp 0x3c315
movb $0x0, (%r14)
movq (%rsp), %r12
movl %r12d, %edi
andl $0x3, %edi
movl $0x800000, %esi         # imm = 0x800000
leaq 0x18e9a(%rip), %rax     # 0x55320
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 0x3c852
leaq (%rsp,%rax), %r8
addq $0x430, %r8             # imm = 0x430
movl $0x800000, %eax         # imm = 0x800000
movq 0x8(%rsp), %rdx
cmpl $0x800000, %ecx         # imm = 0x800000
ja 0x3c502
movq 0x8(%rsp), %rdx
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
cmpl %ecx, %eax
jae 0x3c4f5
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 0x3c852
leaq (%rsp,%rax), %rdi
addq $0x430, %rdi            # imm = 0x430
movl $0x800000, %eax         # imm = 0x800000
cmpl $0x800000, %ecx         # imm = 0x800000
ja 0x3c56b
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
cmpl %ecx, %eax
jae 0x3c55e
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 0x3c852
leaq (%rsp,%rax), %rdi
addq $0x430, %rdi            # imm = 0x430
movl $0x800000, %eax         # imm = 0x800000
cmpl $0x800000, %ecx         # imm = 0x800000
ja 0x3c5d4
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
cmpl %ecx, %eax
jae 0x3c5c7
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 0x3c784
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 0x3c852
movzbl -0x2(%r13,%rdi), %r8d
movzbl -0x3(%r13,%rdi), %r14d
movzbl -0x4(%r13,%rdi), %r12d
cmpl %r10d, %esi
jb 0x3c657
movb %sil, -0x1(%rdx)
decq %rdx
shrl $0x8, %esi
jmp 0x3c646
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 0x3c852
addl 0x8(%r11), %esi
movzwl 0xc(%r11), %r11d
cmpl %ecx, %ebx
jb 0x3c6a4
movb %bl, -0x1(%rdx)
decq %rdx
shrl $0x8, %ebx
jmp 0x3c695
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 0x3c852
addl 0x8(%r8), %ebx
movzwl 0xc(%r8), %r14d
cmpl %ecx, %eax
jb 0x3c6e7
movb %al, -0x1(%rdx)
decq %rdx
shrl $0x8, %eax
jmp 0x3c6d8
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 0x3c852
addl 0x8(%rbp), %eax
movzwl 0xc(%rbp), %ebp
movl %r15d, %r9d
cmpl %ecx, %r15d
jb 0x3c730
movb %r9b, -0x1(%rdx)
decq %rdx
shrl $0x8, %r9d
cmpl %ecx, %r9d
jae 0x3c720
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 0x3c61a
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 0x48c0
jmp 0x3c83d
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 0x18d07(%rip), %rdi     # 0x55560
leaq 0x18c68(%rip), %rsi     # 0x554c8
leaq 0x18d09(%rip), %rcx     # 0x55570
movl $0x10f, %edx            # imm = 0x10F
callq 0x4350
leaq 0x18cc5(%rip), %rdi     # 0x5553d
leaq 0x18c49(%rip), %rsi     # 0x554c8
leaq 0x18c55(%rip), %rcx     # 0x554db
movl $0xbb, %edx
callq 0x4350
leaq 0x18c8a(%rip), %rdi     # 0x55521
leaq 0x18c2a(%rip), %rsi     # 0x554c8
leaq 0x18c36(%rip), %rcx     # 0x554db
movl $0xba, %edx
callq 0x4350
leaq 0x18a8a(%rip), %rdi     # 0x55340
leaq 0x18a8a(%rip), %rsi     # 0x55347
leaq 0x18a96(%rip), %rcx     # 0x5535a
movl $0x6f, %edx
callq 0x4350