// File: karel-brinda[P]ococo/ext/htslib/./cram/cram_io.h
// Function: safe_itf8_get
static inline int safe_itf8_get(const char *cp, const char *endp,
                                int32_t *val_p) {
    const unsigned char *up = (unsigned char *)cp;

    if (endp - cp < 5 &&
        (cp >= endp || endp - cp < itf8_bytes[up[0]>>4])) {
        *val_p = 0;
        return 0;
    }

    if (up[0] < 0x80) {
        *val_p =   up[0];
        return 1;
    } else if (up[0] < 0xc0) {
        *val_p = ((up[0] <<8) |  up[1])                           & 0x3fff;
        return 2;
    } else if (up[0] < 0xe0) {
        *val_p = ((up[0]<<16) | (up[1]<< 8) |  up[2])             & 0x1fffff;
        return 3;
    } else if (up[0] < 0xf0) {
        *val_p = ((up[0]<<24) | (up[1]<<16) | (up[2]<<8) | up[3]) & 0x0fffffff;
        return 4;
    } else {
        *val_p = ((up[0] & 0x0f)<<28) | (up[1]<<20) | (up[2]<<12) | (up[3]<<4) | (up[4] & 0x0f);
        return 5;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
cmpq $0x5, %rax
jge 0x24601
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x245eb
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq -0x28(%rbp), %rcx
movzbl (%rcx), %ecx
sarl $0x4, %ecx
movslq %ecx, %rdx
leaq 0x585de(%rip), %rcx     # 0x7cbc0
movslq (%rcx,%rdx,4), %rcx
cmpq %rcx, %rax
jge 0x24601
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x24748
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x80, %eax
jge 0x24628
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x24748
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xc0, %eax
jge 0x24662
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
shll $0x8, %ecx
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
orl %eax, %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x2, -0x4(%rbp)
jmp 0x24748
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xe0, %eax
jge 0x246a9
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
shll $0x10, %ecx
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x8, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movzbl 0x2(%rax), %eax
orl %eax, %ecx
andl $0x1fffff, %ecx         # imm = 0x1FFFFF
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x3, -0x4(%rbp)
jmp 0x24748
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xf0, %eax
jge 0x246fa
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
shll $0x18, %ecx
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x10, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movzbl 0x2(%rax), %eax
shll $0x8, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movzbl 0x3(%rax), %eax
orl %eax, %ecx
andl $0xfffffff, %ecx        # imm = 0xFFFFFFF
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x4, -0x4(%rbp)
jmp 0x24748
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
andl $0xf, %ecx
shll $0x1c, %ecx
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x14, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movzbl 0x2(%rax), %eax
shll $0xc, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movzbl 0x3(%rax), %eax
shll $0x4, %eax
orl %eax, %ecx
movq -0x28(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0xf, %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x5, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)