// File: /workspace/github_c_makefile_star2_O2/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, %rbx
andq $0x0, (%rsi)
movq %rdi, %r15
leaq 0x110(%rdi), %r14
addq $0x10, %r15
leaq 0x30(%rsp), %r12
movq %rsp, %rbp
leaq 0xc6ff(%rip), %r13      # 0xe3d0
movq %r14, %rdi
callq 0x2984
testl %eax, %eax
jne 0x22b8
movq %r14, %rdi
callq 0x299e
testl %eax, %eax
jne 0x1cf9
movq %r14, %rdi
callq 0x29c4
testl %eax, %eax
je 0x1d22
movq %r12, %rdi
movq %r14, %rsi
callq 0x2a9a
movq 0x50(%rsp), %rax
movq %rax, 0x20(%r14)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%r14)
movups %xmm0, (%r14)
jmp 0x1cd1
movq %r12, %rdi
movq %r14, %rsi
callq 0x2a9a
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
callq 0x29b8
leal -0x21(%rax), %ecx
cmpl $0x1d, %ecx
jbe 0x1d83
addl $-0x5b, %eax
cmpl $0x22, %eax
ja 0x1f4d
movq %rbp, %rcx
leaq 0xc6d8(%rip), %rdx      # 0xe448
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %rbx, %rdi
pushq $0x1e
jmp 0x2159
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
movq %rbp, %rcx
jmpq *%rax
movq %rcx, %rdi
callq 0x29b8
cmpl $0x3d, %eax
jne 0x2264
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2a9a
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
pushq $0x10
jmp 0x2201
movq %rbx, %rdi
pushq $0x23
jmp 0x2159
movq %rcx, %rdi
callq 0x29b8
cmpl $0x26, %eax
jne 0x2264
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2a9a
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
pushq $0xe
jmp 0x2201
movq %rcx, %rdi
callq 0x29b8
cmpl $0x3d, %eax
jne 0x21ee
movq %r12, %rdi
movq %rsp, %rsi
callq 0x2a9a
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
pushq $0x14
jmp 0x2201
movq %rbx, %rdi
pushq $0x1a
jmp 0x2159
movq %rbx, %rdi
pushq $0x22
jmp 0x2159
movq %rbx, %rdi
pushq $0x1b
jmp 0x2159
movq %rbx, %rdi
pushq $0x1c
jmp 0x2159
movq %rbx, %rdi
pushq $0x25
jmp 0x2159
movq %rbx, %rdi
pushq $0x18
jmp 0x2159
movq %rcx, %rdi
callq 0x29b8
cmpl $0x3d, %eax
jne 0x21f5
movq %r12, %rdi
movq %rsp, %rsi
callq 0x2a9a
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
pushq $0xf
jmp 0x2201
movq %rbx, %rdi
pushq $0x19
jmp 0x2159
movq %rcx, %rdi
callq 0x29b8
cmpl $0x3d, %eax
jne 0x21fc
movq %r12, %rdi
movq %rsp, %rsi
callq 0x2a9a
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
pushq $0x13
jmp 0x2201
movq %rbx, %rdi
pushq $0x24
jmp 0x2159
movq %rbx, %rdi
pushq $0x16
jmp 0x2159
movq %rbx, %rdi
pushq $0x17
jmp 0x2159
movq %r14, %rdi
callq 0x29f3
testl %eax, %eax
je 0x220f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x24f0
cmpl $-0x1, %eax
jne 0x2264
movq (%rbx), %rax
movabsq $0x400000027, %rcx      # imm = 0x400000027
movq %rcx, (%rax)
jmp 0x2264
movq %r14, %rdi
leaq 0xc559(%rip), %rsi      # 0xe4e9
pushq $0x5
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x4
popq %rdx
leaq 0xc539(%rip), %rcx      # 0xe4e9
jmp 0x204d
movq %r14, %rdi
leaq 0xc53f(%rip), %rsi      # 0xe4fe
pushq $0x6
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x7
popq %rdx
leaq 0xc51f(%rip), %rcx      # 0xe4fe
jmp 0x20db
movq %rbx, %rdi
pushq $0x21
jmp 0x2159
movq %rbx, %rdi
pushq $0x1f
jmp 0x2159
movq %r14, %rdi
leaq 0xc4d2(%rip), %rsi      # 0xe4d4
pushq $0x8
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
leaq 0xc4b3(%rip), %rcx      # 0xe4d4
jmp 0x207e
movq %r14, %rdi
leaq 0xc4c2(%rip), %rsi      # 0xe4ef
pushq $0x5
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x5
popq %rdx
leaq 0xc4a2(%rip), %rcx      # 0xe4ef
pushq $0x5
jmp 0x2250
movq %r14, %rdi
leaq 0xc497(%rip), %rsi      # 0xe4f5
pushq $0x8
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x6
popq %rdx
leaq 0xc477(%rip), %rcx      # 0xe4f5
pushq $0x8
jmp 0x2250
movq %r14, %rdi
leaq 0xc48e(%rip), %rsi      # 0xe51d
pushq $0x6
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0xb
popq %rdx
leaq 0xc46e(%rip), %rcx      # 0xe51d
jmp 0x20db
movq %r14, %rdi
leaq 0xc44a(%rip), %rsi      # 0xe505
pushq $0x6
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x8
popq %rdx
leaq 0xc42a(%rip), %rcx      # 0xe505
pushq $0x6
jmp 0x2250
movq %rcx, %rdi
callq 0x29b8
cmpl $0x7c, %eax
jne 0x2264
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2a9a
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
pushq $0xd
jmp 0x2201
movq %r14, %rdi
leaq 0xc3ae(%rip), %rsi      # 0xe4dd
pushq $0x3
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2228
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
leaq 0xc38e(%rip), %rcx      # 0xe4dd
jmp 0x224e
movq %rbx, %rdi
pushq $0x20
popq %rsi
movq %r14, %rdx
jmp 0x2208
movq %r14, %rdi
leaq 0xc375(%rip), %rsi      # 0xe4e1
pushq $0x2
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x2
popq %rdx
leaq 0xc355(%rip), %rcx      # 0xe4e1
pushq $0x2
jmp 0x2250
movq %r14, %rdi
leaq 0xc347(%rip), %rsi      # 0xe4e4
pushq $0x4
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x3
popq %rdx
leaq 0xc327(%rip), %rcx      # 0xe4e4
pushq $0x4
jmp 0x2250
movq %r14, %rdi
leaq 0xc33e(%rip), %rsi      # 0xe50c
pushq $0xc
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x9
popq %rdx
leaq 0xc322(%rip), %rcx      # 0xe50c
pushq $0xc
jmp 0x2250
movq %rbx, %rdi
pushq $0x12
jmp 0x2201
movq %rbx, %rdi
pushq $0x15
jmp 0x2201
movq %rbx, %rdi
pushq $0x11
popq %rsi
movq %r14, %rdx
movq %rsp, %rcx
callq 0x2760
jmp 0x2264
movq %r14, %rdi
callq 0x2a09
testl %eax, %eax
jne 0x2259
movq %rbx, %rdi
movq %r14, %rsi
callq 0x27be
jmp 0x2264
movq %r14, %rdi
leaq 0xc2e7(%rip), %rsi      # 0xe519
pushq $0x3
popq %rdx
callq 0x2b13
testl %eax, %eax
je 0x2259
movq %rbx, %rdi
movq %r14, %rsi
pushq $0xa
popq %rdx
leaq 0xc2cb(%rip), %rcx      # 0xe519
pushq $0x3
popq %r8
callq 0x2429
jmp 0x2264
movq %rbx, %rdi
movq %r14, %rsi
callq 0x266c
movq (%rbx), %rax
movq 0x50(%rax), %rcx
movq %rcx, 0x20(%r14)
movups 0x30(%rax), %xmm0
movups 0x40(%rax), %xmm1
movups %xmm1, 0x10(%r14)
movups %xmm0, (%r14)
movq (%rbx), %rax
cmpl $0x27, (%rax)
jne 0x2304
movq 0x13d61(%rip), %rcx     # 0x15ff0
movq (%rcx), %rdi
movq 0x18(%rax), %rcx
movq 0x20(%rax), %r8
leaq 0xc360(%rip), %rsi      # 0xe601
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
movq (%rbx), %rdi
callq 0x297c
jmp 0x1cd1
xorl %eax, %eax
callq 0x23e8
movq %rax, (%rbx)
movabsq $0x400000026, %rcx      # imm = 0x400000026
movq %rcx, (%rax)
movq 0x20(%r14), %rcx
movq %rcx, 0x28(%rax)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x18(%rax)
movups %xmm0, 0x8(%rax)
movq (%rbx), %rax
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x40(%rax)
movq 0x20(%r14), %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