// File: /workspace/github_c_makefile_star2_O3/samtools[P]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->u.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->u.subexp.offset;
    }

    return 0;
}

// Assembly:
movslq (%r8), %r9
testq %r9, %r9
jle 0x8ff84
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %rdi
movl 0x64(%rsi), %r10d
movq 0x30(%rdx), %r11
xorl %ebx, %ebx
movslq 0x14(%rdx), %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %r15, %r11
jae 0x8ff79
movq 0x20(%rdx), %r14
movl 0x38(%rdx), %ecx
movl $0x2, %ebp
movzbl (%r14,%r11), %r8d
shrl %cl, %r8d
subl $0x1, %ecx
movl %ecx, 0x38(%rdx)
jae 0x8fe76
movl $0x7, 0x38(%rdx)
incq %r11
movq %r11, 0x30(%rdx)
andl $0x1, %r8d
movl $0x7, %ecx
cmpq %r15, %r11
jne 0x8fe7a
testl %r8d, %r8d
je 0x8fe7a
jmp 0x8ff79
andl $0x1, %r8d
decl %ebp
testl %r8d, %r8d
jne 0x8fe40
movl %r10d, %r8d
subl %ebp, %r8d
cmpl $0x1, %ebp
movl %r8d, %r12d
cmovel %r10d, %r12d
testl %r12d, %r12d
js 0x8ff79
je 0x8fea5
cmpq %r11, %r15
jbe 0x8ff79
subq %r11, %r15
cmpq $0x10000000, %r15       # imm = 0x10000000
ja 0x8fecb
movslq %ecx, %r13
leaq -0x7(,%r15,8), %r15
addq %r13, %r15
movl %r12d, %r12d
cmpq %r12, %r15
jb 0x8ff79
cmpl $0x1, %ebp
jne 0x8ff12
xorl %r15d, %r15d
testl %r10d, %r10d
je 0x8ff63
movl %r10d, %eax
movzbl (%r14,%r11), %r8d
xorl %r12d, %r12d
btl %ecx, %r8d
setb %r12b
leal (%r12,%r15,2), %r15d
xorl %r8d, %r8d
testl %ecx, %ecx
leal -0x1(%rcx), %ecx
setle %r8b
addq %r8, %r11
movq %r11, 0x30(%rdx)
andl $0x7, %ecx
movl %ecx, 0x38(%rdx)
decl %eax
jne 0x8fedf
jmp 0x8ff63
xorl %eax, %eax
cmpl %ebp, %r10d
je 0x8ff54
xorl %eax, %eax
movl %r10d, %r15d
movzbl (%r14,%r11), %r12d
xorl %r13d, %r13d
btl %ecx, %r12d
setb %r13b
leal (%r13,%rax,2), %eax
xorl %r12d, %r12d
testl %ecx, %ecx
leal -0x1(%rcx), %ecx
setle %r12b
addq %r12, %r11
movq %r11, 0x30(%rdx)
andl $0x7, %ecx
movl %ecx, 0x38(%rdx)
decl %r15d
cmpl %r15d, %ebp
jne 0x8ff1e
movl $0x1, %r15d
movl %r8d, %ecx
shll %cl, %r15d
addl %eax, %r15d
subl 0x60(%rsi), %r15d
movl %r15d, (%rdi,%rbx,4)
incq %rbx
cmpq %r9, %rbx
jne 0x8fe22
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq