// File: 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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jg 0x6efe6
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
movl -0x14(%rbp), %edx
subl $0x1, %edx
subl %edx, %ecx
sarl %cl, %eax
movl -0x14(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
subl %edx, %eax
movl %eax, 0x38(%rcx)
cmpl $-0x1, %eax
jne 0x6efdb
movq -0x10(%rbp), %rax
movl $0x7, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6f3a4
movl -0x14(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x7, %eax
ja 0x6f320
movq -0x28(%rbp), %rax
leaq 0xf9a7(%rip), %rcx      # 0x7e9ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
jmp 0x6f39e
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x6f39c
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %ecx
sarl %cl, %eax
andl $0x1, %eax
orl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movl 0x38(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0x7, %ecx
movl %ecx, 0x38(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6f327
jmp 0x6f39e
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)