// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x542e3
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %ebp
jmp 0x542ea
callq 0x6af26
movl %eax, %ebp
cmpl $-0x1, %ebp
je 0x54335
movb %bpl, 0x3(%rsp)
movl %ebp, %eax
sarl $0x4, %eax
movslq %eax, %rcx
leaq 0x4472d(%rip), %rax     # 0x98a30
movl (%rax,%rcx,4), %eax
cmpq $0x4, %rax
ja 0x543c0
leaq 0x44759(%rip), %rdx     # 0x98a70
andl (%rdx,%rcx,4), %ebp
leaq 0x44693(%rip), %rcx     # 0x989b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, %r15d
jmp 0x54545
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x54559
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x543cb
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x543d0
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x54472
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x54477
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x544bc
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x544c1
shll $0x8, %ebp
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x54531
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x54536
movl $0x5, %r15d
jmp 0x54559
callq 0x6af26
movb %al, 0x4(%rsp)
shll $0x10, %ebp
shll $0x8, %eax
movzwl %ax, %r12d
orl %ebp, %r12d
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x543fb
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x54400
callq 0x6af26
movb %al, 0x5(%rsp)
movzbl %al, %ebp
orl %r12d, %ebp
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x54424
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x54429
callq 0x6af26
movb %al, 0x6(%rsp)
shll $0xc, %ebp
movzbl %al, %r12d
shll $0x4, %r12d
orl %ebp, %r12d
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x54455
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %ebp
jmp 0x5445c
callq 0x6af26
movl %eax, %ebp
movb %bpl, 0x7(%rsp)
andl $0xf, %ebp
orl %r12d, %ebp
movl $0x5, %r15d
jmp 0x54545
callq 0x6af26
movb %al, 0x4(%rsp)
shll $0x10, %ebp
shll $0x8, %eax
movzwl %ax, %r12d
orl %ebp, %r12d
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x544a2
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x544a7
callq 0x6af26
movb %al, 0x5(%rsp)
movzbl %al, %ebp
orl %r12d, %ebp
movl $0x3, %r15d
jmp 0x54545
callq 0x6af26
movb %al, 0x4(%rsp)
shll $0x10, %ebp
shll $0x8, %eax
movzwl %ax, %r13d
orl %ebp, %r13d
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x544ec
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x544f1
callq 0x6af26
movb %al, 0x5(%rsp)
movzbl %al, %r12d
orl %r13d, %r12d
shll $0x8, %r12d
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x5451a
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x5451f
callq 0x6af26
movb %al, 0x6(%rsp)
movzbl %al, %ebp
orl %r12d, %ebp
movl $0x4, %r15d
jmp 0x54545
callq 0x6af26
movb %al, 0x4(%rsp)
movzbl %al, %eax
orl %eax, %ebp
movl $0x2, %r15d
movl %ebp, (%r14)
movl (%rbx), %edi
leaq 0x3(%rsp), %rsi
movl %r15d, %edx
callq 0x64b0
movl %eax, (%rbx)
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq