// File: /workspace/github_cpp_makefile_star2_O1/pixlark[P]Badge/src/lexer.cc
// Function: Lexer::next_token()
Token Lexer::next_token()
{
 reset:
	if (peek() == '\0') {
		Token token = create_token(TOKEN_EOF, 1);
		return token;
	}
	
	if (isspace(peek())) {
		advance();
		goto reset;
	}

	if (peek() == '%') {
		while (peek() != '\0' && peek() != '\n') {
			advance();
		}
		goto reset;
	}
	
	if (peek() == '"') {
		size_t start = cursor;
		advance();
		
		String_Builder builder;
		while (peek() != '"') {
			builder.add(next());
		}
		advance();
		char * s = builder.final_string();
		defer { free(s); };
		
		Token token = create_token(TOKEN_STRING_LITERAL, cursor - start);
		token.values.string = Intern::intern(s); // string literals are technically symbols
		return token;
	}
	
	if (isalpha(peek()) || peek() == '_') {
		String_Builder builder;
		while (isalnum(peek()) || peek() == '_') {
			builder.add(next());
		}
		char * s = builder.final_string();
		defer { free(s); };
		
		for (int i = 0; i < RESERVED_WORDS_COUNT; i++) {
			if (strcmp(s, reserved_words[i]) == 0) {
				return create_token((Token_Kind) (RESERVED_WORDS_BEGIN + i), builder.size());
			}
		}
		
		Token token = create_token(TOKEN_SYMBOL, builder.size());
		token.values.symbol = Intern::intern(s);
		return token;
	}

	if (isdigit(peek())) {
		String_Builder builder;
		while (isdigit(peek())) {
			builder.add(next());
		}
		char * s = builder.final_string();
		defer { free(s); };
		Token token = create_token(TOKEN_INTEGER_LITERAL, builder.size());
		token.values.integer = strtol(s, NULL, 10);
		return token;
	}
	
	switch (peek()) {
	case '+':
	case '-':
	case '*':
	case '/':
	case '.':
	case ',':
	case '(':
	case ')':
	case '{':
	case '}':
	case '@':
	case '$':
	case ':':
	case '\'':
		return create_token((Token_Kind) next(), 1);
		//return Token::with_kind((Token_Kind) next());
	case '=':
		return create_token(read_double_token('=', '=', TOKEN_EQUAL), 1);
	case '!':
		return create_token(read_double_token('!', '=', TOKEN_NOT_EQUAL), 1);
	case '>':
		return create_token(read_double_token('>', '=', TOKEN_GTE), 1);
	case '<':
		return create_token(read_double_token('<', '=', TOKEN_LTE), 1);
	case ']':
		return create_token((Token_Kind) next(), 1);
	case '[':
		advance();
		if (peek() == '-') {
			// Multi-line comment
			while (true) {
				advance();
				if (peek() == '\0') {
					fatal("Unterminated multi-line comment");
				}
				if (peek() == '-') {
					advance();
					if (peek() == ']') {
						advance();
						break;
					}
				}
			}
			goto reset;
		} else {
			return create_token((Token_Kind) '[', 1);
			//return Token::with_kind((Token_Kind) '[');
		}
	default:
		fatal_assoc(Assoc_Allocator::make(source, source_length, cursor, 1, line),
					"Line %d\nMisplaced character %c (%d)", line, peek(), peek());
		/*
	case ';':
		return Token::with_kind(read_double_token(';', ';', TOKEN_DOUBLE_SEMICOLON));*/
	}
	return (Token) {}; // @linter
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %r14
cmpq %rsi, %r14
setb %bl
movq %rdi, -0x30(%rbp)
jae 0x2713
movq (%rdi), %r12
movq 0x8(%rdi), %r13
leaq 0x18(%rdi), %rax
movq %rax, -0x68(%rbp)
movq 0x18(%rdi), %r15
movq %rsi, -0x38(%rbp)
cmpb $0x0, (%r12,%r14)
je 0x2713
xorl %edi, %edi
testb $0x1, %bl
je 0x2559
movsbl (%r12,%r14), %edi
callq 0x1040
testl %eax, %eax
je 0x2594
testb $0x1, %bl
movq -0x38(%rbp), %rsi
je 0x2587
cmpb $0xa, (%r12,%r14)
movq -0x30(%rbp), %rax
jne 0x2580
incq %r15
movq -0x68(%rbp), %rcx
movq %r15, (%rcx)
incq %r14
movq %r14, 0x10(%rax)
cmpq %rsi, %r14
setb %bl
jb 0x2542
jmp 0x2713
xorl %edi, %edi
testb $0x1, %bl
movq -0x38(%rbp), %rsi
je 0x2601
cmpb $0x25, (%r12,%r14)
jne 0x25e7
cmpq %rsi, %r14
setb %al
jae 0x2587
movq -0x30(%rbp), %rcx
cmpb $0x0, (%r12,%r14)
je 0x2587
testb $0x1, %al
je 0x25dd
cmpb $0xa, (%r12,%r14)
je 0x2587
testb $0x1, %al
je 0x25dd
cmpb $0xa, (%r12,%r14)
jne 0x25d6
incq %r15
movq %r15, 0x18(%rcx)
incq %r14
movq %r14, 0x10(%rcx)
cmpq %rsi, %r14
setb %al
jb 0x25b2
jmp 0x2587
testb $0x1, %bl
je 0x2601
cmpb $0x22, (%r12,%r14)
je 0x2bb6
testb $0x1, %bl
je 0x2601
movsbl (%r12,%r14), %edi
callq 0x11b0
testl %eax, %eax
jne 0x283a
testb $0x1, %bl
je 0x2643
cmpb $0x5f, (%r12,%r14)
je 0x283a
testb $0x1, %bl
je 0x2643
movsbl (%r12,%r14), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
jbe 0x2a2a
testb $0x1, %bl
movq -0x38(%rbp), %rsi
je 0x267e
movb (%r12,%r14), %al
jmp 0x2649
xorl %eax, %eax
movq -0x38(%rbp), %rsi
movzbl %al, %eax
cmpl $0x5c, %eax
jg 0x2740
cmpl $0x5b, %eax
jne 0x27b4
testb $0x1, %bl
je 0x2682
cmpb $0xa, (%r12,%r14)
movq -0x30(%rbp), %rax
jne 0x2675
incq %r15
movq %r15, 0x18(%rax)
incq %r14
movq %r14, 0x10(%rax)
jmp 0x2686
xorl %eax, %eax
jmp 0x2649
movq -0x30(%rbp), %rax
cmpq %rsi, %r14
jae 0x2a01
cmpb $0x2d, (%r12,%r14)
jne 0x2a01
cmpq %r13, %r14
jae 0x26b4
cmpb $0xa, (%r12,%r14)
jne 0x26ad
incq %r15
movq %r15, 0x18(%rax)
incq %r14
movq %r14, 0x10(%rax)
cmpq %r13, %r14
jae 0x2cf7
cmpb $0x0, (%r12,%r14)
je 0x2cf7
cmpq %r13, %r14
jae 0x269a
cmpb $0x2d, (%r12,%r14)
jne 0x269a
cmpq %r13, %r14
jae 0x26ee
cmpb $0xa, (%r12,%r14)
jne 0x26e7
incq %r15
movq %r15, 0x18(%rax)
incq %r14
movq %r14, 0x10(%rax)
cmpq %r13, %r14
jae 0x269a
cmpb $0x5d, (%r12,%r14)
jne 0x269a
cmpq %r13, %r14
jae 0x2587
cmpb $0xa, (%r12,%r14)
je 0x2576
jmp 0x2580
decq %r14
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %r8
movl $0x1, %ecx
movq %r14, %rdx
callq 0x1810
movl %eax, %r14d
shlq $0x20, %r14
movl $0x100, %r12d           # imm = 0x100
jmp 0x2822
cmpl $0x5d, %eax
je 0x27cc
cmpl $0x7d, %eax
je 0x27cc
cmpl $0x7b, %eax
je 0x27cc
movq -0x30(%rbp), %rbx
movq (%rbx), %rdi
movq 0x18(%rbx), %r8
movl $0x1, %ecx
movq %r14, %rdx
callq 0x1810
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
xorl %r8d, %r8d
movl $0x0, %ecx
cmpq %rdi, %rsi
jae 0x278b
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movsbl (%rcx,%rsi), %ecx
movq -0x30(%rbp), %rdx
movq 0x18(%rdx), %rdx
cmpq %rdi, %rsi
jae 0x27a4
movq -0x30(%rbp), %rdi
movq (%rdi), %rdi
movsbl (%rdi,%rsi), %r8d
leaq 0x8c26(%rip), %rsi      # 0xb3d1
movl %eax, %edi
xorl %eax, %eax
callq 0x1c80
addl $-0x21, %eax
cmpl $0x1f, %eax
ja 0x2753
leaq 0x8851(%rip), %rcx      # 0xb014
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb $0x1, %bl
je 0x27e2
movq -0x30(%rbp), %rax
movq (%rax), %rax
movsbq (%rax,%r14), %rax
movl %eax, %r12d
jmp 0x27e5
xorl %r12d, %r12d
testb $0x1, %bl
movq -0x30(%rbp), %rcx
je 0x2803
movq (%rcx), %rax
cmpb $0xa, (%rax,%r14)
jne 0x27fc
incq 0x18(%rcx)
incq %r14
movq %r14, 0x10(%rcx)
movq (%rcx), %rdi
movq 0x10(%rcx), %rdx
decq %rdx
movq 0x18(%rcx), %r8
movl $0x1, %ecx
callq 0x1810
movl %eax, %r14d
shlq $0x20, %r14
orq %r14, %r12
movq %r12, %rax
movq %r13, %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x58(%rbp), %rbx
movq $0x0, (%rbx)
movq $0x4, 0x8(%rbx)
movq 0xe77c(%rip), %rax      # 0x10fd0
movq %rax, 0x10(%rbx)
movq 0xe769(%rip), %rax      # 0x10fc8
movq %rax, 0x18(%rbx)
movl $0x4, %edi
callq 0x1200
movq %rax, -0x8(%rbx)
leaq -0x60(%rbp), %r15
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %r14
xorl %edi, %edi
cmpq %r12, %r14
jae 0x2890
movq (%rbx), %rax
movsbl (%rax,%r14), %edi
callq 0x1100
testl %eax, %eax
jne 0x28a8
cmpq %r12, %r14
jae 0x28df
movq (%rbx), %rax
cmpb $0x5f, (%rax,%r14)
jne 0x28df
cmpq %r12, %r14
jae 0x28b6
movq (%rbx), %rax
movb (%rax,%r14), %al
jmp 0x28b8
xorl %eax, %eax
cmpq %r12, %r14
jae 0x28d2
movq (%rbx), %rcx
cmpb $0xa, (%rcx,%r14)
jne 0x28cb
incq 0x18(%rbx)
incq %r14
movq %r14, 0x10(%rbx)
movsbl %al, %esi
movq %r15, %rdi
callq 0x5522
jmp 0x2879
movq -0x58(%rbp), %r13
leaq 0x1(%r13), %rdi
callq 0x1200
movq %rax, %r15
movq -0x60(%rbp), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x10b0
movb $0x0, (%r15,%r13)
leaq 0x8e5c(%rip), %rsi      # 0xb766
movq %r15, %rdi
callq 0x1160
testl %eax, %eax
je 0x2958
movq %r13, -0x68(%rbp)
xorl %ebx, %ebx
leaq 0xe3fd(%rip), %r13      # 0x10d20
cmpq $0x10, %rbx
je 0x298f
movq 0x8(%r13,%rbx,8), %rsi
movq %r15, %rdi
callq 0x1160
incq %rbx
testl %eax, %eax
jne 0x2923
leaq -0x1(%rbx), %rax
cmpq $0x10, %rax
setae %al
movl %eax, -0x38(%rbp)
addq $0x105, %rbx            # imm = 0x105
movq -0x68(%rbp), %r13
jmp 0x2964
movl $0x105, %ebx            # imm = 0x105
movl $0x0, -0x38(%rbp)
subq %r13, %r14
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %r8
movq %r12, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x1810
movl %eax, %r14d
shlq $0x20, %r14
orq %r14, %rbx
movl -0x38(%rbp), %eax
jmp 0x2997
setae %al
xorl %ebx, %ebx
xorl %r14d, %r14d
testb %al, %al
je 0x29d3
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
movq 0x10(%rax), %rdx
subq %rcx, %rdx
movq 0x18(%rax), %r8
callq 0x1810
movl %eax, %r14d
movq %r15, %rdi
callq 0x15dd
movq %rax, %r13
shlq $0x20, %r14
leaq 0x116(%r14), %rbx
movq %r15, %rdi
callq 0x11f8
movq -0x60(%rbp), %rdi
callq *-0x40(%rbp)
xorps %xmm0, %xmm0
leaq -0x58(%rbp), %rax
movups %xmm0, (%rax)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rax, %r14
movl %ebx, %r12d
jmp 0x2822
decq %r14
movq (%rax), %rdi
movq 0x18(%rax), %r8
movl $0x1, %ecx
movq %r14, %rdx
callq 0x1810
movl %eax, %r14d
shlq $0x20, %r14
movl $0x5b, %r12d
jmp 0x2822
leaq -0x58(%rbp), %rbx
movq $0x0, (%rbx)
movq $0x4, 0x8(%rbx)
movq 0xe58c(%rip), %rax      # 0x10fd0
movq %rax, 0x10(%rbx)
movq 0xe579(%rip), %rax      # 0x10fc8
movq %rax, 0x18(%rbx)
movl $0x4, %edi
callq 0x1200
movq %rax, -0x8(%rbx)
leaq -0x60(%rbp), %r15
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %r14
cmpq %r12, %r14
jae 0x2abd
movq (%rbx), %rax
movsbl (%rax,%r14), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2abd
cmpq %r12, %r14
jae 0x2a94
movq (%rbx), %rax
movb (%rax,%r14), %al
jmp 0x2a96
xorl %eax, %eax
cmpq %r12, %r14
jae 0x2ab0
movq (%rbx), %rcx
cmpb $0xa, (%rcx,%r14)
jne 0x2aa9
incq 0x18(%rbx)
incq %r14
movq %r14, 0x10(%rbx)
movsbl %al, %esi
movq %r15, %rdi
callq 0x5522
jmp 0x2a69
movq -0x58(%rbp), %r13
leaq 0x1(%r13), %rdi
callq 0x1200
movq %rax, %r15
movq -0x60(%rbp), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x10b0
movb $0x0, (%r15,%r13)
subq %r13, %r14
movq (%rbx), %rdi
movq 0x18(%rbx), %r8
movq %r12, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x1810
movl %eax, %r14d
movq %r15, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1170
movq %rax, %rbx
movq %r15, %rdi
callq 0x11f8
movq -0x60(%rbp), %rdi
callq *-0x40(%rbp)
movl %ebx, %r13d
shlq $0x20, %r14
xorps %xmm0, %xmm0
leaq -0x58(%rbp), %rax
movups %xmm0, (%rax)
movl $0x117, %r12d           # imm = 0x117
jmp 0x2822
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x21, %esi
movl $0x3d, %edx
movl $0x102, %ecx            # imm = 0x102
jmp 0x2b97
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x3d, %esi
movl $0x3d, %edx
movl $0x101, %ecx            # imm = 0x101
jmp 0x2b97
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x3e, %esi
movl $0x3d, %edx
movl $0x103, %ecx            # imm = 0x103
jmp 0x2b97
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x3c, %esi
movl $0x3d, %edx
movl $0x104, %ecx            # imm = 0x104
callq 0x2d7a
movl %eax, %r12d
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
decq %rdx
movq 0x18(%rbx), %r8
jmp 0x2811
testb $0x1, %bl
je 0x2bd5
movq -0x30(%rbp), %rcx
movq (%rcx), %rax
cmpb $0xa, (%rax,%r14)
jne 0x2bcd
incq 0x18(%rcx)
leaq 0x1(%r14), %rax
movq %rax, 0x10(%rcx)
leaq -0x58(%rbp), %rbx
movq $0x0, (%rbx)
movq $0x4, 0x8(%rbx)
movq 0xe3e1(%rip), %rax      # 0x10fd0
movq %rax, 0x10(%rbx)
movq 0xe3ce(%rip), %rax      # 0x10fc8
movq %rax, 0x18(%rbx)
movl $0x4, %edi
callq 0x1200
movq %rax, -0x8(%rbx)
leaq -0x60(%rbp), %r12
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %r15
movq 0x10(%rcx), %rax
cmpq %r15, %rax
jae 0x2c3b
movq (%rcx), %rcx
cmpb $0x22, (%rcx,%rax)
je 0x2c67
cmpq %r15, %rax
jae 0x2c3b
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movb (%rcx,%rax), %cl
jmp 0x2c3d
xorl %ecx, %ecx
cmpq %r15, %rax
jae 0x2c5a
movq -0x30(%rbp), %rsi
movq (%rsi), %rdx
cmpb $0xa, (%rdx,%rax)
jne 0x2c53
incq 0x18(%rsi)
incq %rax
movq %rax, 0x10(%rsi)
movsbl %cl, %esi
movq %r12, %rdi
callq 0x5522
jmp 0x2c10
cmpq %r15, %rax
jae 0x2c84
movq -0x30(%rbp), %rdx
movq (%rdx), %rcx
cmpb $0xa, (%rcx,%rax)
jne 0x2c7d
incq 0x18(%rdx)
incq %rax
movq %rax, 0x10(%rdx)
movq -0x58(%rbp), %r13
leaq 0x1(%r13), %rdi
callq 0x1200
movq %rax, %r12
movq -0x60(%rbp), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x10b0
movb $0x0, (%r12,%r13)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq 0x10(%rax), %rcx
subq %r14, %rcx
movq 0x18(%rax), %r8
movq %r15, %rsi
movq %r14, %rdx
callq 0x1810
movl %eax, %r14d
movq %r12, %rdi
callq 0x15dd
movq %rax, %r13
movq %r12, %rdi
callq 0x11f8
movq -0x60(%rbp), %rdi
callq *-0x40(%rbp)
shlq $0x20, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl $0x118, %r12d           # imm = 0x118
jmp 0x2822
leaq 0x86b3(%rip), %rdi      # 0xb3b1
xorl %eax, %eax
callq 0x1a2a
jmp 0x2d72
jmp 0x2d72
movq %rax, %r14
movq %r15, %rdi
callq 0x11f8
jmp 0x2d37
movq %rax, %r14
movq %r12, %rdi
callq 0x11f8
jmp 0x2d45
jmp 0x2d27
jmp 0x2d72
movq %rax, %r14
movq %r15, %rdi
callq 0x11f8
jmp 0x2d59
movq %rax, %r14
movq -0x60(%rbp), %rdi
callq *-0x40(%rbp)
jmp 0x2d60
jmp 0x2d72
movq %rax, %r14
movq -0x60(%rbp), %rdi
callq *-0x40(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
jmp 0x2d6a
jmp 0x2d72
movq %rax, %r14
movq -0x60(%rbp), %rdi
callq *-0x40(%rbp)
xorps %xmm0, %xmm0
leaq -0x58(%rbp), %rax
movups %xmm0, (%rax)
movq %r14, %rdi
callq 0x11c0
movq %rax, %rdi
callq 0x5513