// File: /workspace/github_c_makefile_star2_O3/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 0x46288
movq %rdx, %r8
movslq %esi, %rsi
addq %rdi, %rsi
movzbl (%rdi), %eax
cmpl $0x2b, %eax
je 0x46158
cmpl $0x2d, %eax
jne 0x4615b
movl $0x1, (%rcx)
incq %rdi
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
leaq 0x1(%rdi), %rax
cmpq %rsi, %rax
jae 0x4619f
movzbl (%rdi), %ecx
cmpl $0x30, %ecx
jne 0x46187
movb (%rax), %dl
xorl %ecx, %ecx
cmpb $0x78, %dl
jne 0x46194
addq $0x2, %rdi
movl $0x10, %ecx
jmp 0x461f0
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x4619f
movb (%rax), %dl
addl $-0x30, %ecx
cmpb $0x72, %dl
jne 0x4619f
addq $0x2, %rdi
jmp 0x461f0
leaq 0x2(%rdi), %rdx
movl $0xa, %ecx
cmpq %rsi, %rdx
jae 0x461f0
movzbl (%rdi), %r10d
leal -0x30(%r10), %r11d
cmpb $0x9, %r11b
ja 0x461f0
movzbl (%rax), %eax
leal -0x30(%rax), %r11d
cmpb $0x9, %r11b
ja 0x461f0
cmpb $0x72, (%rdx)
jne 0x461f0
leal (%r10,%r10,4), %ecx
leal (%rax,%rcx,2), %edx
addl $0xfffffdcb, %edx       # imm = 0xFFFFFDCB
cmpl $-0x23, %edx
jb 0x46284
leal (%rax,%rcx,2), %ecx
addl $0xfffffdf0, %ecx       # imm = 0xFFFFFDF0
addq $0x3, %rdi
movb $0x1, %al
cmpq %rsi, %rdi
jae 0x46216
cmpb $0x30, (%rdi)
setne %al
jne 0x46216
incq %rdi
movq %rdi, %rdx
movq %rdx, %rdi
cmpq %rsi, %rdx
jae 0x46216
leaq 0x1(%rdi), %rdx
cmpb $0x30, (%rdi)
je 0x46205
cmpq %rsi, %rdi
jae 0x46271
movl %ecx, %r11d
xorl %r10d, %r10d
leaq 0x24258(%rip), %rbx     # 0x6a480
movzbl (%rdi), %edx
cmpq $0x5f, %rdx
jne 0x46237
testb $0x1, %al
je 0x46265
jmp 0x4628c
xorl %r9d, %r9d
testb %dl, %dl
js 0x46284
andl $0x7f, %edx
movzbl (%rdx,%rbx), %r14d
cmpl %r14d, %ecx
jle 0x46284
movq %r14, %rax
notq %rax
xorl %r9d, %r9d
xorl %edx, %edx
divq %r11
cmpq %rax, %r10
ja 0x46284
imulq %r11, %r10
addq %r14, %r10
incq %rdi
xorl %eax, %eax
cmpq %rsi, %rdi
jb 0x46228
jmp 0x4627b
xorl %r9d, %r9d
testb %al, %al
jne 0x46284
xorl %r10d, %r10d
movq %r10, (%r8)
movl $0x1, %r9d
popq %rbx
popq %r14
popq %rbp
movl %r9d, %eax
retq
xorl %r9d, %r9d
jmp 0x46284