// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_io.c
// Function: ltf8_decode_crc
int ltf8_decode_crc(cram_fd *fd, int64_t *val_p, uint32_t *crc) {
    unsigned char c[9];
    int64_t val = hgetc(fd->fp);
    if (val < 0)
        return -1;

    c[0] = val;

    if (val < 0x80) {
        *val_p =   val;
        *crc = crc32(*crc, c, 1);
        return 1;

    } else if (val < 0xc0) {
        int v = hgetc(fd->fp);
        if (v < 0)
            return -1;
        val = (val<<8) | (c[1]=v);
        *val_p = val & (((1LL<<(6+8)))-1);
        *crc = crc32(*crc, c, 2);
        return 2;

    } else if (val < 0xe0) {
        if (hread(fd->fp, &c[1], 2) < 2)
            return -1;
        val = (val<<8) | c[1];
        val = (val<<8) | c[2];
        *val_p = val & ((1LL<<(5+2*8))-1);
        *crc = crc32(*crc, c, 3);
        return 3;

    } else if (val < 0xf0) {
        if (hread(fd->fp, &c[1], 3) < 3)
            return -1;
        val = (val<<8) | c[1];
        val = (val<<8) | c[2];
        val = (val<<8) | c[3];
        *val_p = val & ((1LL<<(4+3*8))-1);
        *crc = crc32(*crc, c, 4);
        return 4;

    } else if (val < 0xf8) {
        if (hread(fd->fp, &c[1], 4) < 4)
            return -1;
        val = (val<<8) | c[1];
        val = (val<<8) | c[2];
        val = (val<<8) | c[3];
        val = (val<<8) | c[4];
        *val_p = val & ((1LL<<(3+4*8))-1);
        *crc = crc32(*crc, c, 5);
        return 5;

    } else if (val < 0xfc) {
        if (hread(fd->fp, &c[1], 5) < 5)
            return -1;
        val = (val<<8) | c[1];
        val = (val<<8) | c[2];
        val = (val<<8) | c[3];
        val = (val<<8) | c[4];
        val = (val<<8) | c[5];
        *val_p = val & ((1LL<<(2+5*8))-1);
        *crc = crc32(*crc, c, 6);
        return 6;

    } else if (val < 0xfe) {
        if (hread(fd->fp, &c[1], 6) < 6)
            return -1;
        val = (val<<8) | c[1];
        val = (val<<8) | c[2];
        val = (val<<8) | c[3];
        val = (val<<8) | c[4];
        val = (val<<8) | c[5];
        val = (val<<8) | c[6];
        *val_p = val & ((1LL<<(1+6*8))-1);
        *crc = crc32(*crc, c, 7);
        return 7;

    } else if (val < 0xff) {
        uint64_t uval = val;
        if (hread(fd->fp, &c[1], 7) < 7)
            return -1;
        uval = (uval<<8) | c[1];
        uval = (uval<<8) | c[2];
        uval = (uval<<8) | c[3];
        uval = (uval<<8) | c[4];
        uval = (uval<<8) | c[5];
        uval = (uval<<8) | c[6];
        uval = (uval<<8) | c[7];
        *val_p = uval & ((1ULL<<(7*8))-1);
        *crc = crc32(*crc, c, 8);
        return 8;

    } else {
        uint64_t uval;
        if (hread(fd->fp, &c[1], 8) < 8)
            return -1;
        uval =             c[1];
        uval = (uval<<8) | c[2];
        uval = (uval<<8) | c[3];
        uval = (uval<<8) | c[4];
        uval = (uval<<8) | c[5];
        uval = (uval<<8) | c[6];
        uval = (uval<<8) | c[7];
        uval = (uval<<8) | c[8];
        *crc = crc32(*crc, c, 9);
        // Avoid implementation-defined behaviour on negative values
        *val_p = c[1] < 0x80 ? (int64_t) uval : -((int64_t) (0xffffffffffffffffULL - uval)) - 1;
    }

    return 9;
}

