// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_io.c
// Function: safe_ltf8_get
static int64_t safe_ltf8_get(char **cp, const char *endp, int *err) {
    unsigned char *up = (unsigned char *)*cp;

    if (endp && endp - *cp < 9 &&
        (*cp >= endp || endp - *cp < ltf8_bytes[up[0]])) {
        if (err) *err = 1;
        return 0;
    }

    if (up[0] < 0x80) {
        (*cp)++;
        return up[0];
    } else if (up[0] < 0xc0) {
        (*cp)+=2;
        return (((uint64_t)up[0]<< 8) |
                 (uint64_t)up[1]) & (((1LL<<(6+8)))-1);
    } else if (up[0] < 0xe0) {
        (*cp)+=3;
        return (((uint64_t)up[0]<<16) |
                ((uint64_t)up[1]<< 8) |
                 (uint64_t)up[2]) & ((1LL<<(5+2*8))-1);
    } else if (up[0] < 0xf0) {
        (*cp)+=4;
        return (((uint64_t)up[0]<<24) |
                ((uint64_t)up[1]<<16) |
                ((uint64_t)up[2]<< 8) |
                 (uint64_t)up[3]) & ((1LL<<(4+3*8))-1);
    } else if (up[0] < 0xf8) {
        (*cp)+=5;
        return (((uint64_t)up[0]<<32) |
                ((uint64_t)up[1]<<24) |
                ((uint64_t)up[2]<<16) |
                ((uint64_t)up[3]<< 8) |
                 (uint64_t)up[4]) & ((1LL<<(3+4*8))-1);
    } else if (up[0] < 0xfc) {
        (*cp)+=6;
        return (((uint64_t)up[0]<<40) |
                ((uint64_t)up[1]<<32) |
                ((uint64_t)up[2]<<24) |
                ((uint64_t)up[3]<<16) |
                ((uint64_t)up[4]<< 8) |
                 (uint64_t)up[5]) & ((1LL<<(2+5*8))-1);
    } else if (up[0] < 0xfe) {
        (*cp)+=7;
        return (((uint64_t)up[0]<<48) |
                ((uint64_t)up[1]<<40) |
                ((uint64_t)up[2]<<32) |
                ((uint64_t)up[3]<<24) |
                ((uint64_t)up[4]<<16) |
                ((uint64_t)up[5]<< 8) |
                 (uint64_t)up[6]) & ((1LL<<(1+6*8))-1);
    } else if (up[0] < 0xff) {
        (*cp)+=8;
        return (((uint64_t)up[1]<<48) |
                ((uint64_t)up[2]<<40) |
                ((uint64_t)up[3]<<32) |
                ((uint64_t)up[4]<<24) |
                ((uint64_t)up[5]<<16) |
                ((uint64_t)up[6]<< 8) |
                 (uint64_t)up[7]) & ((1LL<<(7*8))-1);
    } else {
        (*cp)+=9;
        return (((uint64_t)up[1]<<56) |
                ((uint64_t)up[2]<<48) |
                ((uint64_t)up[3]<<40) |
                ((uint64_t)up[4]<<32) |
                ((uint64_t)up[5]<<24) |
                ((uint64_t)up[6]<<16) |
                ((uint64_t)up[7]<< 8) |
                 (uint64_t)up[8]);
    }
}

