// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/htslib/cram/cram_codecs.c
// Function: get_bits_MSB
static inline unsigned int get_bits_MSB(cram_block *block, int nbits) {
    unsigned int val = 0;
    int i;

#if 0
    // Fits within the current byte */
    if (nbits <= block->bit+1) {
	val = (block->data[block->byte]>>(block->bit-(nbits-1))) & ((1<<nbits)-1);
	if ((block->bit -= nbits) == -1) {
	    block->bit = 7;
	    block->byte++;
	}
	return val;
    }

    // partial first byte
    val = block->data[block->byte] & ((1<<(block->bit+1))-1);
    nbits -= block->bit+1;
    block->bit = 7;
    block->byte++;

    // whole middle bytes
    while (nbits >= 8) {
	val = (val << 8) | block->data[block->byte++];
	nbits -= 8;
    }

    val <<= nbits;
    val |= (block->data[block->byte]>>(block->bit-(nbits-1))) & ((1<<nbits)-1);
    block->bit -= nbits;
    return val;
#endif

#if 0
    /* Inefficient implementation! */
    //printf("{");
    for (i = 0; i < nbits; i++)
	//val = (val << 1) | get_bit_MSB(block);
	GET_BIT_MSB(block, val);
#endif

#if 1
    /* Combination of 1st two methods */
    if (nbits <= block->bit+1) {
	val = (block->data[block->byte]>>(block->bit-(nbits-1))) & ((1<<nbits)-1);
	if ((block->bit -= nbits) == -1) {
	    block->bit = 7;
	    block->byte++;
	}
	return val;
    }

    switch(nbits) {
//    case 15: GET_BIT_MSB(block, val);
//    case 14: GET_BIT_MSB(block, val);
//    case 13: GET_BIT_MSB(block, val);
//    case 12: GET_BIT_MSB(block, val);
//    case 11: GET_BIT_MSB(block, val);
//    case 10: GET_BIT_MSB(block, val);
//    case  9: GET_BIT_MSB(block, val);
    case  8: GET_BIT_MSB(block, val);
    case  7: GET_BIT_MSB(block, val);
    case  6: GET_BIT_MSB(block, val);
    case  5: GET_BIT_MSB(block, val);
    case  4: GET_BIT_MSB(block, val);
    case  3: GET_BIT_MSB(block, val);
    case  2: GET_BIT_MSB(block, val);
    case  1: GET_BIT_MSB(block, val);
	break;

    default:
	for (i = 0; i < nbits; i++)
	    //val = (val << 1) | get_bit_MSB(block);
	    GET_BIT_MSB(block, val);
    }
#endif

    //printf("=0x%x}", val);

    return val;
}

// Assembly:
movl 0x38(%rdi), %edx
leal 0x1(%rdx), %eax
cmpl %esi, %eax
jge 0x4a8cd
leal -0x1(%rsi), %eax
cmpl $0x7, %eax
ja 0x4a907
xorl %esi, %esi
leaq 0xbdeb(%rip), %rcx      # 0x564f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %r8
movzbl (%rax,%r8), %esi
movl %edx, %ecx
shrl %cl, %esi
leal -0x1(%rdx), %eax
xorl %ecx, %ecx
testl %edx, %edx
setle %cl
addq %r8, %rcx
movq %rcx, 0x30(%rdi)
andl $0x7, %eax
movl %eax, 0x38(%rdi)
addl %esi, %esi
andl $0x2, %esi
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%rdi), %edx
xorl %r8d, %r8d
btl %edx, %eax
setb %r8b
orl %esi, %r8d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%rdi)
andl $0x7, %eax
movl %eax, 0x38(%rdi)
addl %r8d, %r8d
movl %r8d, %esi
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%rdi), %edx
xorl %r8d, %r8d
btl %edx, %eax
setb %r8b
orl %esi, %r8d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%rdi)
andl $0x7, %eax
movl %eax, 0x38(%rdi)
addl %r8d, %r8d
movl %r8d, %esi
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%rdi), %edx
xorl %r8d, %r8d
btl %edx, %eax
setb %r8b
orl %esi, %r8d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%rdi)
andl $0x7, %eax
movl %eax, 0x38(%rdi)
addl %r8d, %r8d
movl %r8d, %esi
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%rdi), %edx
xorl %r8d, %r8d
btl %edx, %eax
setb %r8b
orl %esi, %r8d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%rdi)
andl $0x7, %eax
movl %eax, 0x38(%rdi)
addl %r8d, %r8d
movl %r8d, %esi
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%rdi), %edx
xorl %r8d, %r8d
btl %edx, %eax
setb %r8b
orl %esi, %r8d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%rdi)
andl $0x7, %eax
movl %eax, 0x38(%rdi)
addl %r8d, %r8d
movl %r8d, %esi
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %rcx
movzbl (%rax,%rcx), %eax
movl 0x38(%rdi), %edx
xorl %r8d, %r8d
btl %edx, %eax
setb %r8b
orl %esi, %r8d
leal -0x1(%rdx), %eax
xorl %esi, %esi
testl %edx, %edx
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%rdi)
andl $0x7, %eax
movl %eax, 0x38(%rdi)
addl %r8d, %r8d
movl %r8d, %esi
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %rcx
movzbl (%rax,%rcx), %edx
movl 0x38(%rdi), %r8d
xorl %eax, %eax
btl %r8d, %edx
setb %al
orl %esi, %eax
leal -0x1(%r8), %edx
xorl %esi, %esi
testl %r8d, %r8d
setle %sil
addq %rcx, %rsi
movq %rsi, 0x30(%rdi)
andl $0x7, %edx
movl %edx, 0x38(%rdi)
retq
movq 0x20(%rdi), %rax
movq 0x30(%rdi), %r8
movzbl (%rax,%r8), %r9d
subl %esi, %edx
leal 0x1(%rdx), %ecx
shrl %cl, %r9d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %eax
notl %eax
andl %r9d, %eax
movl %edx, 0x38(%rdi)
cmpl $-0x1, %edx
jne 0x4a8cc
movl $0x7, 0x38(%rdi)
incq %r8
movq %r8, 0x30(%rdi)
retq
testl %esi, %esi
jle 0x4a953
movq 0x20(%rdi), %rcx
movq 0x30(%rdi), %rdx
movl 0x38(%rdi), %r8d
xorl %eax, %eax
movzbl (%rcx,%rdx), %r9d
xorl %r10d, %r10d
btl %r8d, %r9d
setb %r10b
leal (%r10,%rax,2), %eax
xorl %r9d, %r9d
testl %r8d, %r8d
leal -0x1(%r8), %r8d
setle %r9b
addq %r9, %rdx
movq %rdx, 0x30(%rdi)
andl $0x7, %r8d
movl %r8d, 0x38(%rdi)
decl %esi
jne 0x4a919
jmp 0x4a8cc
xorl %eax, %eax
retq