// 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
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x4bb55
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %r13d
movl %r13d, %eax
jmp 0x4bb65
callq 0xee9b
testl %eax, %eax
js 0x4bc81
movl %eax, %r13d
movb %al, 0xf(%rsp)
cmpl $0x7f, %eax
ja 0x4bb87
movq %r13, (%r14)
movl (%rbx), %edi
leaq 0xf(%rsp), %rsi
movl $0x1, %ebp
movl $0x1, %edx
jmp 0x4bc78
cmpl $0xbf, %eax
ja 0x4bbaf
movq (%r15), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x4bc4a
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x4bc53
cmpl $0xdf, %eax
ja 0x4bc97
movq (%r15), %r12
leaq 0x10(%rsp), %rdi
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rbp
subq %rsi, %rbp
cmpq $0x2, %rbp
movl $0x2, %r15d
cmovbq %rbp, %r15
movq %r15, %rdx
callq 0x43c0
addq %r15, 0x8(%r12)
cmpq $0x1, %rbp
ja 0x4bc10
testb $0x2, 0x30(%r12)
je 0x4bc10
movl $0x2, %edx
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %r15, %rcx
callq 0xf129
movq %rax, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x2, %r15
jl 0x4bc86
leaq 0xf(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x8, %eax
movzbl 0x2(%rsi), %ecx
andl $0x1f, %r13d
shll $0x10, %r13d
orl %eax, %r13d
orq %rcx, %r13
movq %r13, (%r14)
movl (%rbx), %edi
movl $0x3, %ebp
movl $0x3, %edx
jmp 0x4bc78
callq 0xee9b
testl %eax, %eax
js 0x4bc81
leaq 0xf(%rsp), %rsi
movb %al, 0x1(%rsi)
movzbl %al, %eax
andl $0x3f, %r13d
shll $0x8, %r13d
orl %eax, %r13d
movq %r13, (%r14)
movl (%rbx), %edi
movl $0x2, %ebp
movl $0x2, %edx
callq 0x4320
movl %eax, (%rbx)
jmp 0x4bc86
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xef, %eax
ja 0x4bd40
movq (%r15), %r12
leaq 0x10(%rsp), %rdi
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rbp
subq %rsi, %rbp
cmpq $0x3, %rbp
movl $0x3, %r15d
cmovbq %rbp, %r15
movq %r15, %rdx
callq 0x43c0
addq %r15, 0x8(%r12)
cmpq $0x2, %rbp
ja 0x4bcf8
testb $0x2, 0x30(%r12)
je 0x4bcf8
movl $0x3, %edx
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %r15, %rcx
callq 0xf129
movq %rax, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x3, %r15
jl 0x4bc86
leaq 0xf(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r13d
shll $0x8, %eax
orl %r13d, %eax
movzbl 0x2(%rsi), %ecx
orl %eax, %ecx
shll $0x8, %ecx
movzbl 0x3(%rsi), %eax
andl $0xfffff00, %ecx        # imm = 0xFFFFF00
orq %rax, %rcx
movq %rcx, (%r14)
movl (%rbx), %edi
movl $0x4, %ebp
movl $0x4, %edx
jmp 0x4bc78
cmpl $0xf7, %eax
ja 0x4bdb0
movq (%r15), %rdi
leaq 0x10(%rsp), %rsi
movl $0x4, %edx
callq 0x4b15c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x4, %rax
jl 0x4bc86
leaq 0xf(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r13d
shll $0x8, %eax
orl %r13d, %eax
movzbl 0x2(%rsi), %ecx
orl %eax, %ecx
movzbl 0x3(%rsi), %eax
shll $0x8, %eax
movzbl 0x4(%rsi), %edx
andl $0x7ffff, %ecx          # imm = 0x7FFFF
shlq $0x10, %rcx
orq %rax, %rcx
orq %rdx, %rcx
movq %rcx, (%r14)
movl (%rbx), %edi
movl $0x5, %ebp
movl $0x5, %edx
jmp 0x4bc78
cmpl $0xfb, %eax
ja 0x4be32
movq (%r15), %rdi
leaq 0x10(%rsp), %rsi
movl $0x5, %edx
callq 0x4b15c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x5, %rax
jl 0x4bc86
leaq 0xf(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r13d
shll $0x8, %eax
orl %r13d, %eax
movzbl 0x2(%rsi), %ecx
orl %eax, %ecx
movzbl 0x3(%rsi), %eax
shlq $0x10, %rcx
shll $0x8, %eax
orq %rcx, %rax
movzbl 0x4(%rsi), %ecx
orq %rax, %rcx
shlq $0x8, %rcx
movzbl 0x5(%rsi), %eax
movabsq $0x3ffffffff00, %rdx    # imm = 0x3FFFFFFFF00
andq %rcx, %rdx
orq %rax, %rdx
movq %rdx, (%r14)
movl (%rbx), %edi
movl $0x6, %ebp
movl $0x6, %edx
jmp 0x4bc78
cmpl $0xfd, %eax
ja 0x4bec2
movq (%r15), %rdi
leaq 0x10(%rsp), %rsi
movl $0x6, %edx
callq 0x4b15c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x6, %rax
jl 0x4bc86
leaq 0xf(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r13d
shll $0x8, %eax
orl %r13d, %eax
movzbl 0x2(%rsi), %ecx
orl %eax, %ecx
movzbl 0x3(%rsi), %eax
shlq $0x10, %rcx
shll $0x8, %eax
orq %rcx, %rax
movzbl 0x4(%rsi), %ecx
orq %rax, %rcx
movzbl 0x5(%rsi), %eax
shlq $0x10, %rcx
shll $0x8, %eax
movzbl 0x6(%rsi), %edx
movabsq $0x1ffffffff0000, %rdi  # imm = 0x1FFFFFFFF0000
andq %rcx, %rdi
orq %rax, %rdi
orq %rdx, %rdi
movq %rdi, (%r14)
movl (%rbx), %edi
movl $0x7, %ebp
movl $0x7, %edx
jmp 0x4bc78
movq (%r15), %rdi
leaq 0x10(%rsp), %rsi
cmpl $0xfe, %eax
jne 0x4bf41
movl $0x7, %edx
callq 0x4b15c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x7, %rax
jl 0x4bc86
leaq 0xf(%rsp), %rsi
movzbl 0x1(%rsi), %eax
movzbl 0x2(%rsi), %ecx
shll $0x10, %eax
shll $0x8, %ecx
orl %eax, %ecx
movzbl 0x3(%rsi), %eax
orl %ecx, %eax
movzbl 0x5(%rsi), %ecx
movzbl 0x6(%rsi), %edx
shlq $0x20, %rax
movzbl 0x4(%rsi), %edi
shll $0x18, %edi
shll $0x10, %ecx
orl %edi, %ecx
orq %rax, %rcx
shll $0x8, %edx
orq %rcx, %rdx
movzbl 0x7(%rsi), %eax
orq %rdx, %rax
movq %rax, (%r14)
movl (%rbx), %edi
movl $0x8, %ebp
movl $0x8, %edx
jmp 0x4bc78
movl $0x8, %edx
callq 0x4b15c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x8, %rax
jl 0x4bc86
leaq 0xf(%rsp), %rsi
movq 0x1(%rsi), %r15
bswapq %r15
movl (%rbx), %edi
movl $0x9, %ebp
movl $0x9, %edx
callq 0x4320
movl %eax, (%rbx)
movq %r15, (%r14)
jmp 0x4bc86