// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movb -0x14(%rbp), %cl
decb %cl
movl $0x1, %eax
shlq %cl, %rax
decq %rax
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
imull $0x3e8, %eax, %edx      # imm = 0x3E8
movl %edx, %eax
addl $0xfffffc18, %eax       # imm = 0xFFFFFC18
movl %edx, %ecx
cltq
imulq $-0x622d4ffd, %rax, %rax # imm = 0x9DD2B003
shrq $0x20, %rax
movl %eax, %edx
movl %edx, %eax
leal -0x3e8(%rax,%rcx), %eax
movl %eax, %edx
sarl $0xb, %edx
shrl $0x1f, %eax
movl %eax, %ecx
movl %edx, %eax
leal 0x1(%rax,%rcx), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x30, -0x44(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x64(%rbp)
subl $0x2b, %eax
je 0x3a9b0
jmp 0x3a920
movl -0x64(%rbp), %eax
subl $0x2d, %eax
jne 0x3a9bc
jmp 0x3a92e
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x4c(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x34(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x65(%rbp)
je 0x3a981
movq -0x40(%rbp), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, -0x65(%rbp)
jl 0x3a981
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x39, %eax
setle %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
testb $0x1, %al
jne 0x3a98a
jmp 0x3a9ae
imulq $0xa, -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movzbl (%rcx), %ecx
addq %rcx, %rax
subq $0x30, %rax
movq %rax, -0x28(%rbp)
jmp 0x3a94d
jmp 0x3aa26
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x34(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x34(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x66(%rbp)
je 0x3a9f7
movq -0x40(%rbp), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, -0x66(%rbp)
jl 0x3a9f7
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x39, %eax
setle %al
movb %al, -0x66(%rbp)
movb -0x66(%rbp), %al
testb $0x1, %al
jne 0x3aa00
jmp 0x3aa24
imulq $0xa, -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movzbl (%rcx), %ecx
addq %rcx, %rax
subq $0x30, %rax
movq %rax, -0x28(%rbp)
jmp 0x3a9c3
jmp 0x3aa26
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x30, %eax
jl 0x3aae3
cmpl $0x0, -0x34(%rbp)
jne 0x3aae3
movq -0x30(%rbp), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
imulq $0xa, -0x58(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
subl $0x30, %eax
movl %eax, -0x48(%rbp)
cmpl $0xa, %eax
jae 0x3aae1
movq -0x28(%rbp), %rax
cmpq -0x58(%rbp), %rax
jb 0x3aa91
movq -0x28(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0x3aaae
movl -0x48(%rbp), %eax
cmpq -0x60(%rbp), %rax
ja 0x3aaae
imulq $0xa, -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3aadf
jmp 0x3aab0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
subl $0x30, %eax
cmpl $0xa, %eax
jb 0x3aab0
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3aae1
jmp 0x3aa62
jmp 0x3aae3
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x4c(%rbp)
je 0x3ab00
xorl %eax, %eax
subq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x3ab08
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
popq %rbp
retq
nop