// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x66810
cmpl $0x3333333, -0x14(%rbp) # imm = 0x3333333
jle 0x6631f
jmp 0x667f1
movq -0x10(%rbp), %rax
cmpq -0x28(%rbp), %rax
jb 0x6632e
jmp 0x667f1
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x6634f
movl $0x1, -0x3c(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x66369
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x66367
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x66369
cmpl $0x0, -0x18(%rbp)
jne 0x66490
movq -0x10(%rbp), %rax
addq $0x1, %rax
cmpq -0x28(%rbp), %rax
jae 0x663b2
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x30, %eax
jne 0x663b2
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x78, %eax
jne 0x663b2
movl $0x10, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rbp)
jmp 0x6648e
movq -0x10(%rbp), %rax
addq $0x1, %rax
cmpq -0x28(%rbp), %rax
jae 0x66403
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x30, %eax
jl 0x66403
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x39, %eax
jg 0x66403
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x72, %eax
jne 0x66403
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
subl $0x30, %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rbp)
jmp 0x6648c
movq -0x10(%rbp), %rax
addq $0x2, %rax
cmpq -0x28(%rbp), %rax
jae 0x6648a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x30, %eax
jl 0x6648a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x39, %eax
jg 0x6648a
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x30, %eax
jl 0x6648a
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x39, %eax
jg 0x6648a
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x72, %eax
jne 0x6648a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
subl $0x30, %eax
imull $0xa, %eax, %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
subl $0x30, %ecx
addl %ecx, %eax
movl %eax, -0x18(%rbp)
cmpl $0x2, -0x18(%rbp)
jl 0x66479
cmpl $0x24, -0x18(%rbp)
jle 0x6647e
jmp 0x667f1
movq -0x10(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x10(%rbp)
jmp 0x6648c
jmp 0x6648e
jmp 0x66490
cmpl $0x0, -0x18(%rbp)
jne 0x6649d
movl $0xa, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x6d(%rbp)
jae 0x664d9
movq -0x10(%rbp), %rax
movzbl (%rax), %ecx
movb $0x1, %al
cmpl $0x30, %ecx
movb %al, -0x6e(%rbp)
je 0x664d3
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2e, %eax
sete %al
movb %al, -0x6e(%rbp)
movb -0x6e(%rbp), %al
movb %al, -0x6d(%rbp)
movb -0x6d(%rbp), %al
testb $0x1, %al
jne 0x664e2
jmp 0x66529
cmpl $0x0, -0x34(%rbp)
je 0x664f1
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x66511
cmpl $0x0, -0x34(%rbp)
je 0x66508
jmp 0x667f1
movl $0x1, -0x34(%rbp)
jmp 0x66518
movl $0x1, -0x2c(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x664a3
jmp 0x6652b
movq -0x10(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6666a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x6655c
cmpl $0x0, -0x34(%rbp)
je 0x66550
jmp 0x667f1
movl $0x1, -0x34(%rbp)
jmp 0x66659
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x26, %eax
jne 0x66574
movl $0x1, -0x38(%rbp)
jmp 0x6666a
cmpl $0x10, -0x18(%rbp)
jne 0x665b5
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x50, %eax
je 0x66592
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x70, %eax
jne 0x665b5
movl $0x1, -0x38(%rbp)
movl $0xa, -0x5c(%rbp)
movl $0x2, -0x18(%rbp)
movl -0x30(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x30(%rbp)
jmp 0x6666a
cmpl $0xa, -0x18(%rbp)
jne 0x665df
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x45, %eax
je 0x665d3
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x65, %eax
jne 0x665df
movl $0x1, -0x38(%rbp)
jmp 0x6666a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x5f, %eax
jne 0x665f8
cmpl $0x0, -0x2c(%rbp)
jne 0x665f6
jmp 0x667f1
jmp 0x66651
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
andl $0x7f, %eax
movslq %eax, %rcx
leaq 0x4a624(%rip), %rax     # 0xb0c30
movzbl (%rax,%rcx), %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x7f, %eax
jg 0x66627
movl -0x60(%rbp), %eax
cmpl -0x18(%rbp), %eax
jl 0x6662c
jmp 0x667f1
cmpl $0x0, -0x34(%rbp)
je 0x6663b
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x18(%rbp), %esi
movl -0x60(%rbp), %edx
leaq -0x58(%rbp), %rdi
callq 0x66850
movl $0x1, -0x2c(%rbp)
jmp 0x66653
jmp 0x66655
jmp 0x66657
jmp 0x66659
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x6652b
cmpl $0x0, -0x2c(%rbp)
jne 0x66675
jmp 0x667f1
movq -0x10(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x667bd
cmpl $0x0, -0x38(%rbp)
je 0x667bd
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x28(%rbp), %rax
jb 0x666bd
jmp 0x667f1
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x666de
movl $0x1, -0x64(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x666f8
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x666f6
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x666f8
jmp 0x666fa
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x6f(%rbp)
jae 0x66719
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x30, %eax
sete %al
movb %al, -0x6f(%rbp)
movb -0x6f(%rbp), %al
testb $0x1, %al
jne 0x66722
jmp 0x66737
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl $0x1, -0x2c(%rbp)
jmp 0x666fa
jmp 0x66739
movq -0x10(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6679f
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
andl $0x7f, %eax
movslq %eax, %rcx
leaq 0x4a4d9(%rip), %rax     # 0xb0c30
movzbl (%rax,%rcx), %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x7f, %eax
jg 0x66772
movl -0x6c(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jl 0x66774
jmp 0x667f1
cmpl $0x3333333, -0x68(%rbp) # imm = 0x3333333
jge 0x6678a
movl -0x5c(%rbp), %eax
imull -0x68(%rbp), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl $0x1, -0x2c(%rbp)
jmp 0x66739
cmpl $0x0, -0x64(%rbp)
je 0x667b2
movl -0x68(%rbp), %ecx
movl -0x30(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x30(%rbp)
jmp 0x667bb
movl -0x68(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x667bd
cmpl $0x0, -0x2c(%rbp)
jne 0x667c5
jmp 0x667f1
movl -0x3c(%rbp), %edi
movl -0x18(%rbp), %edx
movl -0x30(%rbp), %ecx
leaq -0x58(%rbp), %rsi
callq 0x66920
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x48(%rbp), %rdi
callq 0x120b0
movl $0x0, -0x4(%rbp)
jmp 0x66801
movq -0x48(%rbp), %rdi
callq 0x120b0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)