// File: /workspace/github_cpp_makefile_star2_O3/jaldhar[P]Lets-Build-a-Simple-Interpreter/calc1.cc
// Function: Interpreter::get_next_token()
Token Interpreter::get_next_token() {
    // Skip leading white space.
    while (_pos < _text.length() && isspace(_text[_pos])) {
        _pos++;
    }

    // is _pos index past the end of _text ?
    // if so, then return ENDOFFILE token because there is no more
    // input left to convert into tokens
    if (_pos >= _text.length()) {
        Token token(TOKENTYPE::ENDOFFILE, 0);
        cerr << token << endl;
        return token;
    }

    // get a character at the position _pos and decide what token to create
    // based on the single character
    char current_char = _text[_pos];

    // if the next characters are digits then convert them to an integer, create
    // an INTEGER token, increment _pos index to point to the next character
    // after the digits, and return the INTEGER token
    if (isdigit(current_char)) {
        long total = 0;
        while (isdigit(_text[_pos])) {
            total *= 10;
            total += (_text[_pos] - '0');
            _pos++;
        }
        Token token(TOKENTYPE::INTEGER, total);
        cerr << token << endl;
        return token;
    }

    if (current_char == '+') {
        Token token(TOKENTYPE::PLUS, '+');
        cerr << token << endl;
        _pos++;
        return token;
    }

    if (current_char == '-') {
        Token token(TOKENTYPE::MINUS, '-');
        cerr << token << endl;
        _pos++;
        return token;
    }

    ostringstream out;
    out << "Error parsing input. Got: " << current_char;
    throw(out.str().c_str());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq (%rdi), %rax
movq 0x8(%rdi), %r12
movq 0x8(%rax), %r14
cmpq %r14, %r12
jae 0x24c7
movq %rdi, %rbx
movq (%rax), %r13
incq %r12
negq %r14
movb -0x1(%r13,%r12), %r15b
movsbl %r15b, %ebp
movl %ebp, %edi
callq 0x2040
testl %eax, %eax
je 0x2528
movq %r12, 0x8(%rbx)
leaq (%r14,%r12), %rax
incq %rax
incq %r12
cmpq $0x1, %rax
jne 0x249f
movq %rsp, %rsi
movl $0x0, (%rsi)
movq $0x0, 0x8(%rsi)
movq 0x2b11(%rip), %rbx      # 0x4ff0
movq %rbx, %rdi
callq 0x2370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
xorl %r14d, %r14d
xorl %eax, %eax
movq %r14, %rdx
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl $-0x30, %ebp
cmpl $0x9, %ebp
ja 0x25a8
xorl %r14d, %r14d
leaq (%r14,%r14,4), %rax
movsbq %r15b, %rcx
leaq (%rcx,%rax,2), %r14
addq $-0x30, %r14
movq %r12, 0x8(%rbx)
movsbl (%r13,%r12), %r15d
movl %r15d, %eax
addl $-0x30, %eax
incq %r12
cmpl $0xa, %eax
jb 0x2533
movq %rsp, %rsi
movl $0x1, (%rsi)
movq %r14, 0x8(%rsi)
movq 0x2a81(%rip), %rbx      # 0x4ff0
movq %rbx, %rdi
callq 0x2370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movl $0x1, %eax
jmp 0x2513
movzbl %r15b, %eax
cmpl $0x2d, %eax
je 0x2615
cmpl $0x2b, %eax
jne 0x2670
movq %rsp, %rsi
movl $0x2, (%rsi)
movq $0x2b, 0x8(%rsi)
movq 0x2a1e(%rip), %r14      # 0x4ff0
movq %r14, %rdi
callq 0x2370
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
incq 0x8(%rbx)
movl $0x2, %eax
movl $0x2b, %r14d
jmp 0x2513
movq %rsp, %rsi
movl $0x3, (%rsi)
movq $0x2d, 0x8(%rsi)
movq 0x29c3(%rip), %r14      # 0x4ff0
movq %r14, %rdi
callq 0x2370
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
incq 0x8(%rbx)
movl $0x3, %eax
movl $0x2d, %r14d
jmp 0x2513
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x2120
leaq 0x9c6(%rip), %rsi       # 0x304a
movl $0x1a, %edx
movq %rbx, %rdi
callq 0x2110
leaq 0x10(%rsp), %rsi
movb %r15b, (%rsi)
leaq 0x30(%rsp), %rdi
movl $0x1, %edx
callq 0x2110
movl $0x8, %edi
callq 0x2080
movq %rax, %r14
leaq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2150
movq 0x10(%rsp), %rax
movq %rax, (%r14)
movq 0x28dd(%rip), %rsi      # 0x4fb0
movq %r14, %rdi
xorl %edx, %edx
callq 0x2170
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x270d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2100
jmp 0x270d
movq %rax, %rbx
movq %r14, %rdi
callq 0x20b0
jmp 0x270d
movq %rax, %rbx
movq 0x28ac(%rip), %rsi      # 0x4fc0
leaq 0x30(%rsp), %rdi
callq 0x2090
leaq 0xa0(%rsp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2180
nop