// File: /workspace/github_cpp_makefile_star2_O1/KJTang[P]SimpleCompiler/Lexer.cpp
// Function: Lexer::lexToken()
Token Lexer::lexToken() {
    char curChar = lexingStr[lexingPos++];
    // shift space and '\n'
    while (curChar == ' ' || curChar == '\n') {
        curChar = lexingStr[lexingPos++];
    }
    // identifier
    // def: start with [a-zA-Z_], follow by [a-zA-Z_0-9]
    if (isalpha(curChar) || curChar == '_') {
        std::string identifierName;
        identifierName += curChar;
        curChar = lexingStr[lexingPos++];
        while (isalnum(curChar) || curChar == '_') {
            identifierName += curChar;
            curChar = lexingStr[lexingPos++];
        }
        --lexingPos;
        if (identifierName == "if") {
            tokens.push_back(std::make_pair(Token::KEYWORD_IF, identifierName));
            return Token::KEYWORD_IF;
        } else if (identifierName == "else") {
            tokens.push_back(std::make_pair(Token::KEYWORD_ELSE, identifierName));
            return Token::KEYWORD_ELSE;
        } else if (identifierName == "while") {
            tokens.push_back(std::make_pair(Token::KEYWORD_WHILE, identifierName));
            return Token::KEYWORD_WHILE;
        } else if (identifierName == "int") {
            tokens.push_back(std::make_pair(Token::TYPE_INT, identifierName));
            return Token::TYPE_INT;
        } else if (identifierName == "return") {
            tokens.push_back(std::make_pair(Token::KEYWORD_RET, identifierName));
            return Token::KEYWORD_RET;
        }
        tokens.push_back(std::make_pair(Token::IDENTIFIER, identifierName));
        return Token::IDENTIFIER;
    }
    // number
    // def: start with [0-9.], follow by [0-9.]
    // number only has 'double' type
    if (isdigit(curChar) || curChar == '.') {
        std::string numberStr;
        numberStr += curChar;
        curChar = lexingStr[lexingPos++];
        while (isdigit(curChar) || curChar == '.') {
            numberStr += curChar;
            curChar = lexingStr[lexingPos++];
        }
        --lexingPos;
        tokens.push_back(std::make_pair(Token::NUMBER, numberStr));
        return Token::NUMBER;
    }
    switch (curChar) {
        // end of file
        case '\0': {
            tokens.push_back(std::make_pair(Token::END_OF_FILE, "\0"));
            return Token::END_OF_FILE;
        }
        case '>': {
            if (lexingStr[lexingPos] == '=') {
                tokens.push_back(std::make_pair(Token::OP_GTE, ">="));
                ++lexingPos;
                return Token::OP_GTE;
            }
            goto ASCII;
        }
        case '<': {
            if (lexingStr[lexingPos] == '=') {
                tokens.push_back(std::make_pair(Token::OP_LTE, "<="));
                ++lexingPos;
                return Token::OP_LTE;
            }
            goto ASCII;
        }
        case '=': {
            if (lexingStr[lexingPos] == '=') {
                tokens.push_back(std::make_pair(Token::OP_EQU, "=="));
                ++lexingPos;
                return Token::OP_EQU;
            }
            goto ASCII;
        }
        case '!': {
            if (lexingStr[lexingPos] == '=') {
                tokens.push_back(std::make_pair(Token::OP_NE, "!="));
                ++lexingPos;
                return Token::OP_NE;
            }
            goto ASCII;
        }
        // comment
        // def: start with "//", will comment one line
        case '/': {
            if (lexingStr[lexingPos] == '/') {
                do {
                    curChar = lexingStr[lexingPos++];
                } while (curChar != '\0' && curChar != '\n');
                if (curChar != '\0') {
                    return this->lexToken();
                } else {
                    tokens.push_back(std::make_pair(Token::END_OF_FILE, "\0"));
                    return Token::END_OF_FILE;
                }
            }
            // if not '//', jump to ascii
            goto ASCII;
        }
        // ascii
        default: {
            ASCII:
            tokens.push_back(std::make_pair((Token)curChar, std::string(1, curChar)));
            return (Token)curChar;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
movl 0x20(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x20(%rbx)
movq (%rbx), %r15
movslq %eax, %rcx
movzbl (%r15,%rcx), %r12d
cmpl $0x20, %r12d
je 0x521a
cmpl $0xa, %r12d
jne 0x5224
leal 0x2(%rax), %ecx
movl %ecx, 0x20(%rbx)
incl %eax
jmp 0x5206
movsbl %r12b, %r14d
movl %r14d, %edi
callq 0x32e0
cmpb $0x5f, %r14b
je 0x53d0
testl %eax, %eax
jne 0x53d0
cmpb $0x2e, %r12b
je 0x550f
leal -0x30(%r14), %eax
cmpl $0x9, %eax
jbe 0x550f
cmpb $0x2f, %r12b
jne 0x52e7
movslq 0x20(%rbx), %rax
cmpb $0x2f, (%r15,%rax)
jne 0x5695
movslq 0x20(%rbx), %rax
addq %rax, %r15
incl %eax
movl %eax, 0x20(%rbx)
movzbl (%r15), %ecx
incq %r15
incl %eax
cmpl $0xa, %ecx
je 0x51fa
testl %ecx, %ecx
jne 0x527b
addq $0x28, %rbx
leaq -0x40(%rbp), %rdi
movl $0xffffffff, -0x8(%rdi) # imm = 0xFFFFFFFF
leaq 0x9e9d(%rip), %rsi      # 0xf147
leaq -0x68(%rbp), %rdx
callq 0x30e0
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x52d1
callq 0x31c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movzbl %r12b, %eax
cmpl $0x3b, %eax
jle 0x5365
cmpl $0x3c, %eax
je 0x55e5
cmpl $0x3d, %eax
je 0x563f
cmpl $0x3e, %eax
jne 0x5695
movslq 0x20(%rbx), %rax
cmpb $0x3d, (%r15,%rax)
jne 0x5695
leaq 0x28(%rbx), %r14
leaq -0x40(%rbp), %rdi
movl $0x2, -0x8(%rdi)
leaq 0x9df1(%rip), %rsi      # 0xf121
leaq -0x68(%rbp), %rdx
callq 0x30e0
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x599a
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5357
callq 0x31c0
incl 0x20(%rbx)
movl $0x2, %r14d
jmp 0x52d7
testl %eax, %eax
je 0x5724
cmpl $0x21, %eax
jne 0x5695
movslq 0x20(%rbx), %rax
cmpb $0x3d, (%r15,%rax)
jne 0x5695
leaq 0x28(%rbx), %r14
leaq -0x40(%rbp), %rdi
movl $0x5, -0x8(%rdi)
leaq 0x9d8f(%rip), %rsi      # 0xf12a
leaq -0x68(%rbp), %rdx
callq 0x30e0
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x599a
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x53c2
callq 0x31c0
incl 0x20(%rbx)
movl $0x5, %r14d
jmp 0x52d7
leaq -0x58(%rbp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq -0x68(%rbp), %rdi
movl %r14d, %esi
callq 0x31a0
movslq 0x20(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x20(%rbx)
movq (%rbx), %rcx
movsbl (%rcx,%rax), %r14d
movl %r14d, %edi
callq 0x31f0
cmpl $0x5f, %r14d
je 0x5417
testl %eax, %eax
je 0x544b
leaq -0x68(%rbp), %r15
movsbl %r14b, %esi
movq %r15, %rdi
callq 0x31a0
movslq 0x20(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x20(%rbx)
movq (%rbx), %rcx
movsbl (%rcx,%rax), %r14d
movl %r14d, %edi
callq 0x31f0
cmpl $0x5f, %r14d
je 0x541b
testl %eax, %eax
jne 0x541b
decl 0x20(%rbx)
leaq 0x9cb3(%rip), %rsi      # 0xf108
leaq -0x68(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x5754
leaq 0x9c9e(%rip), %rsi      # 0xf10b
leaq -0x68(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x57a0
leaq 0x9c8b(%rip), %rsi      # 0xf110
leaq -0x68(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x57ec
leaq 0x9c79(%rip), %rsi      # 0xf116
leaq -0x68(%rbp), %rdi
callq 0x30a0
testl %eax, %eax
je 0x5838
leaq 0x9c65(%rip), %rsi      # 0xf11a
leaq -0x68(%rbp), %rdi
callq 0x30a0
leaq -0x40(%rbp), %rdi
testl %eax, %eax
je 0x5881
movl $0x0, -0x8(%rdi)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x42ce
addq $0x28, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x5507
callq 0x31c0
xorl %r14d, %r14d
jmp 0x58c4
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
leaq -0x68(%rbp), %rdi
movl %r14d, %esi
callq 0x31a0
movslq 0x20(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x20(%rbx)
movq (%rbx), %rcx
movsbl (%rcx,%rax), %eax
cmpl $0x2e, %eax
setne %cl
leal -0x30(%rax), %edx
cmpl $0xa, %edx
setae %dl
testb %dl, %cl
jne 0x5588
leaq -0x68(%rbp), %r14
movsbl %al, %esi
movq %r14, %rdi
callq 0x31a0
movslq 0x20(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x20(%rbx)
movq (%rbx), %rcx
movsbl (%rcx,%rax), %eax
cmpl $0x2e, %eax
sete %cl
movl %eax, %edx
addl $-0x30, %edx
cmpl $0xa, %edx
setb %dl
orb %cl, %dl
jne 0x5557
decl 0x20(%rbx)
leaq -0x40(%rbp), %rdi
movl $0x1, -0x8(%rdi)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x42ce
addq $0x28, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x55cc
callq 0x31c0
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x55da
callq 0x31c0
movl $0x1, %r14d
jmp 0x52d7
movslq 0x20(%rbx), %rax
cmpb $0x3d, (%r15,%rax)
jne 0x5695
leaq 0x28(%rbx), %r14
leaq -0x40(%rbp), %rdi
movl $0x3, -0x8(%rdi)
leaq 0x9b1a(%rip), %rsi      # 0xf124
leaq -0x68(%rbp), %rdx
callq 0x30e0
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x599a
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5631
callq 0x31c0
incl 0x20(%rbx)
movl $0x3, %r14d
jmp 0x52d7
movslq 0x20(%rbx), %rax
cmpb $0x3d, (%r15,%rax)
jne 0x5695
leaq 0x28(%rbx), %r14
leaq -0x40(%rbp), %rdi
movl $0x4, -0x8(%rdi)
leaq 0x9ac7(%rip), %rsi      # 0xf127
leaq -0x68(%rbp), %rdx
callq 0x30e0
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x599a
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5687
callq 0x31c0
incl 0x20(%rbx)
movl $0x4, %r14d
jmp 0x52d7
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
leaq -0x68(%rbp), %rdi
movl $0x1, %esi
movl %r14d, %edx
callq 0x3240
addq $0x28, %rbx
leaq -0x30(%rbp), %r12
movl %r14d, -0x18(%r12)
movq %r12, -0x10(%r12)
movq -0x68(%rbp), %rax
cmpq %r15, %rax
je 0x56d7
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x56e0
movups (%r15), %xmm0
movups %xmm0, (%r12)
movq -0x60(%rbp), %rax
leaq -0x48(%rbp), %rsi
movq %rax, 0x10(%rsi)
movq %r15, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x5712
callq 0x31c0
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
jne 0x58d1
jmp 0x52d7
addq $0x28, %rbx
leaq -0x40(%rbp), %rdi
movl $0xffffffff, -0x8(%rdi) # imm = 0xFFFFFFFF
leaq 0x9a0d(%rip), %rsi      # 0xf147
leaq -0x68(%rbp), %rdx
callq 0x30e0
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
jmp 0x52bf
leaq -0x40(%rbp), %rdi
movl $0x6, -0x8(%rdi)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x42ce
addq $0x28, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x5795
callq 0x31c0
movl $0x6, %r14d
jmp 0x58c4
leaq -0x40(%rbp), %rdi
movl $0x7, -0x8(%rdi)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x42ce
addq $0x28, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x57e1
callq 0x31c0
movl $0x7, %r14d
jmp 0x58c4
leaq -0x40(%rbp), %rdi
movl $0x8, -0x8(%rdi)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x42ce
addq $0x28, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x582d
callq 0x31c0
movl $0x8, %r14d
jmp 0x58c4
leaq -0x40(%rbp), %rdi
movl $0xa, -0x8(%rdi)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x42ce
addq $0x28, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x5879
callq 0x31c0
movl $0xa, %r14d
jmp 0x58c4
movl $0x9, -0x8(%rdi)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
callq 0x42ce
addq $0x28, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x599a
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x58be
callq 0x31c0
movl $0x9, %r14d
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x52d7
callq 0x31c0
jmp 0x52d7
jmp 0x58f5
jmp 0x596b
jmp 0x58f5
jmp 0x596b
jmp 0x58f5
jmp 0x596b
jmp 0x58f5
jmp 0x596b
jmp 0x58f5
jmp 0x596b
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x596e
callq 0x31c0
jmp 0x596e
jmp 0x596b
jmp 0x5940
jmp 0x5940
jmp 0x5940
jmp 0x5940
jmp 0x5940
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
jne 0x5934
jmp 0x5955
jmp 0x5952
jmp 0x5952
jmp 0x596b
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x5955
callq 0x31c0
jmp 0x5955
movq %rax, %rbx
jmp 0x5963
movq %rax, %rbx
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x595e
jmp 0x5963
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x5963
callq 0x31c0
movq %rbx, %rdi
callq 0x3330
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
jne 0x595e
jmp 0x5963
nop