// File: /workspace/github_cpp_makefile_star2_O1/baziotis[P]minijava-cpp/lex.cpp
// Function: next_token()
void next_token() {
    tok_start = input;
lex_again:
    if (!input[0]) {
        token.kind = TOK::EOI;
        return;
    }
    // skip whitespace
    while (*input && charmap[*input] & BLANK) {
        if (*input == '\n') {
            encountered_newline();
        }
        input++;
    }
    if (!input[0]) goto lex_again;
    tok_start = input;

    switch (*input) {
    case '.':
    {
        token.kind = TOK::DOT;
        if (charmap[input[1]]&DEC) {
            warning("Floating numbers are not supported.");
        }
        ++input;
    } break;

    case '0' ... '9':
    {
        while (charmap[*input]&DEC) {
            ++input;
        }
        const char *save = input;
        if (*input == '.' || *input == 'e') {
            warning("Floating numbers are not supported.");
            ++save;
        }
        input = tok_start;  // reset input
        scan_int();
        input = save;
    } break;

    // TODO: Maybe an automata-like lexer is not that good these days..
    // Think of making a modified version of memcmp (one that can
    // intelligently be inlined) optimized for small lengths.

    // Explicitly handle letters that start keywords.
    // If we don't match a keyword, we fall-through to the
    // identifier case.
    case 'b':
    {
        if (input[1] == 'o'
        &&  input[2] == 'o'
        &&  input[3] == 'l'
        &&  input[4] == 'e'
        &&  input[5] == 'a'
        &&  input[6] == 'n'
        && !(charmap[input[7]]&(DEC|MIDCHAR))) {
            input += 7;
            token.kind = TOK::BOOLEAN;
            return;
        }
        goto Lid;
    } break;
    case 'c':
    {
        if (input[1] == 'l'
        &&  input[2] == 'a'
        &&  input[3] == 's'
        &&  input[4] == 's'
        && !(charmap[input[5]]&(DEC|MIDCHAR))) {
            input += 5;
            token.kind = TOK::CLASS;
            return;
        }
        goto Lid;
    } break;
    case 'e':
    {
        if (input[1] == 'l'
        &&  input[2] == 's'
        &&  input[3] == 'e'
        && !(charmap[input[4]]&(DEC|MIDCHAR))) {
            input += 4;
            token.kind = TOK::ELSE;
            return;
        }
        if (input[1] == 'x'
        &&  input[2] == 't'
        &&  input[3] == 'e'
        &&  input[4] == 'n'
        &&  input[5] == 'd'
        &&  input[6] == 's'
        && !(charmap[input[7]]&(DEC|MIDCHAR))) {
            input += 7;
            token.kind = TOK::EXTENDS;
            return;
        }
        goto Lid;
    }
    case 'f':
    {
        if (input[1] == 'a'
        &&  input[2] == 'l'
        &&  input[3] == 's'
        &&  input[4] == 'e'
        && !(charmap[input[5]]&(DEC|MIDCHAR))) {
            input += 5;
            token.kind = TOK::FALSE;
            return;
        }
        goto Lid;
    }
	case 'i':
    {
		if (input[1] == 'f'
		&& !(charmap[input[2]]&(DEC|MIDCHAR)))
        {
            input += 2;
            token.kind = TOK::IF;
			return;
		}
		if (input[1] == 'n'
		&&  input[2] == 't'
		&& !(charmap[input[3]]&(DEC|MIDCHAR)))
        {
            input += 3;
            token.kind = TOK::INT;
            return;
		}
		goto Lid;
    }
    case 'n':
    {
		if (input[1] == 'e'
		&&  input[2] == 'w'
		&& !(charmap[input[3]]&(DEC|MIDCHAR))) {
            input += 3;
            token.kind = TOK::NEW;
            return;
        }
        goto Lid;
    } break;
    case 'p':
    {
		if (input[1] == 'u'
		&&  input[2] == 'b'
		&&  input[3] == 'l'
		&&  input[4] == 'i'
		&&  input[5] == 'c'
		&& !(charmap[input[6]]&(DEC|MIDCHAR))) {
            input += 6;
            token.kind = TOK::PUBLIC;
            return;
        }
        goto Lid;
    } break;
    case 'r':
    {
        if (input[1] == 'e'
        &&  input[2] == 't'
        &&  input[3] == 'u'
        &&  input[4] == 'r'
        &&  input[5] == 'n'
        && !(charmap[input[6]]&(DEC|MIDCHAR))) {
            input += 6;
            token.kind = TOK::RETURN;
            return;
        }
        goto Lid;
    }
    case 's':
    {
        if (input[1] == 't'
        &&  input[2] == 'a'
        &&  input[3] == 't'
        &&  input[4] == 'i'
        &&  input[5] == 'c'
        && !(charmap[input[6]]&(DEC|MIDCHAR))) {
            input += 6;
            token.kind = TOK::STATIC;
            return;
        }
        goto Lid;
    }
    case 't':
    {
        if (input[1] == 'r'
        &&  input[2] == 'u'
        &&  input[3] == 'e'
        && !(charmap[input[4]]&(DEC|MIDCHAR))) {
            input += 4;
            token.kind = TOK::TRUE;
            return;
        }
        if (input[1] == 'h'
        &&  input[2] == 'i'
        &&  input[3] == 's'
        && !(charmap[input[4]]&(DEC|MIDCHAR))) {
            input += 4;
            token.kind = TOK::THIS;
            return;
        }
        goto Lid;
    }
    case 'w':
    {
        if (input[1] == 'h'
        &&  input[2] == 'i'
        &&  input[3] == 'l'
        &&  input[4] == 'e'
        && !(charmap[input[5]]&(DEC|MIDCHAR))) {
            input += 5;
            token.kind = TOK::WHILE;
            return;
        }
        goto Lid;
    }
    case 'v':
    {
        if (input[1] == 'o'
        &&  input[2] == 'i'
        &&  input[3] == 'd'
        && !(charmap[input[4]]&(DEC|MIDCHAR))) {
            input += 4;
            token.kind = TOK::VOID;
            return;
        }
        goto Lid;
    }

    case 'S':
    {
        if (input[1] == 't'
        &&  input[2] == 'r'
        &&  input[3] == 'i'
        &&  input[4] == 'n'
        &&  input[5] == 'g'
        && !(charmap[input[6]]&(DEC|MIDCHAR))) {
            input += 6;
            token.kind = TOK::STRING;
            return;
        }
        if (!memcmp(input, print_stmt_key, print_stmt_key_len)) {
            input += print_stmt_key_len;
            token.kind = TOK::PRINT;
            return;
        }
        goto Lid;
    } break;

    // The rest of letters and _ (which correspond to an identifier)
    case 'a': case 'd': case 'g': case 'h': case 'j':
    case 'k': case 'l': case 'm': case 'o':
    case 'q': case 'u':
    case 'x': case 'y': case 'z':
    case 'A' ... 'R': case 'T' ... 'Z':
    case '_':
    {
Lid:
        while (charmap[*input]&(MIDCHAR|DEC)) {
            ++input;
        }
        token.id = str_intern_range(tok_start, input);
        token.kind = TOK::ID;
    } break;

    case '&':
    {
        if (input[1] == '&') {
            token.kind = TOK::AND_AND;
            input += 2;
        } else {
            warning("There's no `&` token. Maybe you meant to write `&&`.");
            ++input;
        }
    } break;

    case '<': case '\0': case '(': case ')': case '{': case '}':
    case '[': case ']': case ',': case ';': case '!': case '=':
    case '-': case '+': case '*':
    {
        switch (*input)
        {
        case '<': token.kind = TOK::LT; break;
        case '\0': token.kind = TOK::EOI; break;
        case '(': token.kind = TOK::LPAR; break;
        case ')': token.kind = TOK::RPAR; break;
        case '{': token.kind = TOK::LBRACE; break;
        case '}': token.kind = TOK::RBRACE; break;
        case '[': token.kind = TOK::LBRACKET; break;
        case ']': token.kind = TOK::RBRACKET; break;
        case ',': token.kind = TOK::COMMA; break;
        case ';': token.kind = TOK::SEMI; break;
        case '!': token.kind = TOK::NOT; break;
        case '=': token.kind = TOK::ASGN; break;
        case '-': token.kind = TOK::MINUS; break;
        case '+': token.kind = TOK::PLUS; break;
        case '*': token.kind = TOK::STAR; break;
        default: printf("%c\n", *input); assert(0);
        }
        ++input;
    } break;

    case '/':
    {
        ++input;
        if (*input != '/') {
            syntax_error("Expected `/` after `/` so that comment starts;"
                         " skipping the rest of the line");

        }
        while (*input != 0 && *input != '\n') {
            ++input;
        }
        goto lex_again;
    } break;

    default:
        fatal_error("Unrecognized character: ", *input, " - ln: ", loc.ln);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq 0x15c57(%rip), %rax     # 0x196a8
movq %rax, 0x15f58(%rip)     # 0x199b0
cmpb $0x0, (%rax)
je 0x3b38
leaq 0x15c48(%rip), %r14     # 0x196b0
leaq 0xcb51(%rip), %r15      # 0x105c0
leaq 0xd06d(%rip), %rbx      # 0x10ae3
movq 0x15c2b(%rip), %rdi     # 0x196a8
movsbq (%rdi), %rax
testq %rax, %rax
sete %dl
je 0x3b28
testb $0x1, (%rax,%r14)
je 0x3ac9
movl 0x15bf6(%rip), %ecx     # 0x19690
incq %rdi
cmpb $0xa, %al
jne 0x3aa9
incl %ecx
movl %ecx, 0x15be7(%rip)     # 0x19690
movsbq (%rdi), %rax
testq %rax, %rax
sete %dl
je 0x3b21
incq %rdi
testb $0x1, (%rax,%r14)
jne 0x3a9d
decq %rdi
movq %rdi, 0x15bdf(%rip)     # 0x196a8
testb %dl, %dl
jne 0x3b28
movq %rdi, 0x15edc(%rip)     # 0x199b0
cmpb $0x7d, %al
ja 0x4236
movzbl %al, %ecx
movslq (%r15,%rcx,4), %rdx
addq %r15, %rdx
jmpq *%rdx
leaq 0x1(%rdi), %rax
movq %rax, 0x15bb5(%rip)     # 0x196a8
cmpb $0x2f, 0x1(%rdi)
je 0x3b01
movq %rbx, %rdi
callq 0x3901
movq 0x15ba0(%rip), %rax     # 0x196a8
incq %rax
movzbl -0x1(%rax), %ecx
testl %ecx, %ecx
je 0x3b28
cmpl $0xa, %ecx
je 0x3b28
movq %rax, 0x15b89(%rip)     # 0x196a8
jmp 0x3b08
movq %rdi, 0x15b80(%rip)     # 0x196a8
movq 0x15b79(%rip), %rax     # 0x196a8
cmpb $0x0, (%rax)
jne 0x3a76
movl $0x1, 0x15b56(%rip)     # 0x19698
jmp 0x41a5
cmpl $0x5a, %ecx
jg 0x3bd8
leal -0x28(%rcx), %edx
cmpl $0x15, %edx
ja 0x3bf9
leaq 0xcc55(%rip), %rcx      # 0x107b8
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movl $0x3, %eax
jmp 0x4195
movq 0x15b2b(%rip), %rbx     # 0x196a8
movsbq (%rbx), %rax
testb $0x4, (%rax,%r14)
je 0x3b9e
movsbq 0x1(%rbx), %rax
incq %rbx
testb $0x4, (%rax,%r14)
jne 0x3b88
movq %rbx, 0x15b0a(%rip)     # 0x196a8
cmpb $0x65, %al
je 0x3baa
movzbl %al, %eax
cmpl $0x2e, %eax
jne 0x3bb9
leaq 0xcebb(%rip), %rdi      # 0x10a6c
callq 0x39b8
incq %rbx
movq 0x15df0(%rip), %rax     # 0x199b0
movq %rax, 0x15ae1(%rip)     # 0x196a8
callq 0x369c
movq %rbx, 0x15ad5(%rip)     # 0x196a8
jmp 0x41a5
cmpl $0x7a, %ecx
jg 0x3c14
cmpl $0x5b, %ecx
je 0x4182
cmpl $0x5d, %ecx
jne 0x4244
movl $0x1b, %eax
jmp 0x4195
testl %ecx, %ecx
je 0x4190
cmpl $0x21, %ecx
jne 0x4244
movl $0x4, %eax
jmp 0x4195
cmpl $0x7b, %ecx
je 0x4189
cmpl $0x7d, %ecx
jne 0x4244
movl $0x1a, %eax
jmp 0x4195
cmpb $0x68, 0x1(%rdi)
jne 0x410a
cmpb $0x69, 0x2(%rdi)
jne 0x410a
cmpb $0x6c, 0x3(%rdi)
jne 0x410a
cmpb $0x65, 0x4(%rdi)
jne 0x410a
movsbq 0x5(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x5, %rdi
movq %rdi, 0x15a35(%rip)     # 0x196a8
movl $0xa, 0x15a1b(%rip)     # 0x19698
jmp 0x41a5
cmpb $0x65, 0x1(%rdi)
jne 0x410a
cmpb $0x74, 0x2(%rdi)
jne 0x410a
cmpb $0x75, 0x3(%rdi)
jne 0x410a
cmpb $0x72, 0x4(%rdi)
jne 0x410a
cmpb $0x6e, 0x5(%rdi)
jne 0x410a
movsbq 0x6(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x6, %rdi
movq %rdi, 0x159d9(%rip)     # 0x196a8
movl $0xe, 0x159bf(%rip)     # 0x19698
jmp 0x41a5
cmpb $0x75, 0x1(%rdi)
jne 0x410a
cmpb $0x62, 0x2(%rdi)
jne 0x410a
cmpb $0x6c, 0x3(%rdi)
jne 0x410a
cmpb $0x69, 0x4(%rdi)
jne 0x410a
cmpb $0x63, 0x5(%rdi)
jne 0x410a
movsbq 0x6(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x6, %rdi
movq %rdi, 0x1597d(%rip)     # 0x196a8
movl $0xc, 0x15963(%rip)     # 0x19698
jmp 0x41a5
movzbl 0x1(%rdi), %eax
cmpl $0x68, %eax
je 0x3d70
cmpl $0x72, %eax
jne 0x410a
cmpb $0x75, 0x2(%rdi)
jne 0x3d68
cmpb $0x65, 0x3(%rdi)
jne 0x3d68
movsbq 0x4(%rdi), %rcx
testb $0x6, (%rcx,%r14)
je 0x41ee
cmpb $0x68, %al
jne 0x410a
cmpb $0x69, 0x2(%rdi)
jne 0x410a
cmpb $0x73, 0x3(%rdi)
jne 0x410a
movsbq 0x4(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x4, %rdi
movq %rdi, 0x15909(%rip)     # 0x196a8
movl $0x14, 0x158ef(%rip)    # 0x19698
jmp 0x41a5
cmpb $0x6f, 0x1(%rdi)
jne 0x410a
cmpb $0x6f, 0x2(%rdi)
jne 0x410a
cmpb $0x6c, 0x3(%rdi)
jne 0x410a
cmpb $0x65, 0x4(%rdi)
jne 0x410a
cmpb $0x61, 0x5(%rdi)
jne 0x410a
cmpb $0x6e, 0x6(%rdi)
jne 0x410a
movsbq 0x7(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x7, %rdi
movq %rdi, 0x158a3(%rip)     # 0x196a8
movl $0x5, 0x15889(%rip)     # 0x19698
jmp 0x41a5
cmpb $0x74, 0x1(%rdi)
jne 0x3e42
cmpb $0x72, 0x2(%rdi)
jne 0x3e42
cmpb $0x69, 0x3(%rdi)
jne 0x3e42
cmpb $0x6e, 0x4(%rdi)
jne 0x3e42
cmpb $0x67, 0x5(%rdi)
jne 0x3e42
movsbq 0x6(%rdi), %rax
testb $0x6, (%rax,%r14)
je 0x421c
movdqu (%rdi), %xmm0
movzwl 0x10(%rdi), %eax
movd %eax, %xmm1
pcmpeqb 0xc74a(%rip), %xmm0     # 0x105a0
pcmpeqb 0xc752(%rip), %xmm1     # 0x105b0
pand %xmm0, %xmm1
pmovmskb %xmm1, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x410a
addq $0x12, %rdi
movq %rdi, 0x1582c(%rip)     # 0x196a8
movl $0xb, 0x15812(%rip)     # 0x19698
jmp 0x41a5
movzbl 0x1(%rdi), %eax
cmpl $0x78, %eax
je 0x3ec1
cmpl $0x6c, %eax
jne 0x410a
cmpb $0x73, 0x2(%rdi)
jne 0x3eb9
cmpb $0x65, 0x3(%rdi)
jne 0x3eb9
movsbq 0x4(%rdi), %rcx
testb $0x6, (%rcx,%r14)
je 0x4205
cmpb $0x78, %al
jne 0x410a
cmpb $0x74, 0x2(%rdi)
jne 0x410a
cmpb $0x65, 0x3(%rdi)
jne 0x410a
cmpb $0x6e, 0x4(%rdi)
jne 0x410a
cmpb $0x64, 0x5(%rdi)
jne 0x410a
cmpb $0x73, 0x6(%rdi)
jne 0x410a
movsbq 0x7(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x7, %rdi
movq %rdi, 0x1579a(%rip)     # 0x196a8
movl $0x17, 0x15780(%rip)    # 0x19698
jmp 0x41a5
cmpb $0x6f, 0x1(%rdi)
jne 0x410a
cmpb $0x69, 0x2(%rdi)
jne 0x410a
cmpb $0x64, 0x3(%rdi)
jne 0x410a
movsbq 0x4(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x4, %rdi
movq %rdi, 0x15752(%rip)     # 0x196a8
movl $0x10, 0x15738(%rip)    # 0x19698
jmp 0x41a5
cmpb $0x26, 0x1(%rdi)
jne 0x41ab
movl $0x1f, 0x1571f(%rip)    # 0x19698
addq $0x2, %rdi
jmp 0x419e
cmpb $0x61, 0x1(%rdi)
jne 0x410a
cmpb $0x6c, 0x2(%rdi)
jne 0x410a
cmpb $0x73, 0x3(%rdi)
jne 0x410a
cmpb $0x65, 0x4(%rdi)
jne 0x410a
movsbq 0x5(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x5, %rdi
movq %rdi, 0x156e3(%rip)     # 0x196a8
movl $0x13, 0x156c9(%rip)    # 0x19698
jmp 0x41a5
movl $0x1d, 0x156ba(%rip)    # 0x19698
movsbq 0x1(%rdi), %rax
testb $0x4, (%rax,%r14)
je 0x41b7
leaq 0xca77(%rip), %rdi      # 0x10a6c
jmp 0x41b2
cmpb $0x74, 0x1(%rdi)
jne 0x410a
cmpb $0x61, 0x2(%rdi)
jne 0x410a
cmpb $0x74, 0x3(%rdi)
jne 0x410a
cmpb $0x69, 0x4(%rdi)
jne 0x410a
cmpb $0x63, 0x5(%rdi)
jne 0x410a
movsbq 0x6(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x6, %rdi
movq %rdi, 0x15661(%rip)     # 0x196a8
movl $0xf, 0x15647(%rip)     # 0x19698
jmp 0x41a5
movzbl 0x1(%rdi), %eax
cmpl $0x6e, %eax
je 0x4080
cmpl $0x66, %eax
jne 0x410a
movsbq 0x2(%rdi), %rcx
testb $0x6, (%rcx,%r14)
je 0x41c0
cmpb $0x6e, %al
jne 0x410a
cmpb $0x74, 0x2(%rdi)
jne 0x410a
movsbq 0x3(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x3, %rdi
movq %rdi, 0x15607(%rip)     # 0x196a8
movl $0x6, 0x155ed(%rip)     # 0x19698
jmp 0x41a5
cmpb $0x6c, 0x1(%rdi)
jne 0x410a
cmpb $0x61, 0x2(%rdi)
jne 0x410a
cmpb $0x73, 0x3(%rdi)
jne 0x410a
cmpb $0x73, 0x4(%rdi)
jne 0x410a
movsbq 0x5(%rdi), %rax
testb $0x6, (%rax,%r14)
jne 0x410a
addq $0x5, %rdi
movq %rdi, 0x155c9(%rip)     # 0x196a8
movl $0x16, 0x155af(%rip)    # 0x19698
jmp 0x41a5
cmpb $0x65, 0x1(%rdi)
jne 0x410a
cmpb $0x77, 0x2(%rdi)
jne 0x410a
movsbq 0x3(%rdi), %rax
testb $0x6, (%rax,%r14)
je 0x41d7
movq 0x15597(%rip), %rsi     # 0x196a8
movsbq (%rsi), %rax
testb $0x6, (%rax,%r14)
je 0x4132
movsbq 0x1(%rsi), %rax
incq %rsi
testb $0x6, (%rax,%r14)
jne 0x411c
movq %rsi, 0x15576(%rip)     # 0x196a8
callq 0x824d
movq %rax, 0x15562(%rip)     # 0x196a0
movl $0x8, 0x15550(%rip)     # 0x19698
jmp 0x41a5
movl $0x23, %eax
jmp 0x4195
movl $0x22, %eax
jmp 0x4195
movl $0x21, %eax
jmp 0x4195
movl $0x19, %eax
jmp 0x4195
movl $0x1e, %eax
jmp 0x4195
movl $0x1c, %eax
jmp 0x4195
movl $0x20, %eax
jmp 0x4195
movl $0x18, %eax
jmp 0x4195
movl $0x24, %eax
jmp 0x4195
movl $0x7, %eax
jmp 0x4195
movl $0x1, %eax
movl %eax, 0x154fd(%rip)     # 0x19698
incq %rdi
movq %rdi, 0x15503(%rip)     # 0x196a8
popq %rbx
popq %r14
popq %r15
retq
leaq 0xc8de(%rip), %rdi      # 0x10a90
callq 0x39b8
incq 0x154ea(%rip)           # 0x196a8
jmp 0x41a5
addq $0x2, %rdi
movq %rdi, 0x154dd(%rip)     # 0x196a8
movl $0x9, 0x154c3(%rip)     # 0x19698
jmp 0x41a5
addq $0x3, %rdi
movq %rdi, 0x154c6(%rip)     # 0x196a8
movl $0x15, 0x154ac(%rip)    # 0x19698
jmp 0x41a5
addq $0x4, %rdi
movq %rdi, 0x154af(%rip)     # 0x196a8
movl $0x12, 0x15495(%rip)    # 0x19698
jmp 0x41a5
addq $0x4, %rdi
movq %rdi, 0x15498(%rip)     # 0x196a8
movl $0xd, 0x1547e(%rip)     # 0x19698
jmp 0x41a5
addq $0x6, %rdi
movq %rdi, 0x15481(%rip)     # 0x196a8
movl $0x11, 0x15467(%rip)    # 0x19698
jmp 0x41a5
movl 0x15454(%rip), %esi     # 0x19690
movsbl %al, %edi
callq 0x4274
movsbl %al, %esi
leaq 0xc877(%rip), %rdi      # 0x10ac5
xorl %eax, %eax
callq 0x2030
leaq 0xe456(%rip), %rdi      # 0x126b2
leaq 0xc866(%rip), %rsi      # 0x10ac9
leaq 0xc867(%rip), %rcx      # 0x10ad1
movl $0x18b, %edx            # imm = 0x18B
callq 0x20b0