// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/strtod.c
// Function: janet_scan_number_base
int janet_scan_number_base(
    const uint8_t *str,
    int32_t len,
    int32_t base,
    double *out) {
    const uint8_t *end = str + len;
    int seenadigit = 0;
    int ex = 0;
    int seenpoint = 0;
    int foundexp = 0;
    int neg = 0;
    struct BigNat mant;
    bignat_zero(&mant);

    /* Prevent some kinds of overflow bugs relating to the exponent
     * overflowing.  For example, if a string was passed 2GB worth of 0s after
     * the decimal point, exponent could wrap around and become positive. It's
     * easier to reject ridiculously large inputs than to check for overflows.
     * */
    if (len > INT32_MAX / 40) goto error;

    /* Get sign */
    if (str >= end) goto error;
    if (*str == '-') {
        neg = 1;
        str++;
    } else if (*str == '+') {
        str++;
    }

    /* Check for leading 0x or digit digit r */
    if (base == 0) {
        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) goto error;
            str += 3;
        }
    }

    /* If still base is 0, set to default (10) */
    if (base == 0) {
        base = 10;
    }
    int exp_base = base;

    /* Skip leading zeros */
    while (str < end && (*str == '0' || *str == '.')) {
        if (seenpoint) ex--;
        if (*str == '.') {
            if (seenpoint) goto error;
            seenpoint = 1;
        } else {
            seenadigit = 1;
        }
        str++;
    }

    /* Parse significant digits */
    while (str < end) {
        if (*str == '.') {
            if (seenpoint) goto error;
            seenpoint = 1;
        } else if (*str == '&') {
            foundexp = 1;
            break;
        } else if (base == 16 && (*str == 'P' || *str == 'p')) { /* IEEE hex float */
            foundexp = 1;
            exp_base = 10;
            base = 2;
            ex *= 4; /* We need to correct the current exponent after we change the base */
            break;
        } else if (base == 10 && (*str == 'E' || *str == 'e')) {
            foundexp = 1;
            break;
        } else if (*str == '_') {
            if (!seenadigit) goto error;
        } else {
            int digit = digit_lookup[*str & 0x7F];
            if (*str > 127 || digit >= base) goto error;
            if (seenpoint) ex--;
            bignat_muladd(&mant, base, digit);
            seenadigit = 1;
        }
        str++;
    }

    if (!seenadigit)
        goto error;

    /* Read exponent */
    if (str < end && foundexp) {
        int eneg = 0;
        int32_t ee = 0;
        seenadigit = 0;
        str++;
        if (str >= end) goto error;
        if (*str == '-') {
            eneg = 1;
            str++;
        } else if (*str == '+') {
            str++;
        }
        /* Skip leading 0s in exponent */
        while (str < end && *str == '0') {
            str++;
            seenadigit = 1;
        }
        while (str < end) {
            int digit = digit_lookup[*str & 0x7F];
            if (*str > 127 || digit >= exp_base) goto error;
            if (ee < (INT32_MAX / 40)) {
                ee = exp_base * ee + digit;
            }
            str++;
            seenadigit = 1;
        }
        if (eneg) ex -= ee;
        else ex += ee;
    }

    if (!seenadigit)
        goto error;

    *out = convert(neg, &mant, base, ex);
    janet_free(mant.digits);
    return 0;

