// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_lexer.c
// Function: lexKeywordOrIdent
static void lexKeywordOrIdent(Lexer *lex)
{
    lex->tok.kind = TOK_NONE;
    char ch = lex->buf[lex->bufPos];
    int len = 0;

    do
    {
        lex->tok.name[len++] = ch;
        ch = lexChar(lex);

        if (len > MAX_IDENT_LEN)
        {
            lex->error->handler(lex->error->context, "Identifier is too long");
            lex->tok.kind = TOK_NONE;
            return;
        }
    } while (((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') ||
              (ch >= '0' && ch <= '9') ||  ch == '_'));

    lex->tok.name[len] = 0;
    lex->tok.hash = hash(lex->tok.name);

    // Search for a keyword
    for (int i = 0; i < NUM_KEYWORDS; i++)
        if (lex->tok.hash == keywordHash[i] && strcmp(lex->tok.name, spelling[TOK_BREAK + i]) == 0)
        {
            lex->tok.kind = TOK_BREAK + i;
            break;
        }

    if (lex->tok.kind == TOK_NONE)
        lex->tok.kind = TOK_IDENT;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movb (%rax,%rcx), %al
movb %al, -0x9(%rbp)
movl $0x0, -0x10(%rbp)
movb -0x9(%rbp), %dl
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x10(%rbp)
movslq %ecx, %rcx
movb %dl, 0x30(%rax,%rcx)
movq -0x8(%rbp), %rdi
callq 0x1bff0
movb %al, -0x9(%rbp)
cmpl $0xff, -0x10(%rbp)
jle 0x1b3ea
movq -0x8(%rbp), %rax
movq 0x268(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x268(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x1be3b8(%rip), %rsi    # 0x1d978e
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movl $0x0, 0x28(%rax)
jmp 0x1b4f5
jmp 0x1b3ec
movsbl -0x9(%rbp), %eax
cmpl $0x41, %eax
jl 0x1b403
movsbl -0x9(%rbp), %ecx
movb $0x1, %al
cmpl $0x5a, %ecx
movb %al, -0x15(%rbp)
jle 0x1b43e
movsbl -0x9(%rbp), %eax
cmpl $0x61, %eax
jl 0x1b41a
movsbl -0x9(%rbp), %ecx
movb $0x1, %al
cmpl $0x7a, %ecx
movb %al, -0x15(%rbp)
jle 0x1b43e
movsbl -0x9(%rbp), %eax
cmpl $0x30, %eax
jl 0x1b431
movsbl -0x9(%rbp), %ecx
movb $0x1, %al
cmpl $0x39, %ecx
movb %al, -0x15(%rbp)
jle 0x1b43e
movsbl -0x9(%rbp), %eax
cmpl $0x5f, %eax
sete %al
movb %al, -0x15(%rbp)
movb -0x15(%rbp), %al
testb $0x1, %al
jne 0x1b384
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movb $0x0, 0x30(%rax,%rcx)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
addq $0x8, %rdi
callq 0x1ad00
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x130(%rax)
movl $0x0, -0x14(%rbp)
cmpl $0x15, -0x14(%rbp)
jge 0x1b4e0
movq -0x8(%rbp), %rax
movl 0x130(%rax), %eax
movslq -0x14(%rbp), %rdx
leaq 0x1cb40b(%rip), %rcx    # 0x1e68a0
cmpl (%rcx,%rdx,4), %eax
jne 0x1b4d3
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
addq $0x8, %rdi
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x1cad8a(%rip), %rax    # 0x1e6240
movq (%rax,%rcx,8), %rsi
callq 0x3220
cmpl $0x0, %eax
jne 0x1b4d3
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x1b4e0
jmp 0x1b4d5
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1b47a
movq -0x8(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x1b4f5
movq -0x8(%rbp), %rax
movl $0x45, 0x28(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)