// Assembly:
movq (%rdi), %rcx
testq %rsi, %rsi
je 0x5590c
movq %rsi, %rax
subq %rcx, %rax
cmpq $0x8, %rax
jg 0x5590c
cmpq %rsi, %rcx
jae 0x558fe
movzbl (%rcx), %esi
leaq 0x44c1b(%rip), %r8      # 0x9a510
movslq (%r8,%rsi,4), %rsi
cmpq %rsi, %rax
jge 0x5590c
testq %rdx, %rdx
je 0x55909
movl $0x1, (%rdx)
xorl %eax, %eax
retq
movb (%rcx), %al
testb %al, %al
js 0x5591d
leaq 0x1(%rcx), %rax
movq %rax, (%rdi)
movzbl (%rcx), %eax
retq
cmpb $-0x41, %al
ja 0x5593a
leaq 0x2(%rcx), %rax
movq %rax, (%rdi)
movzbl (%rcx), %eax
movzbl 0x1(%rcx), %ecx
andl $0x3f, %eax
shll $0x8, %eax
jmp 0x55a62
cmpb $-0x21, %al
ja 0x55960
leaq 0x3(%rcx), %rax
movq %rax, (%rdi)
movzbl (%rcx), %eax
movzbl 0x1(%rcx), %edx
shll $0x8, %edx
movzbl 0x2(%rcx), %ecx
andl $0x1f, %eax
shll $0x10, %eax
orl %edx, %eax
jmp 0x55a62
cmpb $-0x11, %al
ja 0x5598f
leaq 0x4(%rcx), %rax
movq %rax, (%rdi)
movzbl (%rcx), %eax
movzbl 0x1(%rcx), %edx
shll $0x10, %edx
movzbl 0x2(%rcx), %esi
shll $0x8, %esi
movzbl 0x3(%rcx), %ecx
andl $0xf, %eax
shll $0x18, %eax
orl %edx, %eax
orl %esi, %eax
jmp 0x55a62
cmpb $-0x9, %al
ja 0x559cb
leaq 0x5(%rcx), %rax
movq %rax, (%rdi)
movzbl (%rcx), %eax
movzbl 0x1(%rcx), %edx
shll $0x18, %edx
movzbl 0x2(%rcx), %esi
shll $0x10, %esi
movzbl 0x3(%rcx), %edi
shll $0x8, %edi
movzbl 0x4(%rcx), %ecx
andl $0x7, %eax
shlq $0x20, %rax
orq %rdx, %rax
orq %rsi, %rax
orq %rdi, %rax
jmp 0x55a62
cmpb $-0x5, %al
ja 0x55a11
leaq 0x6(%rcx), %rax
movq %rax, (%rdi)
movzbl (%rcx), %eax
movzbl 0x1(%rcx), %edx
shlq $0x20, %rdx
movzbl 0x2(%rcx), %esi
shll $0x18, %esi
movzbl 0x3(%rcx), %edi
shll $0x10, %edi
movzbl 0x4(%rcx), %r8d
shll $0x8, %r8d
movzbl 0x5(%rcx), %ecx
andl $0x3, %eax
shlq $0x28, %rax
orq %rdx, %rax
orq %rsi, %rax
orq %rdi, %rax
orq %r8, %rax
jmp 0x55a62
cmpb $-0x3, %al
ja 0x55a66
leaq 0x7(%rcx), %rax
movq %rax, (%rdi)
movzbl (%rcx), %eax
movzbl 0x1(%rcx), %edx
shlq $0x28, %rdx
movzbl 0x2(%rcx), %esi
shlq $0x20, %rsi
movzbl 0x3(%rcx), %edi
shll $0x18, %edi
movzbl 0x4(%rcx), %r8d
shll $0x10, %r8d
movzbl 0x5(%rcx), %r9d
shll $0x8, %r9d
movzbl 0x6(%rcx), %ecx
andl $0x1, %eax
shlq $0x30, %rax
orq %rdx, %rax
orq %rsi, %rax
orq %rdi, %rax
orq %r8, %rax
orq %r9, %rax
orq %rcx, %rax
retq
cmpb $-0x1, %al
je 0x55ab5
leaq 0x8(%rcx), %rax
movq %rax, (%rdi)
movzbl 0x1(%rcx), %eax
shlq $0x30, %rax
movzbl 0x2(%rcx), %edx
shlq $0x28, %rdx
orq %rax, %rdx
movzbl 0x3(%rcx), %eax
shlq $0x20, %rax
orq %rdx, %rax
movzbl 0x4(%rcx), %edx
shll $0x18, %edx
orq %rax, %rdx
movzbl 0x5(%rcx), %eax
shll $0x10, %eax
orq %rdx, %rax
movzbl 0x6(%rcx), %edx
shll $0x8, %edx
orq %rax, %rdx
movzbl 0x7(%rcx), %eax
orq %rdx, %rax
retq
leaq 0x9(%rcx), %rax
movq %rax, (%rdi)
movq 0x1(%rcx), %rax
bswapq %rax
retq