// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rdi, %r12
movq (%rdi), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x4e311
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %r15d
jmp 0x4e319
callq 0xf054
movl %eax, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %r15d, %r15d
js 0x4e44e
movslq %r15d, %rax
movb %al, 0x7(%rsp)
cmpl $0x7f, %r15d
jg 0x4e34e
movq %rax, (%r13)
movl (%rbx), %edi
leaq 0x7(%rsp), %rsi
movl $0x1, %ebp
movl $0x1, %edx
jmp 0x4e447
cmpl $0xbf, %r15d
jg 0x4e379
movq (%r12), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x4e418
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
jmp 0x4e41d
cmpl $0xdf, %r15d
jg 0x4e45f
movq %r13, 0x10(%rsp)
movq (%r12), %r13
leaq 0x8(%rsp), %rdi
movq 0x8(%r13), %rsi
movq 0x10(%r13), %r14
subq %rsi, %r14
cmpq $0x2, %r14
movl $0x2, %r12d
cmovbq %r14, %r12
movq %r12, %rdx
callq 0x43c0
addq %r12, 0x8(%r13)
cmpq $0x1, %r14
ja 0x4e3de
testb $0x2, 0x30(%r13)
je 0x4e3de
movl $0x2, %edx
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
movq %r12, %rcx
callq 0xf2cd
movq %rax, %r12
cmpq $0x2, %r12
movq 0x10(%rsp), %rdx
jl 0x4e44e
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, (%rdx)
movl (%rbx), %edi
movl $0x3, %ebp
movl $0x3, %edx
jmp 0x4e447
callq 0xf054
testl %eax, %eax
js 0x4e44e
leaq 0x7(%rsp), %rsi
movb %al, 0x1(%rsi)
movzbl %al, %eax
andl $0x3f, %r15d
shll $0x8, %r15d
orl %eax, %r15d
movq %r15, (%r13)
movl (%rbx), %edi
movl $0x2, %ebp
movl $0x2, %edx
callq 0x4320
movl %eax, (%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0xef, %r15d
jg 0x4e510
movq %r13, 0x10(%rsp)
movq (%r12), %r13
leaq 0x8(%rsp), %rdi
movq 0x8(%r13), %rsi
movq 0x10(%r13), %r14
subq %rsi, %r14
cmpq $0x3, %r14
movl $0x3, %r12d
cmovbq %r14, %r12
movq %r12, %rdx
callq 0x43c0
addq %r12, 0x8(%r13)
cmpq $0x2, %r14
ja 0x4e4c4
testb $0x2, 0x30(%r13)
je 0x4e4c4
movl $0x3, %edx
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
movq %r12, %rcx
callq 0xf2cd
movq %rax, %r12
cmpq $0x3, %r12
movq 0x10(%rsp), %rdx
jl 0x4e44e
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, (%rdx)
movl (%rbx), %edi
movl $0x4, %ebp
movl $0x4, %edx
jmp 0x4e447
cmpl $0xf7, %r15d
jg 0x4e57f
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x4d96c
cmpq $0x4, %rax
jl 0x4e44e
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, (%r13)
movl (%rbx), %edi
movl $0x5, %ebp
movl $0x5, %edx
jmp 0x4e447
cmpl $0xfb, %r15d
jg 0x4e600
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
movl $0x5, %edx
callq 0x4d96c
cmpq $0x5, %rax
jl 0x4e44e
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, (%r13)
movl (%rbx), %edi
movl $0x6, %ebp
movl $0x6, %edx
jmp 0x4e447
cmpl $0xfd, %r15d
jg 0x4e68f
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
movl $0x6, %edx
callq 0x4d96c
cmpq $0x6, %rax
jl 0x4e44e
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, (%r13)
movl (%rbx), %edi
movl $0x7, %ebp
movl $0x7, %edx
jmp 0x4e447
movq (%r12), %rdi
leaq 0x8(%rsp), %rsi
cmpl $0xfe, %r15d
jne 0x4e70d
movl $0x7, %edx
callq 0x4d96c
cmpq $0x7, %rax
jl 0x4e44e
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, (%r13)
movl (%rbx), %edi
movl $0x8, %ebp
movl $0x8, %edx
jmp 0x4e447
movl $0x8, %edx
callq 0x4d96c
cmpq $0x8, %rax
jl 0x4e44e
leaq 0x7(%rsp), %rsi
movq 0x1(%rsi), %r14
bswapq %r14
movl (%rbx), %edi
movl $0x9, %ebp
movl $0x9, %edx
callq 0x4320
movl %eax, (%rbx)
movq %r14, (%r13)
jmp 0x4e44e