// File: /workspace/github_c_makefile_star2_O3/masyagin1998[P]GCI/src/lexer/lexer.c
// Function: lexer_next_token
void lexer_next_token(lexer_type_t lexer, struct TOKEN**tok)
{    
    struct POS*cur = &(lexer->cur);
    struct POS cur_next;
    (*tok) = NULL;

    while (!pos_is_eof(cur)) {
        int found_eof = 0;
        while (pos_is_whitespace(cur) || pos_is_newline(cur)) {
            (*cur) = pos_next(cur);
            if (pos_is_eof(cur)) {
                found_eof = 1;
                break;
            }
        }

        if (found_eof) {
            break;
        }

        cur_next = pos_next(cur);

        /* keywords */
        switch (pos_get_code(cur)) {
        case 'f': {
            if (pos_check_keyword(cur, function_keyword, function_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_FUNCTION, function_keyword, function_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'l': {
            if (pos_check_keyword(cur, let_keyword, let_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_LET, let_keyword, let_keyword_len);   
            } else if (pos_check_keyword(cur, len_keyword, len_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_LEN, len_keyword, len_keyword_len);
            }else {
                goto eat_ident;
            }
            break;
        }
        case 'i': {
            if (pos_check_keyword(cur, if_keyword, if_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_IF, if_keyword, if_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'e': {
            if (pos_check_keyword(cur, else_keyword, else_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_ELSE, else_keyword, else_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'w': {
            if (pos_check_keyword(cur, while_keyword, while_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_WHILE, while_keyword, while_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'b': {
            if (pos_check_keyword(cur, break_keyword, break_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_BREAK, break_keyword, break_keyword_len);
            } else {
                goto eat_ident;
            }            
            break;
        }
        case 'c': {
            if (pos_check_keyword(cur, continue_keyword, continue_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_CONTINUE, continue_keyword, continue_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'a': {
            if (pos_check_keyword(cur, append_keyword, append_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_APPEND, append_keyword, append_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'd': {
            if (pos_check_keyword(cur, delete_keyword, delete_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_DELETE, delete_keyword, delete_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'h': {
            if (pos_check_keyword(cur, has_property_keyword, has_property_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_HAS_PROPERTY, has_property_keyword, has_property_keyword_len);
            } else {
                goto eat_ident;
            }
            break;
        }
        case 'r': {
            if (pos_check_keyword(cur, return_keyword, return_keyword_len)) {
                token_read_keyword(tok, cur, TOKEN_TYPE_RETURN, return_keyword, return_keyword_len);
            } else {
                goto eat_ident;
            }            
            break;
        }

            /* operators */
        case '|': {
            if (pos_get_code(&cur_next) == '|') {
                cur_next = pos_next(&cur_next);
                token_read_op(tok, TOKEN_TYPE_OR, cur, &cur_next);
            }
            break;
        }
        case '&': {
            if (pos_get_code(&cur_next) == '&') {
                cur_next = pos_next(&cur_next);
                token_read_op(tok, TOKEN_TYPE_AND, cur, &cur_next);
            }            
            break;
        }
        case '=': {
            if (pos_get_code(&cur_next) == '=') {
                cur_next = pos_next(&cur_next);
                token_read_op(tok, TOKEN_TYPE_EQEQ, cur, &cur_next);
            } else {
                token_read_op(tok, TOKEN_TYPE_EQ, cur, &cur_next);
            }
            break;            
        }
        case '!': {
            if (pos_get_code(&cur_next) == '=') {
                cur_next = pos_next(&cur_next);
                token_read_op(tok, TOKEN_TYPE_NEQ, cur, &cur_next);
            }
            break;            
        }
        case '<': {
            if (pos_get_code(&cur_next) == '=') {
                cur_next = pos_next(&cur_next);
                token_read_op(tok, TOKEN_TYPE_LE, cur, &cur_next);
            } else {
                token_read_op(tok, TOKEN_TYPE_LT, cur, &cur_next);
            }
            break;            
        }
        case '>': {
            if (pos_get_code(&cur_next) == '=') {
                cur_next = pos_next(&cur_next);
                token_read_op(tok, TOKEN_TYPE_GE, cur, &cur_next);
            } else {
                token_read_op(tok, TOKEN_TYPE_GT, cur, &cur_next);
            }            
            break;            
        }
        case '+': {
            token_read_op(tok, TOKEN_TYPE_PLUS, cur, &cur_next);
            break;            
        }
        case '-': {
            token_read_op(tok, TOKEN_TYPE_MINUS, cur, &cur_next);
            break;            
        }
        case '*': {
            token_read_op(tok, TOKEN_TYPE_MUL, cur, &cur_next);
            break;            
        }
        case '/': {
            token_read_op(tok, TOKEN_TYPE_DIV, cur, &cur_next);
            break;            
        }
        case '%': {
            token_read_op(tok, TOKEN_TYPE_MOD, cur, &cur_next);
            break;            
        }
        case '(': {
            token_read_op(tok, TOKEN_TYPE_LPAREN, cur, &cur_next);
            break;            
        }
        case ')': {
            token_read_op(tok, TOKEN_TYPE_RPAREN, cur, &cur_next);
            break;            
        }
        case '[': {
            token_read_op(tok, TOKEN_TYPE_LBRACKET, cur, &cur_next);            
            break;
        }
        case ']': {
            token_read_op(tok, TOKEN_TYPE_RBRACKET, cur, &cur_next);
            break;
        }
        case '{': {
            token_read_op(tok, TOKEN_TYPE_LBRACE, cur, &cur_next);
            break;            
        }
        case '}': {
            token_read_op(tok, TOKEN_TYPE_RBRACE, cur, &cur_next);
            break;            
        }
        case ',': {
            token_read_op(tok, TOKEN_TYPE_COMMA, cur, &cur_next);
            break;            
        }
        case ';': {
            token_read_op(tok, TOKEN_TYPE_SEMI, cur, &cur_next);
            break;            
        }
        case '.': {
            token_read_op(tok, TOKEN_TYPE_DOT, cur, &cur_next);
            break;            
        }
        case ':': {
            token_read_op(tok, TOKEN_TYPE_COLON, cur, &cur_next);
            break;            
        }
        default: {
            if (pos_is_digit(cur)) {
                enum LEXER_CODES r = token_read_number(tok, cur);
                if (r == LEXER_INVALID_TOKEN) {
                    (*tok)->token_type = TOKEN_TYPE_UNKNOWN;
                    (*tok)->group_type = GROUP_TYPE_AUX;
                }
            } else if (pos_is_letter(cur)) {
            eat_ident:
                token_read_ident(tok, cur);
            } else {
                token_read_unknown(tok, cur);
            }
            break;
        }
        }

        (*cur) = (*tok)->frag.following;
        if ((*tok)->token_type == TOKEN_TYPE_UNKNOWN) {
            fprintf(stderr, "%s:%zu:%zu: warning: unknown token ‘‘\n",
                    lexer->program_name,
                    (*tok)->frag.starting.line,
                    (*tok)->frag.starting.pos);
            token_free((*tok));
        } else {
            return;
        }
    }

    /* EOF */
    (*tok) = create_token();

    (*tok)->token_type = TOKEN_TYPE_EOF;
    (*tok)->group_type = GROUP_TYPE_AUX;
    (*tok)->frag.starting = (*cur);
    (*tok)->frag.following = (*cur);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x110(%rdi), %rbx
movq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x53b4
testl %eax, %eax
je 0x465b
xorl %eax, %eax
callq 0x4e08
movq %rax, (%r14)
movabsq $0x400000026, %rcx      # imm = 0x400000026
movq %rcx, (%rax)
movq 0x20(%rbx), %rcx
movq %rcx, 0x28(%rax)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x18(%rax)
movups %xmm0, 0x8(%rax)
movq (%r14), %rax
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x40(%rax)
movq 0x20(%rbx), %rcx
movq %rcx, 0x50(%rax)
movups %xmm0, 0x30(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x10, %r15
leaq 0x30(%rsp), %r12
leaq 0xaeb2(%rip), %r13      # 0xf51d
movq %rbx, %rdi
callq 0x53d0
testl %eax, %eax
jne 0x4683
movq %rbx, %rdi
callq 0x53f6
testl %eax, %eax
je 0x46b9
movq %r12, %rdi
movq %rbx, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rbx)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x53b4
testl %eax, %eax
je 0x466b
jmp 0x4604
movq %r12, %rdi
movq %rbx, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x53ea
leal -0x21(%rax), %ecx
cmpl $0x1d, %ecx
jbe 0x471d
addl $-0x5b, %eax
cmpl $0x22, %eax
movq %rsp, %rcx
ja 0x492c
leaq 0xad41(%rip), %rdx      # 0xf448
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %r14, %rdi
movl $0x1e, %esi
jmp 0x4b9f
leaq 0xacac(%rip), %rdx      # 0xf3d0
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
movq %rsp, %rcx
jmpq *%rax
movq %rcx, %rdi
callq 0x53ea
cmpl $0x3d, %eax
jne 0x4cd6
movq %r12, %rdi
movq %rsp, %rbp
movq %rbp, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %r14, %rdi
movl $0x10, %esi
jmp 0x4c6b
movq %r14, %rdi
movl $0x23, %esi
jmp 0x4b9f
movq %rcx, %rdi
callq 0x53ea
cmpl $0x26, %eax
jne 0x4cd6
movq %r12, %rdi
movq %rsp, %rbp
movq %rbp, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %r14, %rdi
movl $0xe, %esi
jmp 0x4c6b
movq %rcx, %rdi
movq %rcx, %rbp
callq 0x53ea
cmpl $0x3d, %eax
jne 0x4c4f
movq %r12, %rdi
movq %rbp, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %r14, %rdi
movl $0x14, %esi
jmp 0x4c6b
movq %r14, %rdi
movl $0x1a, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x22, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x1b, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x1c, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x25, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x18, %esi
jmp 0x4b9f
movq %rcx, %rdi
movq %rcx, %rbp
callq 0x53ea
cmpl $0x3d, %eax
jne 0x4c59
movq %r12, %rdi
movq %rbp, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %r14, %rdi
movl $0xf, %esi
jmp 0x4c6b
movq %r14, %rdi
movl $0x19, %esi
jmp 0x4b9f
movq %rcx, %rdi
movq %rcx, %rbp
callq 0x53ea
cmpl $0x3d, %eax
jne 0x4c63
movq %r12, %rdi
movq %rbp, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %r14, %rdi
movl $0x13, %esi
jmp 0x4c6b
movq %r14, %rdi
movl $0x24, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x16, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x17, %esi
jmp 0x4b9f
movq %rbx, %rdi
callq 0x5425
testl %eax, %eax
je 0x4c78
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4eea
cmpl $-0x1, %eax
jne 0x4cd6
movq (%r14), %rax
movabsq $0x400000027, %rcx      # imm = 0x400000027
movq %rcx, (%rax)
jmp 0x4cd6
movl $0x5, %edx
movq %rbx, %rdi
leaq 0xab75(%rip), %rsi      # 0xf4e9
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x5, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x4, %edx
leaq 0xab50(%rip), %rcx      # 0xf4e9
jmp 0x4cc4
movl $0x6, %edx
movq %rbx, %rdi
leaq 0xab51(%rip), %rsi      # 0xf4fe
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x6, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x7, %edx
leaq 0xab2c(%rip), %rcx      # 0xf4fe
jmp 0x4cc4
movq %r14, %rdi
movl $0x21, %esi
jmp 0x4b9f
movq %r14, %rdi
movl $0x1f, %esi
jmp 0x4b9f
movl $0x8, %edx
movq %rbx, %rdi
leaq 0xaad4(%rip), %rsi      # 0xf4d4
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x8, %r8d
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
leaq 0xaab2(%rip), %rcx      # 0xf4d4
jmp 0x4cc4
movl $0x5, %edx
movq %rbx, %rdi
leaq 0xaab9(%rip), %rsi      # 0xf4ef
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x5, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x5, %edx
leaq 0xaa94(%rip), %rcx      # 0xf4ef
jmp 0x4cc4
movl $0x8, %edx
movq %rbx, %rdi
leaq 0xaa86(%rip), %rsi      # 0xf4f5
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x8, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x6, %edx
leaq 0xaa61(%rip), %rcx      # 0xf4f5
jmp 0x4cc4
movl $0x6, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x6, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0xb, %edx
movq %r13, %rcx
jmp 0x4cc4
movl $0x6, %edx
movq %rbx, %rdi
leaq 0xaa2c(%rip), %rsi      # 0xf505
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x6, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x8, %edx
leaq 0xaa07(%rip), %rcx      # 0xf505
jmp 0x4cc4
movq %rcx, %rdi
callq 0x53ea
cmpl $0x7c, %eax
jne 0x4cd6
movq %r12, %rdi
movq %rsp, %rbp
movq %rbp, %rsi
callq 0x54e6
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq %r14, %rdi
movl $0xd, %esi
jmp 0x4c6b
leaq 0xa9c6(%rip), %r13      # 0xf519
movl $0x3, %edx
movq %rbx, %rdi
leaq 0xa97b(%rip), %rbp      # 0xf4dd
movq %rbp, %rsi
callq 0x5566
testl %eax, %eax
je 0x4c91
movl $0x3, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movq %rbp, %rcx
callq 0x4e24
leaq 0xa98b(%rip), %r13      # 0xf51d
jmp 0x4cd6
movq %r14, %rdi
movl $0x20, %esi
movq %rbx, %rdx
jmp 0x4c71
movl $0x2, %edx
movq %rbx, %rdi
leaq 0xa92b(%rip), %rsi      # 0xf4e1
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x2, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x2, %edx
leaq 0xa906(%rip), %rcx      # 0xf4e1
jmp 0x4cc4
movl $0x4, %edx
movq %rbx, %rdi
leaq 0xa8f5(%rip), %rsi      # 0xf4e4
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0x4, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x3, %edx
leaq 0xa8d0(%rip), %rcx      # 0xf4e4
jmp 0x4cc4
movl $0xc, %edx
movq %rbx, %rdi
leaq 0xa8e4(%rip), %rsi      # 0xf50c
callq 0x5566
testl %eax, %eax
je 0x4ccb
movl $0xc, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x9, %edx
leaq 0xa8bf(%rip), %rcx      # 0xf50c
jmp 0x4cc4
movq %r14, %rdi
movl $0x12, %esi
jmp 0x4c6b
movq %r14, %rdi
movl $0x15, %esi
jmp 0x4c6b
movq %r14, %rdi
movl $0x11, %esi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x5183
jmp 0x4cd6
movq %rbx, %rdi
callq 0x543b
testl %eax, %eax
jne 0x4ccb
movq %r14, %rdi
movq %rbx, %rsi
callq 0x51e1
jmp 0x4cd6
movl $0x3, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5566
testl %eax, %eax
leaq 0xa873(%rip), %r13      # 0xf51d
je 0x4ccb
movl $0x3, %r8d
movq %r14, %rdi
movq %rbx, %rsi
movl $0xa, %edx
leaq 0xa855(%rip), %rcx      # 0xf519
callq 0x4e24
jmp 0x4cd6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x508d
movq (%r14), %rax
movq 0x50(%rax), %rcx
movq %rcx, 0x20(%rbx)
movups 0x30(%rax), %xmm0
movups 0x40(%rax), %xmm1
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
movq (%r14), %rdi
cmpl $0x27, (%rdi)
jne 0x464c
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x14e6
testb $0x1, %al
jne 0x466b
jmp 0x4604