// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/./textutils_internal.h
// Function: hts_str2int
static inline int64_t hts_str2int(const char *in, char **end, int bits,
                                    int *failed) {
    uint64_t n = 0, limit = (1ULL << (bits - 1)) - 1;
    uint32_t fast = (bits - 1) * 1000 / 3322 + 1; // log(10)/log(2) ~= 3.322
    const unsigned char *v = (const unsigned char *) in;
    const unsigned int ascii_zero = '0'; // Prevents conversion to signed
    unsigned int d;

    int neg;
    switch(*v) {
    case '-':
        limit++;
        neg=1;
        v++;
        // See "dup" comment below
        while (--fast && *v>='0' && *v<='9')
            n = n*10 + *v++ - ascii_zero;
        break;

    case '+':
        v++;
        // fall through

    default:
        neg = 0;
        // dup of above.  This is somewhat unstable and mainly for code
        // size cheats to prevent instruction cache lines spanning 32-byte
        // blocks in the sam_parse_B_vals calling code.  It's been tested
        // on gcc7, gcc13, clang10 and clang16 with -O2 and -O3.  While
        // not exhaustive, this code duplication gives stable fast results
        // while a single copy does not.
        // (NB: system was "seq4d", so quite old)
        while (--fast && *v>='0' && *v<='9')
            n = n*10 + *v++ - ascii_zero;
        break;
    }

    // NB gcc7 is slow with (unsigned)(*v - ascii_zero) < 10,
    // while gcc13 prefers it.
    if (*v>='0' && !fast) { // rejects ',' and tab
        uint64_t limit_d_10 = limit / 10;
        uint64_t limit_m_10 = limit - 10 * limit_d_10;
        while ((d = *v - ascii_zero) < 10) {
            if (n < limit_d_10 || (n == limit_d_10 && d <= limit_m_10)) {
                n = n*10 + d;
                v++;
            } else {
                do { v++; } while (*v - ascii_zero < 10);
                n = limit;
                *failed = 1;
                break;
            }
        }
    }

    *end = (char *)v;

    return neg ? (int64_t)-n : (int64_t)n;
}

// Assembly:
pushq %rbx
movq %rcx, %r9
movl %edx, %ecx
decl %ecx
movl $0x1, %r8d
shlq %cl, %r8
imull $0x3e8, %ecx, %edx      # imm = 0x3E8
movl $0x9dd2b003, %eax       # imm = 0x9DD2B003
imulq %rdx, %rax
shrq $0x2b, %rax
movzbl (%rdi), %edx
cmpl $0x2b, %edx
je 0x28279
cmpl $0x2d, %edx
jne 0x2827c
leaq 0x1(%rdi), %r10
cmpl $0x4, %ecx
jae 0x282c4
xorl %edi, %edi
jmp 0x2828a
incq %rdi
movq %rdi, %r10
decq %r8
movb $0x1, %dil
cmpl $0x4, %ecx
jae 0x2828e
xorl %ecx, %ecx
jmp 0x282fb
leal -0x1(%rax), %ecx
leaq (%rcx,%r10), %rdx
incq %rdx
xorl %ecx, %ecx
movzbl (%r10), %r11d
leal -0x30(%r11), %ebx
cmpb $0xa, %bl
jae 0x282bc
leaq (%rcx,%rcx,4), %rcx
incq %r10
leaq (%r11,%rcx,2), %rcx
addq $-0x30, %rcx
decl %eax
jne 0x2829a
jmp 0x282f8
movq %r10, (%rsi)
jmp 0x2836a
leal -0x1(%rax), %ecx
leaq (%rdi,%rcx), %rdx
addq $0x2, %rdx
xorl %ecx, %ecx
movzbl (%r10), %edi
leal -0x30(%rdi), %r11d
cmpb $0xa, %r11b
jae 0x28396
leaq (%rcx,%rcx,4), %rcx
leaq (%rdi,%rcx,2), %rcx
addq $-0x30, %rcx
incq %r10
decl %eax
jne 0x282d1
xorl %edi, %edi
movq %rdx, %r10
movzbl (%r10), %r11d
cmpl $0x30, %r11d
jb 0x2835f
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
movq %r8, %rax
mulq %rdx
addl $-0x30, %r11d
cmpl $0x9, %r11d
ja 0x2835f
shrq $0x3, %rdx
leaq (%rdx,%rdx), %rax
leaq (%rax,%rax,4), %rbx
movq %r8, %rax
subq %rbx, %rax
cmpq %rdx, %rcx
jae 0x2833b
movl %r11d, %r11d
jmp 0x28345
jne 0x2836f
movl %r11d, %r11d
cmpq %r11, %rax
jb 0x2836f
leaq (%rcx,%rcx,4), %rcx
leaq (%r11,%rcx,2), %rcx
movzbl 0x1(%r10), %r11d
incq %r10
addl $-0x30, %r11d
cmpl $0xa, %r11d
jb 0x28331
movq %r10, (%rsi)
testb %dil, %dil
jne 0x2836a
negq %rcx
movq %rcx, %rax
popq %rbx
retq
movzbl 0x1(%r10), %eax
incq %r10
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x2836f
movl $0x1, (%r9)
movq %r10, (%rsi)
testb %dil, %dil
jne 0x28391
negq %r8
movq %r8, %rcx
jmp 0x2836a
movq %r10, (%rsi)
jmp 0x28367