// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/strtod.c
// Function: scan_uint64
static int scan_uint64(
    const uint8_t *str,
    int32_t len,
    uint64_t *out,
    int *neg) {
    const uint8_t *end = str + len;
    int seenadigit = 0;
    int base = 10;
    *neg = 0;
    *out = 0;
    uint64_t accum = 0;
    /* len max is INT64_MAX in base 2 with _ between each bits */
    /* '2r' + 64 bits + 63 _  + sign = 130 => 150 for some leading  */
    /* zeros */
    if (len > 150) return 0;
    /* Get sign */
    if (str >= end) return 0;
    if (*str == '-') {
        *neg = 1;
        str++;
    } else if (*str == '+') {
        str++;
    }
    /* Check for leading 0x or digit digit r */
    if (str + 1 < end && str[0] == '0' && str[1] == 'x') {
        base = 16;
        str += 2;
    } else if (str + 1 < end  &&
               str[0] >= '0' && str[0] <= '9' &&
               str[1] == 'r') {
        base = str[0] - '0';
        str += 2;
    } else if (str + 2 < end  &&
               str[0] >= '0' && str[0] <= '9' &&
               str[1] >= '0' && str[1] <= '9' &&
               str[2] == 'r') {
        base = 10 * (str[0] - '0') + (str[1] - '0');
        if (base < 2 || base > 36) return 0;
        str += 3;
    }

    /* Skip leading zeros */
    while (str < end && *str == '0') {
        seenadigit = 1;
        str++;
    }
    /* Parse significant digits */
    while (str < end) {
        if (*str == '_') {
            if (!seenadigit) return 0;
        } else {
            int digit = digit_lookup[*str & 0x7F];
            if (*str > 127 || digit >= base) return 0;
            if (accum > (UINT64_MAX - digit) / base) return 0;
            accum = accum * base + digit;
            seenadigit = 1;
        }
        str++;
    }

    if (!seenadigit) return 0;
    *out = accum;
    return 1;
}

// Assembly:
movl $0x0, (%rcx)
movq $0x0, (%rdx)
leal -0x1(%rsi), %eax
xorl %r9d, %r9d
cmpl $0x95, %eax
ja 0x46ca6
movq %rdx, %r8
movslq %esi, %rsi
addq %rdi, %rsi
movzbl (%rdi), %eax
cmpl $0x2b, %eax
je 0x46b52
cmpl $0x2d, %eax
jne 0x46b55
movl $0x1, (%rcx)
incq %rdi
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
leaq 0x1(%rdi), %rax
cmpq %rsi, %rax
jae 0x46b97
movzbl (%rdi), %ecx
cmpl $0x30, %ecx
jne 0x46b81
cmpb $0x78, (%rax)
jne 0x46b81
addq $0x2, %rdi
movl $0x10, %ecx
jmp 0x46be8
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x46b97
cmpb $0x72, (%rax)
jne 0x46b97
addl $-0x30, %ecx
addq $0x2, %rdi
jmp 0x46be8
leaq 0x2(%rdi), %rdx
movl $0xa, %ecx
cmpq %rsi, %rdx
jae 0x46be8
movzbl (%rdi), %r10d
leal -0x30(%r10), %r11d
cmpb $0x9, %r11b
ja 0x46be8
movzbl (%rax), %eax
leal -0x30(%rax), %r11d
cmpb $0x9, %r11b
ja 0x46be8
cmpb $0x72, (%rdx)
jne 0x46be8
leal (%r10,%r10,4), %ecx
leal (%rax,%rcx,2), %edx
addl $0xfffffdcb, %edx       # imm = 0xFFFFFDCB
cmpl $-0x23, %edx
jb 0x46c9e
leal (%rax,%rcx,2), %ecx
addl $0xfffffdf0, %ecx       # imm = 0xFFFFFDF0
addq $0x3, %rdi
xorl %r10d, %r10d
cmpq %rsi, %rdi
jae 0x46c12
cmpb $0x30, (%rdi)
jne 0x46c12
incq %rdi
movq %rdi, %rax
movl $0x1, %r10d
movq %rax, %rdi
cmpq %rsi, %rax
jae 0x46c12
leaq 0x1(%rdi), %rax
cmpb $0x30, (%rdi)
je 0x46c01
xorl %r11d, %r11d
cmpq %rsi, %rdi
jae 0x46c85
movl %ecx, %ebx
xorl %r11d, %r11d
leaq 0x2487a(%rip), %r14     # 0x6b4a0
xorl %r9d, %r9d
movzbl (%rdi), %eax
cmpq $0x5f, %rax
jne 0x46c3f
testl %r10d, %r10d
movl $0x1, %r10d
jne 0x46c7d
jmp 0x46c9b
testb %al, %al
js 0x46c75
andl $0x7f, %eax
movzbl (%rax,%r14), %r12d
cmpl %r12d, %ecx
jle 0x46c75
movq %r12, %rax
notq %rax
xorl %r15d, %r15d
xorl %edx, %edx
divq %rbx
cmpq %rax, %r11
ja 0x46c78
imulq %rbx, %r11
addq %r12, %r11
movb $0x1, %r15b
movl $0x1, %r10d
jmp 0x46c78
xorl %r15d, %r15d
testb %r15b, %r15b
je 0x46c9e
incq %rdi
cmpq %rsi, %rdi
jb 0x46c29
movl $0x0, %r9d
testl %r10d, %r10d
je 0x46c9e
movq %r11, (%r8)
movl $0x1, %r9d
jmp 0x46c9e
xorl %r9d, %r9d
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
movl %r9d, %eax
retq