// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_lexer.c
// Function: lexNumber
static void lexNumber(Lexer *lex)
{
    lex->tok.kind = TOK_NONE;

    uint64_t whole = 0, frac = 0, expon = 0;
    bool isExpNegative = false, isReal = false;
    int base = 10, wholeLen = 0, fracLen = 0, exponLen = 0;

    if (lex->buf[lex->bufPos] == '0' && (lex->buf[lex->bufPos + 1] == 'x' || lex->buf[lex->bufPos + 1] == 'X'))
    {
        lexChar(lex);
        lexChar(lex);
        lexCharIf(lex, '_');
        base = 16;
    }

    if (lex->buf[lex->bufPos] == '.' && lexCharDigit(lex->buf[lex->bufPos + 1], 10) == -1)
        return;     // Single dot is not a number

    if (!(lex->buf[lex->bufPos] == '.' && base == 10))
        whole = lexDigitSeq(lex, base, &wholeLen, false);

    if (base == 10)
    {
        if (lexCharIf(lex, '.'))
        {
            isReal = true;

            if (lexCharDigit(lex->buf[lex->bufPos], 10) != -1)
                frac = lexDigitSeq(lex, 10, &fracLen, true);
        }

        if (lexCharIf(lex, 'e') || lexCharIf(lex, 'E'))
        {
            isReal = true;

            if (lexCharIf(lex, '-'))
                isExpNegative = true;
            else
                lexCharIf(lex, '+');

            expon = lexDigitSeq(lex, 10, &exponLen, false);
        }
    }

    if (isReal)
    {
        lex->tok.kind = TOK_REALNUMBER;
        lex->tok.realVal = whole;
        lex->tok.realVal += frac / pow(10, fracLen);

        if (isExpNegative)
            lex->tok.realVal /= pow(10, expon);
        else
            lex->tok.realVal *= pow(10, expon);

        if (lex->tok.realVal < -DBL_MAX || lex->tok.realVal > DBL_MAX)
            lex->error->handler(lex->error->context, "Number is too large");
    }
    else
    {
        lex->tok.kind = TOK_INTNUMBER;
        lex->tok.uintVal = whole;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0x28(%rax)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
movl $0xa, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jne 0x1b5cf
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x78, %eax
je 0x1b5a8
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x58, %eax
jne 0x1b5cf
movq -0x8(%rbp), %rdi
callq 0x1bff0
movq -0x8(%rbp), %rdi
callq 0x1bff0
movq -0x8(%rbp), %rdi
movl $0x5f, %esi
callq 0x1c180
movl $0x10, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x1b615
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl $0xa, %esi
movsbl (%rax,%rcx), %edi
callq 0x1c1d0
cmpl $-0x1, %eax
jne 0x1b615
jmp 0x1b8a6
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x1b634
cmpl $0xa, -0x28(%rbp)
je 0x1b64a
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
leaq -0x2c(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1c2c0
movq %rax, -0x10(%rbp)
cmpl $0xa, -0x28(%rbp)
jne 0x1b71a
movq -0x8(%rbp), %rdi
movl $0x2e, %esi
callq 0x1c180
cmpb $0x0, %al
je 0x1b6aa
movb $0x1, -0x22(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movl $0xa, %esi
movsbl (%rax,%rcx), %edi
callq 0x1c1d0
cmpl $-0x1, %eax
je 0x1b6a8
movq -0x8(%rbp), %rdi
movl $0xa, %esi
leaq -0x30(%rbp), %rdx
movl $0x1, %ecx
callq 0x1c2c0
movq %rax, -0x18(%rbp)
jmp 0x1b6aa
movq -0x8(%rbp), %rdi
movl $0x65, %esi
callq 0x1c180
movsbl %al, %eax
cmpl $0x0, %eax
jne 0x1b6d6
movq -0x8(%rbp), %rdi
movl $0x45, %esi
callq 0x1c180
movsbl %al, %eax
cmpl $0x0, %eax
je 0x1b718
movb $0x1, -0x22(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2d, %esi
callq 0x1c180
cmpb $0x0, %al
je 0x1b6f2
movb $0x1, -0x21(%rbp)
jmp 0x1b700
movq -0x8(%rbp), %rdi
movl $0x2b, %esi
callq 0x1c180
movq -0x8(%rbp), %rdi
movl $0xa, %esi
leaq -0x34(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1c2c0
movq %rax, -0x20(%rbp)
jmp 0x1b71a
testb $0x1, -0x22(%rbp)
je 0x1b88f
movq -0x8(%rbp), %rax
movl $0x47, 0x28(%rax)
movq -0x10(%rbp), %xmm0
movaps 0x1bc855(%rip), %xmm2   # 0x1d7f90
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x1bc859(%rip), %xmm1   # 0x1d7fa0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm3
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm3, %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x18(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
cvtsi2sdl -0x30(%rbp), %xmm1
movsd 0x1bdeb7(%rip), %xmm0   # 0x1d9640
callq 0x3100
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
divsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
testb $0x1, -0x21(%rbp)
je 0x1b7f9
movaps 0x1bc7db(%rip), %xmm0   # 0x1d7f90
movq -0x20(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x1bc7da(%rip), %xmm0   # 0x1d7fa0
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x1bde63(%rip), %xmm0   # 0x1d9640
callq 0x3100
movaps %xmm0, %xmm1
movq -0x8(%rbp), %rax
movsd 0x30(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0x1b83b
movaps 0x1bc790(%rip), %xmm0   # 0x1d7f90
movq -0x20(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x1bc78f(%rip), %xmm0   # 0x1d7fa0
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x1bde18(%rip), %xmm0   # 0x1d9640
callq 0x3100
movq -0x8(%rbp), %rax
mulsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
movq -0x8(%rbp), %rax
movsd 0x1bc769(%rip), %xmm0   # 0x1d7fb0
ucomisd 0x30(%rax), %xmm0
ja 0x1b865
movq -0x8(%rbp), %rax
movsd 0x30(%rax), %xmm0
movsd 0x1bc759(%rip), %xmm1   # 0x1d7fb8
ucomisd %xmm1, %xmm0
jbe 0x1b88d
movq -0x8(%rbp), %rax
movq 0x268(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x268(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x1bdf1c(%rip), %rsi    # 0x1d97a5
movb $0x0, %al
callq *%rcx
jmp 0x1b8a6
movq -0x8(%rbp), %rax
movl $0x46, 0x28(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)