error:
    janet_free(mant.digits);
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorl %eax, %eax
movq %rax, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movq %rax, -0x40(%rbp)
leal -0x1(%rsi), %eax
cmpl $0x3333332, %eax        # imm = 0x3333332
ja 0x466e8
movq %rdi, %r13
movslq %esi, %rax
movzbl (%rdi), %esi
movb $0x1, %r10b
cmpl $0x2b, %esi
je 0x46466
movq %r13, %r15
cmpl $0x2d, %esi
jne 0x4646a
leaq 0x1(%r13), %r15
xorl %r10d, %r10d
jmp 0x4646a
leaq 0x1(%r13), %r15
addq %rax, %r13
testl %edx, %edx
je 0x46650
testl %edx, %edx
movl $0xa, %eax
cmovnel %edx, %eax
movl %eax, -0x2c(%rbp)
xorl %eax, %eax
cmpq %r13, %r15
jae 0x464e7
xorl %edx, %edx
movl $0x1, %r9d
xorl %ebx, %ebx
xorl %eax, %eax
movzbl (%r15), %esi
cmpl $0x30, %esi
je 0x464a7
cmpl $0x2e, %esi
jne 0x46713
testl %edx, %edx
sete %dil
cmpb $0x2e, %sil
setne %r8b
orb %dil, %r8b
cmpb $0x1, %r8b
jne 0x466e8
cmpb $0x2e, %sil
movl $0x1, %r14d
cmovnel %edx, %r14d
cmovnel %r9d, %eax
cmpl %r9d, %edx
adcl $-0x1, %ebx
incq %r15
movl %r14d, %edx
cmpq %r13, %r15
jb 0x46495
jmp 0x464ec
xorl %ebx, %ebx
xorl %r14d, %r14d
movl %r10d, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
cmpq %r13, %r15
setb %dl
jae 0x465df
leaq 0x24f99(%rip), %r8      # 0x6b4a0
movl -0x2c(%rbp), %esi
movq %r13, -0x58(%rbp)
movzbl (%r15), %ecx
cmpl $0x2e, %ecx
je 0x46556
cmpl $0x26, %ecx
je 0x465e2
cmpl $0xa, %esi
je 0x4653d
cmpl $0x10, %esi
jne 0x4656c
movl %ecx, %edi
orl $0x20, %edi
cmpl $0x70, %edi
je 0x4682e
cmpl $0xa, %esi
jne 0x4656c
cmpq $0x5f, %rcx
je 0x46571
cmpl $0x45, %ecx
je 0x46840
cmpl $0x65, %ecx
jne 0x46585
jmp 0x46840
movl $0x1, %r12d
testl %r14d, %r14d
movl $0x1, %r14d
je 0x465ce
jmp 0x466ee
cmpl $0x5f, %ecx
jne 0x46585
movl $0x1, %r12d
testl %eax, %eax
movl $0x1, %eax
jne 0x465ce
jmp 0x466ee
movl %ecx, %edx
andl $0x7f, %edx
movzbl (%rdx,%r8), %edx
testb %cl, %cl
setns %cl
cmpl %edx, %esi
setg %r12b
andb %cl, %r12b
cmpb $0x1, %r12b
jne 0x465c5
cmpl $0x1, %r14d
adcl $-0x1, %ebx
leaq -0x50(%rbp), %rdi
movq %r8, %r13
callq 0x46a12
movq %r13, %r8
movq -0x58(%rbp), %r13
movl -0x2c(%rbp), %esi
movl $0x1, %eax
testb %r12b, %r12b
je 0x466e8
incq %r15
cmpq %r13, %r15
setb %dl
jb 0x4650e
jmp 0x465e2
movl -0x2c(%rbp), %esi
movl %esi, %ecx
movl $0x1, %r12d
testl %eax, %eax
je 0x466ee
testb $0x1, %dl
je 0x46675
leaq 0x1(%r15), %r14
cmpq %r13, %r14
jae 0x46709
movb 0x1(%r15), %dl
addq $0x2, %r15
leal -0x2b(%rdx), %eax
testb $-0x3, %al
cmoveq %r15, %r14
xorl %edi, %edi
cmpq %r13, %r14
jae 0x4671b
cmpb $0x30, (%r14)
jne 0x4671b
incq %r14
movq %r14, %r8
movl $0x1, %eax
movq %r8, %r14
cmpq %r13, %r8
jae 0x4671d
leaq 0x1(%r14), %r8
cmpb $0x30, (%r14)
je 0x46635
jmp 0x4671d
leaq 0x1(%r15), %rax
cmpq %r13, %rax
jae 0x46699
movzbl (%r15), %edx
cmpl $0x30, %edx
jne 0x4667f
cmpb $0x78, (%rax)
jne 0x4667f
addq $0x2, %r15
movl $0x10, %edx
jmp 0x46475
movl $0x1, %eax
jmp 0x4679d
leal -0x30(%rdx), %esi
cmpb $0x9, %sil
ja 0x46699
cmpb $0x72, (%rax)
jne 0x46699
addl $-0x30, %edx
addq $0x2, %r15
jmp 0x46475
leaq 0x2(%r15), %r8
xorl %edx, %edx
cmpq %r13, %r8
jae 0x46475
movzbl (%r15), %esi
leal -0x30(%rsi), %edi
cmpb $0x9, %dil
ja 0x46475
movzbl (%rax), %eax
leal -0x30(%rax), %edi
cmpb $0x9, %dil
ja 0x46475
cmpb $0x72, (%r8)
jne 0x46475
leal (%rsi,%rsi,4), %esi
leal (%rax,%rsi,2), %edx
addl $0xfffffdcb, %edx       # imm = 0xFFFFFDCB
cmpl $-0x23, %edx
jae 0x46987
movl $0x1, %r12d
movq -0x40(%rbp), %rdi
callq 0x120b0
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, %r9d
xorl %eax, %eax
jmp 0x4678a
movl %edx, %r14d
jmp 0x464ec
xorl %eax, %eax
leaq 0x24d7c(%rip), %r8      # 0x6b4a0
cmpq %r13, %r14
jae 0x46779
movzbl (%r14), %r9d
movl %r9d, %r10d
andl $0x7f, %r10d
movzbl (%r10,%r8), %r11d
testb %r9b, %r9b
setns %r9b
cmpl %r11d, %ecx
setg %r10b
andb %r9b, %r10b
movl $0x2, %r9d
cmpb $0x1, %r10b
jne 0x46772
movl %edi, %eax
imull %ecx, %eax
addl %r11d, %eax
cmpl $0x3333333, %edi        # imm = 0x3333333
cmovll %eax, %edi
incq %r14
xorl %r9d, %r9d
movl $0x1, %eax
testb %r10b, %r10b
jne 0x46724
jmp 0x4678a
movl %edi, %ecx
negl %ecx
cmpb $0x2d, %dl
cmovnel %edi, %ecx
addl %ebx, %ecx
xorl %r9d, %r9d
movl %ecx, %ebx
cmpl $0x2, %r9d
je 0x466ee
testl %r9d, %r9d
jne 0x466f7
testl %eax, %eax
je 0x466ee
movslq -0x4c(%rbp), %r14
movl %esi, -0x2c(%rbp)
cvtsi2sd %esi, %xmm0
callq 0x120e0
cvtsi2sd %ebx, %xmm1
mulsd %xmm1, %xmm0
callq 0x12a00
movl -0x50(%rbp), %eax
orl %r14d, %eax
jne 0x467e9
xorpd %xmm0, %xmm0
cmpb $0x0, -0x30(%rbp)
movq -0x38(%rbp), %r14
jne 0x46a05
movsd 0x24cac(%rip), %xmm0    # 0x6b490
jmp 0x46a05
shlq $0x5, %r14
cvttsd2si %xmm0, %rax
addq %r14, %rax
addq $0x10, %rax
cmpq $0x499, %rax            # imm = 0x499
movq -0x38(%rbp), %r14
movl -0x30(%rbp), %ecx
jl 0x46819
testb %cl, %cl
jne 0x4684f
movsd 0x1a854(%rip), %xmm0    # 0x61068
jmp 0x46a05
cmpq $-0x497, %rax           # imm = 0xFB69
jge 0x4685c
xorpd %xmm0, %xmm0
testb %cl, %cl
je 0x467dc
jmp 0x46a05
shll $0x2, %ebx
movl $0xa, %ecx
movl $0x2, %esi
jmp 0x465e4
movl $0xa, %esi
movl $0xa, %ecx
jmp 0x465e4
movsd 0x13749(%rip), %xmm0    # 0x59fa0
jmp 0x46a05
cmpl $0x4, %ebx
jl 0x4688c
movl -0x2c(%rbp), %r15d
imull %r15d, %r15d
imull %r15d, %r15d
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x46a12
leal -0x4(%rbx), %r14d
cmpl $0x7, %ebx
movl %r14d, %ebx
jg 0x46871
jmp 0x4688f
movl %ebx, %r14d
cmpl $0x2, %r14d
jl 0x468bd
movl -0x2c(%rbp), %r15d
imull %r15d, %r15d
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x46a12
leal -0x2(%r14), %ebx
cmpl $0x3, %r14d
movl %ebx, %r14d
jg 0x468a1
jmp 0x468c0
movl %r14d, %ebx
testl %ebx, %ebx
jle 0x468d4
leaq -0x50(%rbp), %rdi
xorl %ebx, %ebx
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x46a12
xorl %r15d, %r15d
testl %ebx, %ebx
movq -0x38(%rbp), %r14
movl -0x30(%rbp), %r12d
jns 0x469ec
leal 0x3(%rbx), %r14d
testl %ebx, %ebx
cmovnsl %ebx, %r14d
sarl $0x2, %r14d
movl $0x5, %r15d
subl %r14d, %r15d
negl %r14d
leaq -0x50(%rbp), %rdi
movslq 0x4(%rdi), %r13
movl %r15d, %esi
callq 0x46e0f
leaq -0x50(%rbp), %rax
movq 0x10(%rax), %r12
leaq (%r12,%r14,4), %rdi
addq $0x14, %rdi
movq %rdi, -0x58(%rbp)
shlq $0x2, %r13
movq %r12, %rsi
movq %r13, %rdx
callq 0x12930
leaq 0x10(,%r14,4), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x12410
leaq -0x50(%rbp), %rcx
movl (%rcx), %eax
movq -0x58(%rbp), %rdx
movl %eax, -0x4(%rdx)
movl $0x0, (%rcx)
cmpl $-0x4, %ebx
jg 0x46999
movl -0x2c(%rbp), %r12d
imull %r12d, %r12d
imull %r12d, %r12d
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movl %r12d, %esi
callq 0x46e6e
leal 0x4(%rbx), %r14d
cmpl $-0x7, %ebx
movl %r14d, %ebx
jl 0x4696e
jmp 0x4699c
leal (%rax,%rsi,2), %edx
addl $0xfffffdf0, %edx       # imm = 0xFFFFFDF0
addq $0x3, %r15
jmp 0x46475
movl %ebx, %r14d
movl %r15d, %ebx
shll $0x5, %ebx
cmpl $-0x2, %r14d
jg 0x469ce
movl -0x2c(%rbp), %r12d
imull %r12d, %r12d
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movl %r12d, %esi
callq 0x46e6e
leal 0x2(%r14), %eax
cmpl $-0x3, %r14d
movl %eax, %r14d
jl 0x469b4
jmp 0x469d1
movl %r14d, %eax
subl %ebx, %r15d
testl %eax, %eax
jns 0x469e4
leaq -0x50(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x46e6e
movq -0x38(%rbp), %r14
movl -0x30(%rbp), %r12d
leaq -0x50(%rbp), %rdi
movl %r15d, %esi
callq 0x46ee4
testb %r12b, %r12b
jne 0x46a05
xorpd 0x24a7b(%rip), %xmm0    # 0x6b480
movsd %xmm0, (%r14)
xorl %r12d, %r12d
jmp 0x466ee