// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
movq (%rdi), %rdi
callq 0x3e519
pushq $-0x1
popq %rbp
testl %eax, %eax
js 0x3ef4e
movl %eax, %r15d
cltq
movb %al, 0x7(%rsp)
cmpl $0x7f, %r15d
ja 0x3eca0
movq %rax, (%r14)
movl (%rbx), %edi
leaq 0x7(%rsp), %rsi
pushq $0x1
jmp 0x3ef44
cmpl $0xbf, %r15d
ja 0x3ecdc
movq (%r12), %rdi
callq 0x3e519
testl %eax, %eax
js 0x3ef4e
leaq 0x7(%rsp), %rsi
movb %al, 0x1(%rsi)
movzbl %al, %eax
andl $0x3f, %r15d
shll $0x8, %r15d
orl %eax, %r15d
movq %r15, (%r14)
movl (%rbx), %edi
pushq $0x2
jmp 0x3ef44
cmpl $0xdf, %r15d
ja 0x3ed2a
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0x3e674
cmpq $0x2, %rax
jl 0x3ef4e
leaq 0x7(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x8, %eax
movzbl 0x2(%rsi), %ecx
andl $0x1f, %r15d
shll $0x10, %r15d
orl %eax, %r15d
orq %rcx, %r15
movq %r15, (%r14)
movl (%rbx), %edi
pushq $0x3
jmp 0x3ef44
cmpl $0xef, %r15d
ja 0x3ed83
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x3
popq %rdx
callq 0x3e674
cmpq $0x3, %rax
jl 0x3ef4e
leaq 0x7(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r15d
shll $0x8, %eax
orl %r15d, %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
pushq $0x4
jmp 0x3ef44
cmpl $0xf7, %r15d
ja 0x3ede7
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x3e674
cmpq $0x4, %rax
jl 0x3ef4e
leaq 0x7(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r15d
shll $0x8, %eax
orl %r15d, %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
pushq $0x5
jmp 0x3ef44
cmpl $0xfb, %r15d
ja 0x3ee5d
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x5
popq %rdx
callq 0x3e674
cmpq $0x5, %rax
jl 0x3ef4e
leaq 0x7(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r15d
shll $0x8, %eax
orl %r15d, %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
pushq $0x6
jmp 0x3ef44
cmpl $0xfd, %r15d
ja 0x3eeda
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x6
popq %rdx
callq 0x3e674
cmpq $0x6, %rax
jl 0x3ef4e
leaq 0x7(%rsp), %rsi
movzbl 0x1(%rsi), %eax
shll $0x10, %r15d
shll $0x8, %eax
orl %r15d, %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
pushq $0x7
jmp 0x3ef44
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
cmpl $0xfe, %r15d
jne 0x3ef5d
pushq $0x7
popq %rdx
callq 0x3e674
cmpq $0x7, %rax
jl 0x3ef4e
leaq 0x7(%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
pushq $0x8
popq %rbp
movl %ebp, %edx
callq 0x4320
movl %eax, (%rbx)
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x8
popq %rdx
callq 0x3e674
cmpq $0x8, %rax
jl 0x3ef4e
leaq 0x7(%rsp), %rsi
movq 0x1(%rsi), %r15
bswapq %r15
movl (%rbx), %edi
pushq $0x9
popq %rbp
movl %ebp, %edx
callq 0x4320
movl %eax, (%rbx)
movq %r15, (%r14)
jmp 0x3ef4e