// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x7b845
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7bb0f
movb -0x2c(%rbp), %al
movb %al, -0x25(%rbp)
movl -0x2c(%rbp), %eax
sarl $0x4, %eax
movslq %eax, %rcx
leaq 0x8b885(%rip), %rax     # 0x1070e0
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %ecx
sarl $0x4, %ecx
movslq %ecx, %rdx
leaq 0x8b8ad(%rip), %rcx     # 0x107120
movl (%rcx,%rdx,4), %ecx
andl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0x38(%rbp)
subq $0x4, %rax
ja 0x7bb08
movq -0x38(%rbp), %rax
leaq 0x6705d(%rip), %rcx     # 0xe28f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
leaq -0x25(%rbp), %rsi
movl $0x1, %edx
callq 0x64a0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x7bb0f
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x3c(%rbp), %eax
movb %cl, -0x24(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
leaq -0x25(%rbp), %rsi
movl $0x2, %edx
callq 0x64a0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x2, -0x4(%rbp)
jmp 0x7bb0f
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x44(%rbp), %eax
movb %cl, -0x24(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x40(%rbp), %eax
movb %cl, -0x23(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
leaq -0x25(%rbp), %rsi
movl $0x3, %edx
callq 0x64a0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x3, -0x4(%rbp)
jmp 0x7bb0f
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x50(%rbp), %eax
movb %cl, -0x24(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x4c(%rbp), %eax
movb %cl, -0x23(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x48(%rbp), %eax
movb %cl, -0x22(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
leaq -0x25(%rbp), %rsi
movl $0x4, %edx
callq 0x64a0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x4, -0x4(%rbp)
jmp 0x7bb0f
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x60(%rbp), %eax
movb %cl, -0x24(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x5c(%rbp), %eax
movb %cl, -0x23(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x58(%rbp), %eax
movb %cl, -0x22(%rbp)
movzbl %cl, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x4, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7b7c0
movl %eax, %ecx
movl -0x54(%rbp), %eax
movb %cl, -0x21(%rbp)
movzbl %cl, %ecx
andl $0xf, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
leaq -0x25(%rbp), %rsi
movl $0x5, %edx
callq 0x64a0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x5, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)