// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/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 0x3de45
movq %rdi, %r13
addl $-0x9, %esi
cmpl %esi, 0x1(%rdi)
jne 0x3de45
movq %rdx, %rbx
movl 0x5(%r13), %ebp
movl $0x100, %edi            # imm = 0x100
movl $0x808, %esi            # imm = 0x808
callq 0x4360
movq %rax, %r15
testq %rax, %rax
je 0x3de4a
movl $0x40000, %edi          # imm = 0x40000
callq 0x4700
xorl %r14d, %r14d
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3de62
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 0x3d8ad
incq %r13
jmp 0x3d8c6
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 0x3d8da
movl $0x1000, (%r14,%rax,8)  # imm = 0x1000
cmpl $0x10001, %ebx          # imm = 0x10001
jae 0x3ded9
movslq (%r14,%rax,8), %r12
movl $0x10000, %ecx          # imm = 0x10000
subl %ebx, %ecx
cmpl %r12d, %ecx
jb 0x3deba
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movw %bx, (%rax)
movw %r12w, 0x2(%rax)
cmpq $0x0, 0x800(%r14)
jne 0x3d92f
movl $0x1000, %edi           # imm = 0x1000
callq 0x4700
movq %rax, 0x800(%r14)
testq %rax, %rax
je 0x3de58
movl %ebx, %edi
addq 0x800(%r14), %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0x42d0
addl %r12d, %ebx
cmpl $0x1001, %ebx           # imm = 0x1001
jge 0x3def8
testl %r15d, %r15d
je 0x3d95d
decl %r15d
incl %ebp
jmp 0x3d97b
movl %ebp, %eax
incl %eax
movzbl (%r13), %ebp
cmpl %ebp, %eax
jne 0x3d975
movzbl 0x1(%r13), %r15d
addq $0x2, %r13
jmp 0x3d97b
incq %r13
xorl %r15d, %r15d
testl %ebp, %ebp
jne 0x3d898
movq 0x68(%rsp), %r14
testl %r14d, %r14d
je 0x3d99d
decl %r14d
movl 0x10(%rsp), %ecx
incl %ecx
movq 0x28(%rsp), %r15
jmp 0x3d9c2
movl 0x10(%rsp), %eax
incl %eax
movzbl (%r13), %ecx
cmpl %ecx, %eax
movq 0x28(%rsp), %r15
jne 0x3d9bc
movzbl 0x1(%r13), %r14d
addq $0x2, %r13
jmp 0x3d9c2
incq %r13
xorl %r14d, %r14d
testl %ecx, %ecx
jne 0x3d863
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 0x4700
movq $0x0, 0x18(%rsp)
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x3de58
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 0x3dd94
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 0x3dc48
movl %ebx, %edx
shll $0x8, %edx
movzbl (%r13), %r15d
incq %r13
orl %edx, %r15d
cmpl $0x8000, %ebx           # imm = 0x8000
movl %r15d, %ebx
jb 0x3dc2b
jmp 0x3dc4b
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 0x3dca3
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 0x3dc89
jmp 0x3dcb4
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 0x3dd04
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 0x3dce7
jmp 0x3dd11
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 0x3dd68
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 0x3dd49
jmp 0x3dd75
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 0x3db13
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 0x3de40
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 0x3de35
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r13), %r12d
incq %r13
orl %edx, %r12d
cmpl $0x8000, %ecx           # imm = 0x8000
movl %r12d, %ecx
jb 0x3de18
jmp 0x3de38
movl %ecx, %r12d
incq %rax
cmpq %r9, %rax
jl 0x3ddc1
movl %r10d, (%rdi)
jmp 0x3de6b
xorl %r14d, %r14d
jmp 0x3dea5
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
jmp 0x3de6b
xorl %r14d, %r14d
movq 0x28(%rsp), %r15
jmp 0x3de6b
movq $0x0, 0x8(%rsp)
testq %r15, %r15
je 0x3de9b
movl $0x800, %ebx            # imm = 0x800
movq (%r15,%rbx), %rdi
testq %rdi, %rdi
je 0x3de83
callq 0x4610
addq $0x808, %rbx            # imm = 0x808
cmpq $0x81000, %rbx          # imm = 0x81000
jne 0x3de75
movq %r15, %rdi
callq 0x4610
movq 0x8(%rsp), %rdi
callq 0x4610
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17744(%rip), %rdi     # 0x55605
leaq 0x17600(%rip), %rsi     # 0x554c8
leaq 0x176fa(%rip), %rcx     # 0x555c9
movl $0x104, %edx            # imm = 0x104
callq 0x4350
leaq 0x176d6(%rip), %rdi     # 0x555b6
leaq 0x175e1(%rip), %rsi     # 0x554c8
leaq 0x176db(%rip), %rcx     # 0x555c9
movl $0x103, %edx            # imm = 0x103
callq 0x4350
leaq 0x1756b(%rip), %rdi     # 0x5546a
leaq 0x17441(%rip), %rsi     # 0x55347
leaq 0x1756a(%rip), %rcx     # 0x55477
movl $0x26a, %edx            # imm = 0x26A
callq 0x4350