// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/htslib/cram/cram_io.c
// Function: itf8_decode_crc
int itf8_decode_crc(cram_fd *fd, int32_t *val_p, uint32_t *crc) {
    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
    };
    unsigned char c[5];

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

    c[0]=val;

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

    switch(i) {
    case 0:
	*val_p = val;
	*crc = crc32(*crc, c, 1);
	return 1;

    case 1:
	val = (val<<8) | (c[1]=hgetc(fd->fp));
	*val_p = val;
	*crc = crc32(*crc, c, 2);
	return 2;

    case 2:
	val = (val<<8) | (c[1]=hgetc(fd->fp));
	val = (val<<8) | (c[2]=hgetc(fd->fp));
	*val_p = val;
	*crc = crc32(*crc, c, 3);
	return 3;

    case 3:
	val = (val<<8) | (c[1]=hgetc(fd->fp));
	val = (val<<8) | (c[2]=hgetc(fd->fp));
	val = (val<<8) | (c[3]=hgetc(fd->fp));
	*val_p = val;
	*crc = crc32(*crc, c, 4);
	return 4;

    case 4: // really 3.5 more, why make it different?
	val = (val<<8) |   (c[1]=hgetc(fd->fp));
	val = (val<<8) |   (c[2]=hgetc(fd->fp));
	val = (val<<8) |   (c[3]=hgetc(fd->fp));
	val = (val<<4) | (((c[4]=hgetc(fd->fp))) & 0x0f);
	*val_p = val;
	*crc = crc32(*crc, c, 5);
    }

    return 5;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rdi
callq 0x4c711
cmpl $-0x1, %eax
je 0x4c795
movb %al, 0xb(%rsp)
movl %eax, %ecx
sarl $0x4, %ecx
movslq %ecx, %rdx
leaq 0x3b2ee(%rip), %rcx     # 0x87a50
movl (%rcx,%rdx,4), %ecx
cmpq $0x4, %rcx
ja 0x4c8ae
leaq 0x3b31a(%rip), %rsi     # 0x87a90
movl (%rsi,%rdx,4), %r12d
andl %eax, %r12d
leaq 0x3b250(%rip), %rax     # 0x879d4
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $0x1
popq %rbp
jmp 0x4c899
pushq $-0x1
jmp 0x4c8b0
movq %r14, 0x10(%rsp)
leaq 0xf(%rsp), %r13
movq (%r15), %rdi
callq 0x4c711
movb %al, -0x3(%r13)
shll $0x10, %r12d
shll $0x8, %eax
movzwl %ax, %r14d
orl %r12d, %r14d
movq (%r15), %rdi
callq 0x4c711
movl %eax, %ebp
movb %bpl, -0x2(%r13)
movl $0xff, %r12d
andl %r12d, %ebp
orl %r14d, %ebp
movq (%r15), %rdi
callq 0x4c711
movl %eax, %r14d
movb %r14b, -0x1(%r13)
shll $0xc, %ebp
andl %r12d, %r14d
shll $0x4, %r14d
orl %ebp, %r14d
pushq $0x5
popq %rbp
pushq $0xf
popq %r12
jmp 0x4c882
movq %r14, 0x10(%rsp)
leaq 0xd(%rsp), %r13
movq (%r15), %rdi
callq 0x4c711
movb %al, -0x1(%r13)
shll $0x10, %r12d
shll $0x8, %eax
movzwl %ax, %r14d
orl %r12d, %r14d
pushq $0x3
jmp 0x4c87b
movq %r14, 0x10(%rsp)
leaq 0xe(%rsp), %r13
movq (%r15), %rdi
callq 0x4c711
movb %al, -0x2(%r13)
shll $0x10, %r12d
shll $0x8, %eax
movzwl %ax, %ebp
orl %r12d, %ebp
movq (%r15), %rdi
callq 0x4c711
movb %al, -0x1(%r13)
movzbl %al, %r14d
orl %ebp, %r14d
shll $0x8, %r14d
pushq $0x4
jmp 0x4c87b
movq %r14, 0x10(%rsp)
leaq 0xc(%rsp), %r13
movl %r12d, %r14d
shll $0x8, %r14d
pushq $0x2
popq %rbp
movl $0xff, %r12d
movq (%r15), %rdi
callq 0x4c711
movb %al, (%r13)
andl %eax, %r12d
orl %r14d, %r12d
movq 0x10(%rsp), %r14
movl %r12d, (%r14)
movl (%rbx), %edi
leaq 0xb(%rsp), %rsi
movl %ebp, %edx
callq 0x64b0
movl %eax, (%rbx)
jmp 0x4c8b1
pushq $0x5
popq %rbp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq