// File: /workspace/github_c_makefile_star2_O1/lengjingzju[P]json/jnum.c
// Function: jnum_parse_num
int jnum_parse_num(const char *str, jnum_type_t *type, jnum_value_t *value)
{
#define IS_DIGIT(c)     ((c) >= '0' && (c) <= '9')
    const char *s = str;
    int32_t eneg = 0, e = 0, k = 0, ek = 0, b = 0, i = 0, z = 0;
    uint64_t neg = 0, m = 0, n = 0;

    switch (*s) {
    case '-':
        neg = 1;
        FALLTHROUGH_ATTR;
    case '+':
        ++s;
        break;
    case '0':
        if ((*(s + 1) == 'x' || *(s + 1) == 'X')) {
            int len = jnum_parse_hex(s, type, value);
            if (len == 2) {
                *type = JNUM_INT;
                value->vint = 0;
                return 1;
            }
            return len;
        }
        break;
    default:
        break;
    }

    if (!IS_DIGIT(*s) && (*s != '.')) {
        *type = JNUM_NULL;
        value->vint = 0;
        return 0;
    }

    /* ---------- Parse integer ---------- */
    while (*s == '0')
        ++s;
    while (IS_DIGIT(*s)) {
        m = (m << 3) + (m << 1) + (*s++ - '0');
        ++k;
    }
    if (k >= 20) {
        goto overflow1;
    }

    if (*s != '.') {
        if (*s != 'e' && *s != 'E') {
            goto end1;
        }
    } else {
        /* ---------- Parse decimal ---------- */
        ++s;
        if (m == 0) {
            while (*s == '0') {
                ++s;
                --z;
            }
        } else {
            n = m;
            b = k;
        }

        while (IS_DIGIT(*s)) {
            m = (m << 3) + (m << 1) + (*s++ - '0');
            ++k;
            --i;
        }
        if (k >= 20) {
            goto overflow2;
        }

        if (*s != 'e' && *s != 'E') {
            goto end2;
        }
    }

end3:
    /* ---------- Parse Exponent ---------- */
    switch (*(s + 1)) {
    case '-':
        eneg = 1;
        FALLTHROUGH_ATTR;
    case '+':
        if (IS_DIGIT(*(s + 2))) {
            s += 2;
            break;
        }
        if (i)
            goto end2;
        else
            goto end1;
    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
        ++s;
        break;
    default:
        if (i)
            goto end2;
        else
            goto end1;
    }

    while (*s == '0')
        ++s;
    ek = 0;
    while (IS_DIGIT(*s)) {
        e = (e << 3) + (e << 1) + (*s++ - '0');
        ++ek;
        if (ek == 4)
            break;
    }
    while (IS_DIGIT(*s))
        ++s;
    i += eneg == 0 ? e : -e;

end2:
    *type = JNUM_DOUBLE;
    if (m == 0) {
        value->vlhex = neg << 63;
    } else {
        value->vdbl = ldouble_rconvert(m, i + z);
        value->vlhex |= neg << 63;
    }
    return (int)(s - str);

end1:
    if (m <= 2147483647U /*INT_MAX*/) {
        *type = JNUM_INT;
        value->vint = neg == 0 ? (int32_t)m : -((int32_t)m);
    } else if (m <= 9223372036854775807U /*LLONG_MAX*/) {
        *type = JNUM_LINT;
        value->vlint = neg == 0 ? (int64_t)m : -((int64_t)m);
    } else {
        if (m == 9223372036854775808U && neg == 1) {
            *type = JNUM_LINT;
#if defined(_MSC_VER)
            value->vlint = -9223372036854775807 - 1;
#else
            value->vlint = -m;
#endif
        } else {
            *type = JNUM_DOUBLE;
            value->vdbl = neg == 0 ? (double)m : -((double)m);
        }
    }
    return (int)(s - str);

overflow1:
    s -= k;
    m = 0;
    k = 0;
    while (IS_DIGIT(*s)) {
        m = (m << 3) + (m << 1) + (*s++ - '0');
        ++k;
        if (k == 19)
            break;
    }

    while (1) {
        switch (*s) {
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
            ++s;
            ++i;
            break;
        case '.':
            ++s;
            while (IS_DIGIT(*s))
                ++s;
            if (*s == 'e' || *s == 'E') {
                goto end3;
            }
            goto end2;
        case 'e': case 'E':
            goto end3;
        default:
            goto end2;
        }
    }

overflow2:
    s -= k - b;
    m = n;
    k = b;
    i = 0;

    while (IS_DIGIT(*s)) {
        m = (m << 3) + (m << 1) + (*s++ - '0');
        ++k;
        --i;
        if (k == 19)
            break;
    }
    while (IS_DIGIT(*s))
        ++s;

    if (*s == 'e' || *s == 'E') {
        goto end3;
    }
    goto end2;
}

