// File: /workspace/github_c_makefile_star2_O1/sebbekarlsson[P]cola/src/lex.c
// Function: lex_get_next_token
token* lex_get_next_token(lex_state* state) {
    while (state->current_char != '\0') {
        char* str = char_to_string(state->current_char); 

        if (state->current_char == ' ' || (int)state->current_char == 10 || state->current_char == '\0') {
            lex_skip_whitespace(state);
            free(str);
            continue;
        }

        else if (state->current_char == '+') {
            lex_advance(state);
            return init_token(_OP_PLUS, str);
        }

        else if (state->current_char == '-') {
            lex_advance(state);
            return init_token(_OP_SUBTRACT, str);
        }

        else if (state->current_char == '/') {
            lex_advance(state);
            return init_token(_OP_DIVIDE, str);
        }

        else if (state->current_char == '*') {
            lex_advance(state);
            return init_token(_OP_MULTIPLY, str);
        }

        else if (state->current_char == '(') {
            lex_advance(state);
            return init_token(_LPAREN, str);
        }

        else if (state->current_char == ')') {
            lex_advance(state);
            return init_token(_RPAREN, str);
        }

        else if (state->current_char == '{') {
            lex_advance(state);
            return init_token(_LBRACE, str);
        }

        else if (state->current_char == '}') {
            lex_advance(state);
            return init_token(_RBRACE, str);
        }

        else if (state->current_char == ';') {
            lex_advance(state);
            return init_token(_SEMI, str);
        }

        else if (state->current_char == '.') {
            lex_advance(state);
            return init_token(_DOT, str);
        }

        else if (state->current_char == ',') {
            lex_advance(state);
            return init_token(_COMMA, str);
        }

        else if (state->current_char == '<') {
            lex_advance(state);
            return init_token(_LESS_THAN, str);
        }
        
        else if (state->current_char == '>') {
            lex_advance(state);
            return init_token(_LARGER_THAN, str);
        }

        else if (state->current_char == '=') {
            lex_advance(state);
            if (state->current_char == '=') {
                lex_advance(state);
                return init_token(_EQUALS_EQUALS, str);
            } else {
                lex_advance(state);
                return init_token(_EQUALS, str);
            }
        }

        else if (state->current_char == '[') {
            lex_advance(state);
            return init_token(_LBRACKET, str);
        }

        else if (state->current_char == ']') {
            lex_advance(state);
            return init_token(_RBRACKET, str);
        }

        else if (state->current_char == '"') {
            free(str);
            return init_token(_STRING, lex_parse_string(state));
        }

        else if (state->current_char == '#') {
            free(str);
            lex_advance(state);
            if (state->current_char != '!') {
                return init_token(_INTERPRETER_INSTR, lex_parse_id(state));
            }
        }

        else if (state->current_char == '\'') {
            free(str);
            return init_token(_CHAR, lex_parse_char(state));
        }

        else if (isdigit(state->current_char)) {
            free(str);
            return lex_parse_number(state);
        }

        else if (isalnum(state->current_char)) {
            free(str);
            return parse_id(state, init_token(_ID, lex_parse_id(state)));
        } else {
            printf("Unexpected token: `%s` (%d) \n", str, (int) state->current_char);
            break;
        }

        free(str);
        lex_advance(state);
    }

    return init_token(_EOF, "");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movb 0x8(%rdi), %al
testb %al, %al
je 0x32e8
movq %rdi, %rbx
movl $0x2, %ecx
movl %ecx, %r13d
leaq 0x25fc(%rip), %r14      # 0x52f8
movl $0x1, %ecx
movl %ecx, %ecx
movq %rcx, -0x30(%rbp)
movsbl %al, %edi
callq 0x49f4
movq %rax, %r15
movzbl 0x8(%rbx), %eax
cmpl $0x5a, %eax
jg 0x2d64
leal -0x20(%rax), %ecx
cmpl $0x1e, %ecx
ja 0x2db3
leaq 0x254e(%rip), %rdx      # 0x527c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq %r15, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x3361
movl $0x3, %edi
movq %rax, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
cmpl $0x7a, %eax
jg 0x2dd5
cmpl $0x5b, %eax
je 0x31b9
cmpl $0x5d, %eax
jne 0x2e1b
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2d96
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x23, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
testl %eax, %eax
je 0x2dbc
cmpl $0xa, %eax
jne 0x2e1b
movq %rbx, %rdi
callq 0x3316
movq %r15, %rdi
callq 0x1030
movslq (%r14,%r13,4), %rax
addq %r14, %rax
jmpq *%rax
cmpl $0x7b, %eax
je 0x31f1
cmpl $0x7d, %eax
jne 0x2e1b
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2dfe
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0xf, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq %r13, -0x38(%rbp)
movsbl %al, %r13d
callq 0x1170
movq (%rax), %rax
movslq %r13d, %rcx
movzwl (%rax,%rcx,2), %eax
btl $0xb, %eax
jb 0x3229
testb $0x8, %al
jne 0x32a1
leaq 0x24bd(%rip), %rdi      # 0x5308
movq %r15, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x10a0
movl $0x3, %eax
movl %eax, %eax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
movq -0x38(%rbp), %r13
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2e87
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x8, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2ebf
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x15, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2ef7
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x10, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2f2f
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x14, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2f67
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0xd, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2f9f
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x7, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x3502
movl $0x26, %edi
movq %rax, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x1030
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x300c
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
cmpb $0x21, 0x8(%rbx)
jne 0x324d
movq %r15, %rdi
callq 0x1030
movq (%rbx), %rcx
movslq 0xc(%rbx), %rdx
xorl %eax, %eax
cmpb $0x0, (%rcx,%rdx)
je 0x303b
leaq 0x1(%rdx), %rsi
movl %esi, 0xc(%rbx)
movb 0x1(%rcx,%rdx), %cl
movb %cl, 0x8(%rbx)
movl %eax, %eax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3061
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x6, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3099
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x5, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x30d1
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %cl
movb %cl, 0x8(%rbx)
cmpb $0x3d, 0x8(%rbx)
movslq 0xc(%rbx), %rcx
movb (%rax,%rcx), %dl
jne 0x3272
testb %dl, %dl
je 0x30f4
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x24, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x312c
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0xc, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3164
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x16, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x319c
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x17, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x31d4
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x22, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%rbx), %rax
movslq 0xc(%rbx), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x320c
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0xe, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x361f
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
movq -0x38(%rbp), %r13
jmpq *%rax
movq %rbx, %rdi
callq 0x3430
movl $0x20, %edi
movq %rax, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
testb %dl, %dl
je 0x3284
leaq 0x1(%rcx), %rdx
movl %edx, 0xc(%rbx)
movb 0x1(%rax,%rcx), %al
movb %al, 0x8(%rbx)
movl $0x1b, %edi
movq %r15, %rsi
callq 0x4a78
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq %r15, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x3430
movl $0x1, %edi
movq %rax, %rsi
callq 0x4a78
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4578
movq %rax, %r12
movq -0x30(%rbp), %rax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
movq -0x38(%rbp), %r13
jmpq *%rax
movb 0x8(%rbx), %al
testb %al, %al
jne 0x2d07
leaq 0x2036(%rip), %rsi      # 0x5325
xorl %edi, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4a78
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq