// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/cram/cram_io.c
// Function: itf8_decode
int itf8_decode(cram_fd *fd, int32_t *val_p) {
    static int nbytes[16] = {
	0,0,0,0, 0,0,0,0,                               // 0000xxxx - 0111xxxx
	1,1,1,1,                                        // 1000xxxx - 1011xxxx
	2,2,                                            // 1100xxxx - 1101xxxx
	3,                                              // 1110xxxx
	4,                                              // 1111xxxx
    };

    static int nbits[16] = {
	0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, // 0000xxxx - 0111xxxx
	0x3f, 0x3f, 0x3f, 0x3f,                         // 1000xxxx - 1011xxxx
	0x1f, 0x1f,                                     // 1100xxxx - 1101xxxx
	0x0f,                                           // 1110xxxx
	0x0f,                                           // 1111xxxx
    };

    int32_t val = hgetc(fd->fp);
    if (val == -1)
	return -1;

    int i = nbytes[val>>4];
    val &= nbits[val>>4];

    switch(i) {
    case 0:
	*val_p = val;
	return 1;

    case 1:
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val;
	return 2;

    case 2:
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val;
	return 3;

    case 3:
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	*val_p = val;
	return 4;

    case 4: // really 3.5 more, why make it different?
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<8) | (unsigned char)hgetc(fd->fp);
	val = (val<<4) | (((unsigned char)hgetc(fd->fp)) & 0x0f);
	*val_p = val;
    }

    return 5;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rdi
callq 0x266a9
cmpl $-0x1, %eax
je 0x265b7
movl %eax, %ebp
sarl $0x4, %eax
movslq %eax, %rcx
leaq 0x1f187(%rip), %rax     # 0x45710
movl (%rax,%rcx,4), %eax
cmpq $0x4, %rax
ja 0x26697
leaq 0x1f1b3(%rip), %rdx     # 0x45750
andl (%rdx,%rcx,4), %ebp
leaq 0x1f0d9(%rip), %rcx     # 0x45680
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x1
jmp 0x26692
pushq $-0x1
jmp 0x26699
movq (%r14), %rdi
callq 0x266a9
shll $0x10, %ebp
shll $0x8, %eax
movzwl %ax, %r15d
orl %ebp, %r15d
movq (%r14), %rdi
callq 0x266a9
movl %eax, %ebp
movl $0xff, %r12d
andl %r12d, %ebp
orl %r15d, %ebp
movq (%r14), %rdi
callq 0x266a9
movl %eax, %r15d
shll $0xc, %ebp
andl %r12d, %r15d
shll $0x4, %r15d
orl %ebp, %r15d
movq (%r14), %rdi
callq 0x266a9
movl %eax, %ebp
andl $0xf, %ebp
orl %r15d, %ebp
pushq $0x5
jmp 0x26692
movq (%r14), %rdi
callq 0x266a9
shll $0x10, %ebp
shll $0x8, %eax
movzwl %ax, %r15d
orl %ebp, %r15d
movq (%r14), %rdi
callq 0x266a9
movzbl %al, %ebp
orl %r15d, %ebp
pushq $0x3
jmp 0x26692
movq (%r14), %rdi
callq 0x266a9
shll $0x10, %ebp
shll $0x8, %eax
movzwl %ax, %r12d
orl %ebp, %r12d
movq (%r14), %rdi
callq 0x266a9
movl %eax, %r15d
movl $0xff, %r13d
andl %r13d, %r15d
orl %r12d, %r15d
shll $0x8, %r15d
movq (%r14), %rdi
callq 0x266a9
movl %eax, %ebp
andl %r13d, %ebp
orl %r15d, %ebp
pushq $0x4
jmp 0x26692
shll $0x8, %ebp
movq (%r14), %rdi
callq 0x266a9
movzbl %al, %eax
orl %eax, %ebp
pushq $0x2
popq %rax
movl %ebp, (%rbx)
jmp 0x2669a
pushq $0x5
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq