// File: /workspace/github_c_makefile_star2_O2/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:
andl $0x0, (%rcx)
andq $0x0, (%rdx)
leal -0x1(%rsi), %eax
xorl %r9d, %r9d
cmpl $0x95, %eax
ja 0x42a70
movq %rdx, %r8
movslq %esi, %rsi
addq %rdi, %rsi
movzbl (%rdi), %eax
cmpl $0x2b, %eax
je 0x4295a
cmpl $0x2d, %eax
jne 0x4295d
movl $0x1, (%rcx)
incq %rdi
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
leaq 0x1(%rdi), %rax
cmpq %rsi, %rax
jae 0x429a1
movzbl (%rdi), %ecx
cmpl $0x30, %ecx
jne 0x42989
movb (%rax), %dl
xorl %ecx, %ecx
cmpb $0x78, %dl
jne 0x42996
addq $0x2, %rdi
movl $0x10, %ecx
jmp 0x429f1
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x429a1
movb (%rax), %dl
addl $-0x30, %ecx
cmpb $0x72, %dl
jne 0x429a1
addq $0x2, %rdi
jmp 0x429f1
leaq 0x2(%rdi), %rdx
movl $0xa, %ecx
cmpq %rsi, %rdx
jae 0x429f1
movzbl (%rdi), %r10d
leal -0x30(%r10), %r11d
cmpb $0x9, %r11b
ja 0x429f1
movzbl (%rax), %eax
leal -0x30(%rax), %r11d
cmpb $0x9, %r11b
ja 0x429f1
cmpb $0x72, (%rdx)
jne 0x429f1
imull $0xa, %r10d, %ecx
leal (%rcx,%rax), %edx
addl $0xfffffdcb, %edx       # imm = 0xFFFFFDCB
cmpl $-0x23, %edx
jb 0x42a6c
addl %eax, %ecx
addl $0xfffffdf0, %ecx       # imm = 0xFFFFFDF0
addq $0x3, %rdi
movb $0x1, %al
cmpq %rsi, %rdi
jae 0x42a04
cmpb $0x30, (%rdi)
jne 0x42a04
incq %rdi
xorl %eax, %eax
jmp 0x429f3
movl %ecx, %r11d
xorl %r10d, %r10d
leaq 0x23a8f(%rip), %rbx     # 0x664a0
cmpq %rsi, %rdi
jae 0x42a5a
movzbl (%rdi), %edx
cmpq $0x5f, %rdx
jne 0x42a25
testb $0x1, %al
je 0x42a53
jmp 0x42a5e
xorl %r9d, %r9d
testb %dl, %dl
js 0x42a6c
andl $0x7f, %edx
movzbl (%rdx,%rbx), %r14d
cmpl %r14d, %ecx
jle 0x42a6c
movq %r14, %rax
notq %rax
xorl %r9d, %r9d
xorl %edx, %edx
divq %r11
cmpq %rax, %r10
ja 0x42a6c
imulq %r11, %r10
addq %r14, %r10
incq %rdi
xorl %eax, %eax
jmp 0x42a11
testb $0x1, %al
je 0x42a63
xorl %r9d, %r9d
jmp 0x42a6c
movq %r10, (%r8)
movl $0x1, %r9d
popq %rbx
popq %r14
popq %rbp
movl %r9d, %eax
retq