// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: cram_subexp_decode
int cram_subexp_decode(cram_slice *slice, cram_codec *c, cram_block *in, char *out, int *out_size) {
    int32_t *out_i = (int32_t *)out;
    int n, count;
    int k = c->subexp.k;

    for (count = 0, n = *out_size; count < n; count++) {
	int i = 0, tail;
	int val;

	/* Get number of 1s */
	//while (get_bit_MSB(in) == 1) i++;
	i = get_one_bits_MSB(in);
        if (i < 0 || cram_not_enough_bits(in, i > 0 ? i + k - 1 : k))
            return -1;
	/*
	 * Val is
	 * i > 0:  2^(k+i-1) + k+i-1 bits
	 * i = 0:  k bits
	 */
	if (i) {
	    tail = i + k-1;
	    val = 0;
	    while (tail) {
		//val = val<<1; val |= get_bit_MSB(in);
		GET_BIT_MSB(in, val);
		tail--;
	    }
	    val += 1 << (i + k-1);
	} else {
	    tail = k;
	    val = 0;
	    while (tail) {
		//val = val<<1; val |= get_bit_MSB(in);
		GET_BIT_MSB(in, val);
		tail--;
	    }
	}

	out_i[count] = val - c->subexp.offset;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x20(%rsp)
movq %rdx, %r15
movq %rsi, 0x18(%rsp)
movl 0x34(%rsi), %edi
movl (%r8), %r8d
xorl %eax, %eax
testl %r8d, %r8d
cmovlel %eax, %r8d
pushq $0x2
popq %r9
pushq $0x7
popq %r10
xorl %r11d, %r11d
movl %edi, 0x4(%rsp)
movq %r8, 0x8(%rsp)
cmpq %r8, %r11
je 0x3cef6
movq 0x30(%r15), %r12
movslq 0x14(%r15), %rax
cmpq %rax, %r12
jae 0x3cee4
movq 0x20(%r15), %r14
movl 0x38(%r15), %r13d
movl %r9d, %ebx
movzbl (%r14,%r12), %edx
movl %r13d, %ecx
shrl %cl, %edx
subl $0x1, %r13d
movl %r13d, 0x38(%r15)
jae 0x3cdf0
movl $0x7, 0x38(%r15)
incq %r12
movq %r12, 0x30(%r15)
andl $0x1, %edx
movl %r10d, %r13d
cmpq %rax, %r12
jne 0x3cdf3
testl %edx, %edx
je 0x3cdf3
jmp 0x3cee4
andl $0x1, %edx
decl %ebx
testl %edx, %edx
jne 0x3cdb9
movq %r11, 0x10(%rsp)
movl %edi, %ebp
subl %ebx, %ebp
cmpl $0x1, %ebx
movl %ebp, %esi
cmovel %edi, %esi
movq %r15, %rdi
callq 0x3c3b2
testl %eax, %eax
jne 0x3cee4
xorl %eax, %eax
cmpl $0x1, %ebx
jne 0x3ce73
movl 0x4(%rsp), %edi
movl %edi, %ecx
movq 0x8(%rsp), %r8
pushq $0x2
popq %r9
pushq $0x7
popq %r10
movq 0x10(%rsp), %r11
subl $0x1, %ecx
jb 0x3cecb
movzbl (%r14,%r12), %edx
xorl %esi, %esi
btl %r13d, %edx
setb %sil
leal (%rsi,%rax,2), %eax
xorl %edx, %edx
testl %r13d, %r13d
leal -0x1(%r13), %esi
setle %dl
addq %rdx, %r12
movq %r12, 0x30(%r15)
andl $0x7, %esi
movl %esi, 0x38(%r15)
movl %esi, %r13d
jmp 0x3ce39
movl 0x4(%rsp), %edi
movl %edi, %ecx
movq 0x8(%rsp), %r8
pushq $0x2
popq %r9
pushq $0x7
popq %r10
movq 0x10(%rsp), %r11
cmpl %ecx, %ebx
je 0x3cec2
movzbl (%r14,%r12), %edx
xorl %esi, %esi
btl %r13d, %edx
setb %sil
leal (%rsi,%rax,2), %eax
xorl %edx, %edx
testl %r13d, %r13d
leal -0x1(%r13), %esi
setle %dl
addq %rdx, %r12
movq %r12, 0x30(%r15)
andl $0x7, %esi
movl %esi, 0x38(%r15)
decl %ecx
movl %esi, %r13d
jmp 0x3ce8b
pushq $0x1
popq %rdx
movl %ebp, %ecx
shll %cl, %edx
addl %edx, %eax
movq 0x18(%rsp), %rcx
subl 0x30(%rcx), %eax
movq 0x20(%rsp), %rcx
movl %eax, (%rcx,%r11,4)
incq %r11
jmp 0x3cd94
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x3cee7