// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/htslib/cram/rANS_static.c
// Function: rans_uncompress_O1
unsigned char *rans_uncompress_O1(unsigned char *in, unsigned int in_size,
				  unsigned int *out_size) {
    /* Load in the static tables */
    unsigned char *cp = in + 9;
    int i, j = -999, x, out_sz, in_sz, rle_i, rle_j;
    char *out_buf = NULL;
    ari_decoder *D = NULL;              /* D[256] */
    RansDecSymbol (*syms)[256] = NULL;  /* syms[256][256] */

    if (*in++ != 1) // Order-1 check
	return NULL;

    in_sz  = ((in[0])<<0) | ((in[1])<<8) | ((in[2])<<16) | ((in[3])<<24);
    out_sz = ((in[4])<<0) | ((in[5])<<8) | ((in[6])<<16) | ((in[7])<<24);
    if (in_sz != in_size-9)
	return NULL;

    D = calloc(256, sizeof(*D));
    if (!D) goto cleanup;
    syms = malloc(256 * sizeof(*syms));
    if (!syms) goto cleanup;

    //fprintf(stderr, "out_sz=%d\n", out_sz);

    //i = *cp++;
    rle_i = 0;
    i = *cp++;
    do {
	rle_j = x = 0;
	j = *cp++;
	do {
	    if ((D[i].fc[j].F = *cp++) >= 128) {
		D[i].fc[j].F &= ~128;
		D[i].fc[j].F = ((D[i].fc[j].F & 127) << 8) | *cp++;
	    }
	    D[i].fc[j].C = x;

	    //fprintf(stderr, "i=%d j=%d F=%d C=%d\n", i, j, D[i].fc[j].F, D[i].fc[j].C);

	    if (!D[i].fc[j].F)
		D[i].fc[j].F = TOTFREQ;

	    RansDecSymbolInit(&syms[i][j], D[i].fc[j].C, D[i].fc[j].F);

	    /* Build reverse lookup table */
	    if (!D[i].R) {
                D[i].R = (unsigned char *)malloc(TOTFREQ);
                if (!D[i].R)
                    goto cleanup;
            }
	    memset(&D[i].R[x], j, D[i].fc[j].F);

	    x += D[i].fc[j].F;
	    assert(x <= TOTFREQ);

	    if (!rle_j && j+1 == *cp) {
		j = *cp++;
		rle_j = *cp++;
	    } else if (rle_j) {
		rle_j--;
		j++;
	    } else {
		j = *cp++;
	    }
	} while(j);

	if (!rle_i && i+1 == *cp) {
	    i = *cp++;
	    rle_i = *cp++;
	} else if (rle_i) {
	    rle_i--;
	    i++;
	} else {
	    i = *cp++;
	}
    } while (i);

    // Precompute reverse lookup of frequency.

    RansState rans0, rans1, rans2, rans3;
    uint8_t *ptr = cp;
    RansDecInit(&rans0, &ptr);
    RansDecInit(&rans1, &ptr);
    RansDecInit(&rans2, &ptr);
    RansDecInit(&rans3, &ptr);

    int isz4 = out_sz>>2;
    int l0 = 0;
    int l1 = 0;
    int l2 = 0;
    int l3 = 0;
    int i4[] = {0*isz4, 1*isz4, 2*isz4, 3*isz4};

    RansState R[4];
    R[0] = rans0;
    R[1] = rans1;
    R[2] = rans2;
    R[3] = rans3;

    /* Allocate output buffer */
    out_buf = malloc(out_sz);
    if (!out_buf) goto cleanup;

    for (; i4[0] < isz4; i4[0]++, i4[1]++, i4[2]++, i4[3]++) {
	uint32_t m[4] = {R[0] & ((1u << TF_SHIFT)-1),
			 R[1] & ((1u << TF_SHIFT)-1),
			 R[2] & ((1u << TF_SHIFT)-1),
			 R[3] & ((1u << TF_SHIFT)-1)};

	uint8_t c[4] = {D[l0].R[m[0]],
			D[l1].R[m[1]],
			D[l2].R[m[2]],
			D[l3].R[m[3]]};

	out_buf[i4[0]] = c[0];
	out_buf[i4[1]] = c[1];
	out_buf[i4[2]] = c[2];
	out_buf[i4[3]] = c[3];

	//RansDecAdvanceSymbolStep(&R[0], &syms[l0][c[0]], TF_SHIFT);
	//RansDecAdvanceSymbolStep(&R[1], &syms[l1][c[1]], TF_SHIFT);
	//RansDecAdvanceSymbolStep(&R[2], &syms[l2][c[2]], TF_SHIFT);
	//RansDecAdvanceSymbolStep(&R[3], &syms[l3][c[3]], TF_SHIFT);

	R[0] = syms[l0][c[0]].freq * (R[0]>>TF_SHIFT);
	R[1] = syms[l1][c[1]].freq * (R[1]>>TF_SHIFT);
	R[2] = syms[l2][c[2]].freq * (R[2]>>TF_SHIFT);
	R[3] = syms[l3][c[3]].freq * (R[3]>>TF_SHIFT);

	R[0] += m[0] - syms[l0][c[0]].start;
	R[1] += m[1] - syms[l1][c[1]].start;
	R[2] += m[2] - syms[l2][c[2]].start;
	R[3] += m[3] - syms[l3][c[3]].start;

	RansDecRenorm(&R[0], &ptr);
	RansDecRenorm(&R[1], &ptr);
	RansDecRenorm(&R[2], &ptr);
	RansDecRenorm(&R[3], &ptr);

	l0 = c[0];
	l1 = c[1];
	l2 = c[2];
	l3 = c[3];
    }

    rans0 = R[0];
    rans1 = R[1];
    rans2 = R[2];
    rans3 = R[3];

    // Remainder
    for (; i4[3] < out_sz; i4[3]++) {
	unsigned char c3 = D[l3].R[RansDecGet(&rans3, TF_SHIFT)];
	out_buf[i4[3]] = c3;
	RansDecAdvanceSymbol(&rans3, &ptr, &syms[l3][c3], TF_SHIFT);
	l3 = c3;
    }

    *out_size = out_sz;

 cleanup:
    if (D) {
        for (i = 0; i < 256; i++)
            if (D[i].R) free(D[i].R);
        free(D);
    }
    free(syms);

    return (unsigned char *)out_buf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
cmpb $0x1, (%rdi)
jne 0x61249
movq %rdi, %r13
addl $-0x9, %esi
cmpl %esi, 0x1(%rdi)
jne 0x61249
movq %rdx, %rbx
movl 0x5(%r13), %ebp
movl $0x100, %edi            # imm = 0x100
movl $0x808, %esi            # imm = 0x808
callq 0x6470
movq %rax, %r15
testq %rax, %rax
je 0x6124e
movl $0x40000, %edi          # imm = 0x40000
callq 0x69d0
xorl %r14d, %r14d
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x61266
movl %ebp, 0x24(%rsp)
movq %rbx, 0x90(%rsp)
movzbl 0x9(%r13), %ecx
addq $0xa, %r13
movq %r15, 0x28(%rsp)
movq %r14, 0x68(%rsp)
movzbl (%r13), %ebp
incq %r13
movl %ecx, 0x10(%rsp)
movslq %ecx, %rcx
movq %rcx, %rax
shlq $0xb, %rax
leaq (%rax,%rcx,8), %r14
addq %r15, %r14
shlq $0xa, %rcx
addq 0x8(%rsp), %rcx
movq %rcx, 0x18(%rsp)
xorl %r15d, %r15d
xorl %ebx, %ebx
movzbl (%r13), %ecx
movslq %ebp, %rax
movl %ecx, (%r14,%rax,8)
testb %cl, %cl
js 0x60cb1
incq %r13
jmp 0x60cca
andl $0x7f, %ecx
movl %ecx, (%r14,%rax,8)
shll $0x8, %ecx
movzbl 0x1(%r13), %edx
addq $0x2, %r13
orl %ecx, %edx
movl %edx, (%r14,%rax,8)
movl %ebx, 0x4(%r14,%rax,8)
cmpl $0x0, (%r14,%rax,8)
jne 0x60cde
movl $0x1000, (%r14,%rax,8)  # imm = 0x1000
cmpl $0x10001, %ebx          # imm = 0x10001
jae 0x612dd
movslq (%r14,%rax,8), %r12
movl $0x10000, %ecx          # imm = 0x10000
subl %ebx, %ecx
cmpl %r12d, %ecx
jb 0x612be
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movw %bx, (%rax)
movw %r12w, 0x2(%rax)
cmpq $0x0, 0x800(%r14)
jne 0x60d33
movl $0x1000, %edi           # imm = 0x1000
callq 0x69d0
movq %rax, 0x800(%r14)
testq %rax, %rax
je 0x6125c
movl %ebx, %edi
addq 0x800(%r14), %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0x63b0
addl %r12d, %ebx
cmpl $0x1001, %ebx           # imm = 0x1001
jge 0x612fc
testl %r15d, %r15d
je 0x60d61
decl %r15d
incl %ebp
jmp 0x60d7f
movl %ebp, %eax
incl %eax
movzbl (%r13), %ebp
cmpl %ebp, %eax
jne 0x60d79
movzbl 0x1(%r13), %r15d
addq $0x2, %r13
jmp 0x60d7f
incq %r13
xorl %r15d, %r15d
testl %ebp, %ebp
jne 0x60c9c
movq 0x68(%rsp), %r14
testl %r14d, %r14d
je 0x60da1
decl %r14d
movl 0x10(%rsp), %ecx
incl %ecx
movq 0x28(%rsp), %r15
jmp 0x60dc6
movl 0x10(%rsp), %eax
incl %eax
movzbl (%r13), %ecx
cmpl %ecx, %eax
movq 0x28(%rsp), %r15
jne 0x60dc0
movzbl 0x1(%r13), %r14d
addq $0x2, %r13
jmp 0x60dc6
incq %r13
xorl %r14d, %r14d
testl %ecx, %ecx
jne 0x60c67
movzbl (%r13), %eax
movl %eax, 0x70(%rsp)
movzbl 0x1(%r13), %eax
movl %eax, 0x78(%rsp)
movzbl 0x2(%r13), %eax
movl %eax, 0x40(%rsp)
movzbl 0x3(%r13), %r15d
movzbl 0x4(%r13), %eax
movl %eax, 0x48(%rsp)
movzbl 0x5(%r13), %eax
movl %eax, 0x50(%rsp)
movzbl 0x6(%r13), %eax
movl %eax, 0x58(%rsp)
movzbl 0x7(%r13), %ebp
movzbl 0x8(%r13), %eax
movl %eax, 0x80(%rsp)
movzbl 0x9(%r13), %eax
movl %eax, 0x60(%rsp)
movzbl 0xa(%r13), %eax
movl %eax, 0x30(%rsp)
movzbl 0xb(%r13), %r14d
movzbl 0xc(%r13), %eax
movl %eax, 0x38(%rsp)
movzbl 0xd(%r13), %ebx
movzbl 0xe(%r13), %eax
movl %eax, 0x10(%rsp)
movzbl 0xf(%r13), %r12d
movslq 0x24(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x69d0
movq $0x0, 0x18(%rsp)
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x6125c
movl 0x24(%rsp), %eax
movl %eax, %ecx
sarl $0x2, %ecx
leal (%rcx,%rcx,2), %edi
addq $0x10, %r13
shll $0x8, %ebx
addl 0x38(%rsp), %ebx
movl 0x10(%rsp), %eax
shll $0x10, %eax
orl %ebx, %eax
shll $0x18, %r12d
orl %eax, %r12d
testl %ecx, %ecx
jle 0x61198
movl 0x78(%rsp), %edx
shll $0x8, %edx
addl 0x70(%rsp), %edx
movl 0x40(%rsp), %eax
shll $0x10, %eax
orl %edx, %eax
shll $0x18, %r15d
orl %eax, %r15d
movl 0x50(%rsp), %edx
shll $0x8, %edx
addl 0x48(%rsp), %edx
movl 0x58(%rsp), %eax
shll $0x10, %eax
orl %edx, %eax
shll $0x18, %ebp
orl %eax, %ebp
movl 0x60(%rsp), %edx
shll $0x8, %edx
addl 0x80(%rsp), %edx
movl 0x30(%rsp), %eax
shll $0x10, %eax
orl %edx, %eax
shll $0x18, %r14d
orl %eax, %r14d
movl %ecx, %eax
addl %ecx, %ecx
movl %edi, %edi
xorl %edx, %edx
movq %rax, 0x70(%rsp)
movq %rax, %r9
movq $0x0, 0x18(%rsp)
xorl %esi, %esi
xorl %r8d, %r8d
xorl %ebx, %ebx
movq %rdx, 0x38(%rsp)
movq %rcx, 0x10(%rsp)
movq %r9, 0x30(%rsp)
movq %rdi, 0x80(%rsp)
movq %rbx, %r9
movl %r15d, %ebx
movl $0xfff, %edi            # imm = 0xFFF
andl %edi, %ebx
movl %ebp, %eax
andl %edi, %eax
movl %r14d, %ecx
andl %edi, %ecx
movl %r12d, %r11d
andl %edi, %r11d
movq %r9, %rdx
shlq $0xb, %rdx
leaq (%rdx,%r9,8), %rdx
movq 0x28(%rsp), %rdi
movq 0x800(%rdi,%rdx), %rdx
movzbl (%rdx,%rbx), %r10d
shlq $0xa, %r9
addq 0x8(%rsp), %r9
movzwl 0x2(%r9,%r10,4), %edx
shrl $0xc, %r15d
imull %edx, %r15d
movq %r8, %rdx
shlq $0xb, %rdx
movq %r8, 0x78(%rsp)
leaq (%rdx,%r8,8), %rdx
movq 0x800(%rdi,%rdx), %rdx
movzbl (%rdx,%rax), %r8d
movzwl (%r9,%r10,4), %r9d
subl %r9d, %ebx
movq %rsi, %r9
shlq $0xb, %r9
movq %rsi, 0x58(%rsp)
leaq (%r9,%rsi,8), %r9
movq 0x800(%rdi,%r9), %r9
movzbl (%r9,%rcx), %esi
movl 0x18(%rsp), %edx
movq 0x80(%rsp), %r9
addl %r15d, %ebx
movq %rdx, %r15
shlq $0xb, %r15
movq %rdx, 0x40(%rsp)
leaq (%r15,%rdx,8), %r15
movq 0x800(%rdi,%r15), %r15
movzbl (%r15,%r11), %r15d
movq 0x68(%rsp), %rdx
movq %r10, 0x48(%rsp)
movq 0x38(%rsp), %rdi
movb %r10b, (%rdx,%rdi)
movq %r8, 0x60(%rsp)
movq 0x30(%rsp), %rdi
movb %r8b, (%rdx,%rdi)
movq %rsi, 0x50(%rsp)
movq 0x10(%rsp), %rdi
movb %sil, (%rdx,%rdi)
movq %r9, %rdi
movq %r15, 0x18(%rsp)
movb %r15b, (%rdx,%r9)
cmpl $0x7fffff, %ebx         # imm = 0x7FFFFF
ja 0x6104c
movl %ebx, %edx
shll $0x8, %edx
movzbl (%r13), %r15d
incq %r13
orl %edx, %r15d
cmpl $0x8000, %ebx           # imm = 0x8000
movl %r15d, %ebx
jb 0x6102f
jmp 0x6104f
movl %ebx, %r15d
movq 0x78(%rsp), %rsi
shlq $0xa, %rsi
addq 0x8(%rsp), %rsi
movq 0x60(%rsp), %r8
movzwl 0x2(%rsi,%r8,4), %edx
shrl $0xc, %ebp
imull %edx, %ebp
movzwl (%rsi,%r8,4), %edx
subl %edx, %eax
addl %ebp, %eax
cmpl $0x7fffff, %eax         # imm = 0x7FFFFF
ja 0x610a7
movq 0x48(%rsp), %rbx
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %r8
movl %eax, %edx
shll $0x8, %edx
movzbl (%r13), %ebp
incq %r13
orl %edx, %ebp
cmpl $0x8000, %eax           # imm = 0x8000
movl %ebp, %eax
jb 0x6108d
jmp 0x610b8
movl %eax, %ebp
movq 0x48(%rsp), %rbx
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %r8
shlq $0xa, %rsi
addq 0x8(%rsp), %rsi
movzwl 0x2(%rsi,%r8,4), %eax
shrl $0xc, %r14d
imull %eax, %r14d
movzwl (%rsi,%r8,4), %eax
subl %eax, %ecx
addl %r14d, %ecx
cmpl $0x7fffff, %ecx         # imm = 0x7FFFFF
ja 0x61108
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rsi
movl %ecx, %eax
shll $0x8, %eax
movzbl (%r13), %r14d
incq %r13
orl %eax, %r14d
cmpl $0x8000, %ecx           # imm = 0x8000
movl %r14d, %ecx
jb 0x610eb
jmp 0x61115
movl %ecx, %r14d
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rsi
shlq $0xa, %rsi
addq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rcx
movzwl 0x2(%rsi,%rcx,4), %eax
shrl $0xc, %r12d
imull %eax, %r12d
movzwl (%rsi,%rcx,4), %eax
subl %eax, %r11d
addl %r12d, %r11d
cmpl $0x7fffff, %r11d        # imm = 0x7FFFFF
ja 0x6116c
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %r9
movl %r11d, %eax
shll $0x8, %eax
movzbl (%r13), %r12d
incq %r13
orl %eax, %r12d
cmpl $0x8000, %r11d          # imm = 0x8000
movl %r12d, %r11d
jb 0x6114d
jmp 0x61179
movl %r11d, %r12d
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %r9
incq %rdx
incq %r9
incq %rcx
incq %rdi
movq %r8, %rsi
movq 0x60(%rsp), %r8
cmpq 0x70(%rsp), %rdx
jne 0x60f17
movl 0x24(%rsp), %r10d
cmpl %r10d, %edi
movq 0x28(%rsp), %r15
movq 0x68(%rsp), %r14
movq %rdi, %rax
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %r9
jge 0x61244
cltq
movl 0x18(%rsp), %edx
movq %rdx, %rcx
shlq $0xb, %rcx
leaq (%rcx,%rdx,8), %rcx
movq 0x800(%r15,%rcx), %rsi
movl %r12d, %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movzbl (%rsi,%rcx), %r11d
movb %r11b, (%r14,%rax)
shlq $0xa, %rdx
addq 0x8(%rsp), %rdx
movzwl (%rdx,%r11,4), %esi
movq %r11, 0x18(%rsp)
movzwl 0x2(%rdx,%r11,4), %edx
shrl $0xc, %r12d
imull %edx, %r12d
subl %esi, %ecx
addl %r12d, %ecx
cmpl $0x7fffff, %ecx         # imm = 0x7FFFFF
ja 0x61239
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r13), %r12d
incq %r13
orl %edx, %r12d
cmpl $0x8000, %ecx           # imm = 0x8000
movl %r12d, %ecx
jb 0x6121c
jmp 0x6123c
movl %ecx, %r12d
incq %rax
cmpq %r9, %rax
jl 0x611c5
movl %r10d, (%rdi)
jmp 0x6126f
xorl %r14d, %r14d
jmp 0x612a9
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
jmp 0x6126f
xorl %r14d, %r14d
movq 0x28(%rsp), %r15
jmp 0x6126f
movq $0x0, 0x8(%rsp)
testq %r15, %r15
je 0x6129f
movl $0x800, %ebx            # imm = 0x800
movq (%r15,%rbx), %rdi
testq %rdi, %rdi
je 0x61287
callq 0x68a0
addq $0x808, %rbx            # imm = 0x808
cmpq $0x81000, %rbx          # imm = 0x81000
jne 0x61279
movq %r15, %rdi
callq 0x68a0
movq 0x8(%rsp), %rdi
callq 0x68a0
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x384d8(%rip), %rdi     # 0x9979d
leaq 0x38394(%rip), %rsi     # 0x99660
leaq 0x3848e(%rip), %rcx     # 0x99761
movl $0x104, %edx            # imm = 0x104
callq 0x6460
leaq 0x3846a(%rip), %rdi     # 0x9974e
leaq 0x38375(%rip), %rsi     # 0x99660
leaq 0x3846f(%rip), %rcx     # 0x99761
movl $0x103, %edx            # imm = 0x103
callq 0x6460
leaq 0x382ff(%rip), %rdi     # 0x99602
leaq 0x381d5(%rip), %rsi     # 0x994df
leaq 0x382fe(%rip), %rcx     # 0x9960f
movl $0x26a, %edx            # imm = 0x26A
callq 0x6460