// File: /workspace/github_cpp_makefile_star2_O2/baziotis[P]minijava-cpp/lex.cpp
// Function: scan_int()
void scan_int() {
    token.kind = TOK::INTLIT;
    // Find base
    int base = 10;
    if (*input == '0') {
        ++input;
        if (tolower(*input) == 'x') {
            base = 16;
            ++input;
            if (!(charmap[*input]&HEX)) {
                syntax_error("Invalid hex integer literal.");
                return;
            }
        } else if (charmap[*input]&OCT) {
            base = 8;
        } else if (charmap[*input]&(DEC|HEX)) {
            syntax_error("Invalid octal integer literal.");
            token.kind = TOK::INTLIT;
            token.val = 0;
            return;
        }
    }

    // Compute value.
    int val = 0;
    while (true) {
        int digit = digit_from_char[tolower(*input)];
        if (digit == 0 && *input != '0') {
            break;
        }
        if (digit >= base) {
            syntax_error("Digit `", *input, "` out of range for base ", base);
            break;
        }
        // You can choose to either continue on overflow
        // or eat the remaining digits and set a standard value
        // like 0.
        constexpr int int_max = std::numeric_limits<int>::max();
        if (val > (int_max - digit) / 10) {
            warning("Integer literal overflow.");
            // eat remaining digits
            digit = digit_from_char[*input];
            for(;;) {
                if(charmap[*input]&DEC) {
                    ++input;
                } else {
                    digit = digit_from_char[*input];
                    if(digit != 0 && digit < base) {
                        ++input;
                    } else {
                        break;
                    }
                }
            }
            val = int_max;
            break;
        }
        val = val * base + digit;
        ++input;
    }
    token.val = val;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x2, 0x153af(%rip)     # 0x18698
movq 0x153b8(%rip), %rbx     # 0x186a8
movb (%rbx), %bpl
pushq $0xa
popq %r14
cmpb $0x30, %bpl
jne 0x3352
leaq 0x1(%rbx), %r15
movq %r15, 0x153a0(%rip)     # 0x186a8
movb 0x1(%rbx), %bpl
movsbl %bpl, %edi
callq 0x2180
cmpl $0x78, %eax
jne 0x335a
leaq 0x2(%rbx), %r15
movq %r15, 0x15383(%rip)     # 0x186a8
movsbq 0x2(%rbx), %rbp
leaq 0x1537f(%rip), %rax     # 0x186b0
testb $0x8, (%rbp,%rax)
jne 0x3396
leaq 0xb606(%rip), %rdi      # 0xe945
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x349e
movq %rbx, %r15
movl %r14d, %ebx
jmp 0x339d
movsbq %bpl, %rax
leaq 0x1534b(%rip), %rcx     # 0x186b0
movzbl (%rax,%rcx), %eax
testb $0x10, %al
jne 0x339a
movl %r14d, %ebx
testb $0xc, %al
je 0x339d
leaq 0xb5e7(%rip), %rdi      # 0xe962
callq 0x349e
movl $0x2, 0x1530e(%rip)     # 0x18698
andl $0x0, 0x1530f(%rip)     # 0x186a0
jmp 0x3447
pushq $0x10
jmp 0x339c
pushq $0x8
popq %rbx
incq %r15
xorl %r12d, %r12d
leaq 0x15406(%rip), %r13     # 0x187b0
movsbl %bpl, %ebp
movl %ebp, %edi
callq 0x2180
cltq
movzwl (%r13,%rax,2), %eax
cmpb $0x30, %bpl
je 0x33c8
testw %ax, %ax
je 0x3440
movzwl %ax, %ecx
cmpl %ecx, %ebx
jbe 0x33f6
movl %ecx, %eax
xorl $0x7ffffffe, %eax       # imm = 0x7FFFFFFE
xorl %edx, %edx
divl %r14d
cmpl %eax, %r12d
jg 0x3456
imull %ebx, %r12d
addl %ecx, %r12d
movq %r15, 0x152ba(%rip)     # 0x186a8
movb (%r15), %bpl
incq %r15
jmp 0x33aa
movl 0x15294(%rip), %edi     # 0x18690
callq 0x41c3
callq 0x41dd
callq 0x41f9
leaq 0xb824(%rip), %rdi      # 0xec36
callq 0x4215
callq 0x4226
callq 0x4242
leaq 0xb559(%rip), %rdi      # 0xe981
leaq 0xb55a(%rip), %rdx      # 0xe989
movl %ebp, %esi
movl %ebx, %ecx
callq 0x425e
pushq $0xa
popq %rdi
callq 0x2160
movl %r12d, 0x15259(%rip)    # 0x186a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb545(%rip), %rdi      # 0xe9a2
callq 0x34de
movq 0x1523f(%rip), %rax     # 0x186a8
incq %rax
leaq 0x1523d(%rip), %rcx     # 0x186b0
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movsbq -0x1(%rax), %rdx
testb $0x4, (%rdx,%rcx)
jne 0x3492
movzwl (%r13,%rdx,2), %edx
testl %edx, %edx
je 0x3440
cmpl %edx, %ebx
jbe 0x3440
movq %rax, 0x1520f(%rip)     # 0x186a8
incq %rax
jmp 0x3479