// Assembly:
movq %rdx, %r8
movzbl (%rdi), %eax
xorl %r10d, %r10d
cmpl $0x2b, %eax
je 0x8ffa
cmpl $0x30, %eax
je 0x906f
movq %rdi, %r9
cmpl $0x2d, %eax
jne 0x8ffe
movl $0x1, %r10d
leaq 0x1(%rdi), %r9
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movb (%r9), %al
leal -0x30(%rax), %ecx
cmpb $0xa, %cl
setae %cl
cmpb $0x2e, %al
setne %al
testb %cl, %al
jne 0x9061
decq %r9
cmpb $0x30, 0x1(%r9)
leaq 0x1(%r9), %r9
je 0x901e
movb (%r9), %dl
leal -0x30(%rdx), %eax
cmpb $0x9, %al
ja 0x90e6
xorl %eax, %eax
xorl %r11d, %r11d
leaq (%rax,%rax,4), %rax
addb $-0x30, %dl
movzbl %dl, %ecx
leaq (%rcx,%rax,2), %rax
incl %r11d
movb 0x1(%r9), %dl
incq %r9
leal -0x30(%rdx), %ecx
cmpb $0xa, %cl
jb 0x903c
jmp 0x90eb
xorl %r9d, %r9d
movl %r9d, (%rsi)
movl %r9d, (%r8)
jmp 0x9483
movzbl 0x1(%rdi), %eax
orl $0x20, %eax
cmpl $0x78, %eax
jne 0x9392
movl $0x2, %r9d
xorl %eax, %eax
movabsq $0x7e0000007e03ff, %rcx # imm = 0x7E0000007E03FF
leaq 0x47d4(%rip), %rdx      # 0xd86c
movb (%rdi,%r9), %r10b
addb $-0x30, %r10b
cmpb $0x36, %r10b
ja 0x90cb
movzbl %r10b, %r10d
btq %r10, %rcx
jae 0x90cb
movsbq (%r10,%rdx), %r10
shlq $0x4, %rax
addq %r10, %rax
incq %r9
cmpq $0x12, %r9
jl 0x9098
movl $0x12, %r9d
movq %rax, %rcx
shrq $0x20, %rcx
je 0x939d
movl $0x5, (%rsi)
movq %rax, (%r8)
jmp 0x93a6
xorl %r11d, %r11d
xorl %eax, %eax
cmpl $0x13, %r11d
jbe 0x9120
movl %r11d, %eax
subq %rax, %r9
leaq 0x13(%r9), %r11
xorl %ecx, %ecx
xorl %eax, %eax
movb (%r9,%rcx), %dl
addb $-0x30, %dl
cmpb $0x9, %dl
ja 0x9153
leaq (%rax,%rax,4), %rax
movzbl %dl, %edx
leaq (%rdx,%rax,2), %rax
incq %rcx
cmpl $0x13, %ecx
jne 0x90ff
jmp 0x9159
xorl %ecx, %ecx
cmpb $0x65, %dl
je 0x91a6
movzbl %dl, %edx
cmpl $0x45, %edx
je 0x91a6
cmpl $0x2e, %edx
jne 0x93fc
incq %r9
xorl %ecx, %ecx
testq %rax, %rax
je 0x94a9
movl %r11d, %ebx
xorl %edx, %edx
movq %rax, %r14
jmp 0x9528
addq %rcx, %r9
movq %r9, %r11
xorl %ecx, %ecx
movzbl (%r11,%rcx), %edx
leal -0x30(%rdx), %r9d
cmpl $0xa, %r9d
jae 0x916f
incq %rcx
jmp 0x915b
cmpl $0x65, %edx
je 0x91aa
cmpl $0x45, %edx
je 0x91aa
addq %rcx, %r11
cmpl $0x2e, %edx
jne 0x93ea
movq %r11, %r9
movzbl 0x1(%r9), %edx
incq %r9
leal -0x30(%rdx), %r11d
cmpb $0xa, %r11b
jb 0x9188
orl $0x20, %edx
cmpl $0x65, %edx
jne 0x94f0
xorl %edx, %edx
jmp 0x91b2
addq %rcx, %r11
xorl %edx, %edx
movq %r11, %r9
movzbl 0x1(%r9), %ebx
movb $0x1, %r11b
leal -0x30(%rbx), %ebp
cmpl $0xa, %ebp
jae 0x93c8
incq %r9
movq %r9, %r14
leaq 0x4(%r9), %rbx
movq %rbx, %r9
cmpb $0x30, (%r14)
leaq 0x1(%r14), %r14
leaq 0x1(%rbx), %rbx
je 0x91d0
xorl %ebx, %ebx
movq $-0x1, %r15
movb (%r14,%r15), %bpl
addb $-0x30, %bpl
cmpb $0x9, %bpl
ja 0x920e
leal (%rbx,%rbx,4), %ebx
movzbl %bpl, %r12d
leal (%r12,%rbx,2), %ebx
incq %r15
cmpl $0x3, %r15d
jne 0x91ea
jmp 0x9214
addq %r15, %r14
movq %r14, %r9
decq %r9
movb 0x1(%r9), %bpl
incq %r9
addb $-0x30, %bpl
cmpb $0xa, %bpl
jb 0x9217
movl %ebx, %ebp
negl %ebp
testb %r11b, %r11b
cmovnel %ebx, %ebp
addl %ecx, %ebp
movl %ebp, %ecx
movl $0x6, (%rsi)
testq %rax, %rax
je 0x9386
addl %ecx, %edx
cmpl $-0x13, %edx
jl 0x92ad
testl %edx, %edx
js 0x941d
cmpl $0x13, %edx
jg 0x92ad
movq %rax, %xmm0
movq 0x181a(%rip), %xmm1     # 0xaa80
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x181e(%rip), %xmm2     # 0xaa90
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movl %edx, %eax
leaq 0x2bb5(%rip), %rcx      # 0xbe40
movq (%rcx,%rax,8), %xmm4
punpckldq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm0
unpckhpd %xmm4, %xmm0            # xmm0 = xmm0[1],xmm4[1]
addsd %xmm4, %xmm0
mulsd %xmm3, %xmm0
jmp 0x946c
pxor %xmm0, %xmm0
cmpl $0xfffffea9, %edx       # imm = 0xFFFFFEA9
jl 0x946c
movq 0x17fb(%rip), %xmm0     # 0xaac0
cmpl $0x134, %edx            # imm = 0x134
jg 0x946c
addl $0x158, %edx            # imm = 0x158
leaq 0x2c02(%rip), %rsi      # 0xbee0
leaq 0x406b(%rip), %rcx      # 0xd350
movswl (%rcx,%rdx,2), %r11d
bsrq %rax, %rcx
xorq $0x3f, %rcx
shlq %cl, %rax
mulq (%rsi,%rdx,8)
bsrq %rdx, %rsi
xorq $0x3f, %rsi
subl %esi, %r11d
subl %ecx, %r11d
leal 0x4b(%r11), %eax
movb $0xa, %cl
subb %sil, %cl
movzbl %cl, %ebx
movb $0xb, %cl
subb %sil, %cl
movq %rdx, %rsi
shrq %cl, %rsi
btq %rbx, %rdx
jae 0x934d
incq %rsi
addl $0x4c, %r11d
movabsq $0xfffffffffffff, %rcx  # imm = 0xFFFFFFFFFFFFF
incq %rcx
movabsq $0x20000000000000, %rdx # imm = 0x20000000000000
cmpq %rdx, %rsi
cmovel %r11d, %eax
cmoveq %rcx, %rsi
cmpl $0xfffffbcf, %eax       # imm = 0xFFFFFBCF
jl 0x94c2
cmpl $0x3cb, %eax            # imm = 0x3CB
jg 0x946c
addl $0x433, %eax            # imm = 0x433
movabsq $0xfffffffffffff, %rcx  # imm = 0xFFFFFFFFFFFFF
andq %rcx, %rsi
shlq $0x34, %rax
orq %rsi, %rax
movq %rax, %xmm0
jmp 0x946c
shlq $0x3f, %r10
movq %r10, %rax
jmp 0x947d
xorl %r10d, %r10d
movq %rdi, %r9
jmp 0x8ffe
movl $0x3, (%rsi)
movl %eax, (%r8)
cmpl $0x2, %r9d
jne 0x948b
movl $0x2, (%rsi)
movl $0x0, (%r8)
movl $0x1, %r9d
jmp 0x948b
cmpl $0x2b, %ebx
je 0x93d5
cmpl $0x2d, %ebx
jne 0x93f4
xorl %r11d, %r11d
movb 0x2(%r9), %bl
addb $-0x30, %bl
cmpb $0xa, %bl
jae 0x93f4
addq $0x2, %r9
jmp 0x91c9
xorl %edx, %edx
movq %r11, %r9
jmp 0x9236
testl %ecx, %ecx
jne 0x9236
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
ja 0x948f
movl $0x2, (%rsi)
movl %eax, %ecx
negl %ecx
testq %r10, %r10
cmovel %eax, %ecx
movl %ecx, (%r8)
jmp 0x9480
movq %rax, %xmm1
movq 0x1656(%rip), %xmm2     # 0xaa80
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x165a(%rip), %xmm3     # 0xaa90
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
negl %edx
leaq 0x29f1(%rip), %rax      # 0xbe40
movq (%rax,%rdx,8), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq %xmm0, (%r8)
shlq $0x3f, %r10
movq %xmm0, %rax
orq %r10, %rax
movq %rax, (%r8)
subl %edi, %r9d
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
movl %r9d, %eax
retq
testq %rax, %rax
js 0x94f7
movl $0x4, (%rsi)
movq %rax, %rcx
negq %rcx
testq %r10, %r10
cmoveq %rax, %rcx
jmp 0x9519
cmpb $0x30, (%r9)
jne 0x9521
xorl %ebx, %ebx
xorl %edx, %edx
decl %edx
cmpb $0x30, 0x1(%r9)
leaq 0x1(%r9), %r9
je 0x94b3
jmp 0x9525
pxor %xmm0, %xmm0
cmpl $0xfffffb9a, %eax       # imm = 0xFFFFFB9A
jl 0x946c
movb $-0x32, %cl
subb %al, %cl
movq %rsi, %rdx
shrq %cl, %rdx
movl $0xfffffbcd, %ecx       # imm = 0xFFFFFBCD
subl %eax, %ecx
btq %rcx, %rsi
adcq $0x0, %rdx
movq %rdx, %xmm0
jmp 0x946c
xorl %edx, %edx
jmp 0x9236
testq %r10, %r10
je 0x95ce
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
cmpq %rcx, %rax
jne 0x95ce
movl $0x4, (%rsi)
movq %rcx, (%r8)
jmp 0x9480
xorl %ebx, %ebx
xorl %edx, %edx
xorl %r14d, %r14d
movb (%r9), %r15b
leal -0x30(%r15), %ebp
cmpb $0x9, %bpl
ja 0x955d
xorl %ecx, %ecx
leaq (%rax,%rax,4), %rax
addb $-0x30, %r15b
movzbl %r15b, %r15d
leaq (%r15,%rax,2), %rax
decl %ecx
movb 0x1(%r9), %r15b
incq %r9
leal -0x30(%r15), %ebp
cmpb $0xa, %bpl
jb 0x9537
subl %ecx, %r11d
cmpl $0x13, %r11d
jbe 0x95b7
subl %ebx, %r11d
subq %r11, %r9
addl $-0x13, %ebx
xorl %ecx, %ecx
movb (%r9), %al
addb $-0x30, %al
cmpb $0x9, %al
ja 0x958d
leaq (%r14,%r14,4), %r11
incq %r9
movzbl %al, %eax
leaq (%rax,%r11,2), %r14
decl %ecx
cmpl %ecx, %ebx
jne 0x956e
movl %ebx, %ecx
movq %r14, %rax
decq %r9
movzbl 0x1(%r9), %r11d
incq %r9
leal -0x30(%r11), %ebx
cmpb $0xa, %bl
jb 0x9593
orl $0x20, %r11d
cmpl $0x65, %r11d
je 0x91b2
jmp 0x9236
movzbl %r15b, %r11d
orl $0x20, %r11d
cmpl $0x65, %r11d
je 0x91b2
jmp 0x9236
movl $0x6, (%rsi)
movq %rax, %xmm1
punpckldq 0x149f(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x14a7(%rip), %xmm1     # 0xaa90
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
testq %r10, %r10
je 0x9602
xorpd 0x149e(%rip), %xmm0     # 0xaaa0
movsd %xmm0, (%r8)
jmp 0x9480