// File: /workspace/github_cpp_makefile_star2_O3/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, 0x16fef(%rip)     # 0x1a698
movq 0x16ff8(%rip), %r12     # 0x1a6a8
movb (%r12), %r14b
movl $0xa, %ebx
cmpb $0x30, %r14b
jne 0x3720
leaq 0x1(%r12), %r15
movq %r15, 0x16fdd(%rip)     # 0x1a6a8
movb 0x1(%r12), %r14b
movsbl %r14b, %edi
callq 0x2180
cmpl $0x78, %eax
jne 0x387b
leaq 0x2(%r12), %r15
movq %r15, 0x16fba(%rip)     # 0x1a6a8
movsbq 0x2(%r12), %r14
leaq 0x16fb5(%rip), %rax     # 0x1a6b0
testb $0x8, (%r14,%rax)
jne 0x38b8
leaq 0xe264(%rip), %rdi      # 0x11971
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x391a
movq %r12, %r15
movsbl %r14b, %ebp
movl %ebp, %edi
callq 0x2180
cltq
leaq 0x17079(%rip), %r12     # 0x1a7b0
movzwl (%r12,%rax,2), %eax
cmpb $0x30, %bpl
je 0x374d
xorl %ebp, %ebp
testw %ax, %ax
je 0x3866
movzwl %ax, %eax
xorl %ebp, %ebp
cmpl %eax, %ebx
jbe 0x37b1
incq %r15
xorl %ebp, %ebp
movl $0xcccccccd, %r13d      # imm = 0xCCCCCCCD
movl %eax, %ecx
xorl $0x7ffffffe, %ecx       # imm = 0x7FFFFFFE
imulq %r13, %rcx
shrq $0x23, %rcx
cmpl %ecx, %ebp
jg 0x38cc
imull %ebx, %ebp
addl %eax, %ebp
movq %r15, 0x16f23(%rip)     # 0x1a6a8
movsbl (%r15), %r14d
movl %r14d, %edi
callq 0x2180
cltq
movzwl (%r12,%rax,2), %eax
cmpl $0x30, %r14d
je 0x37a7
testw %ax, %ax
je 0x3866
movzwl %ax, %eax
incq %r15
cmpl %eax, %ebx
ja 0x3761
movl 0x16ed9(%rip), %edx     # 0x1a690
leaq 0x17282(%rip), %rax     # 0x1aa40
movq (%rax), %rsi
leaq 0xe4aa(%rip), %rdi      # 0x11c72
xorl %eax, %eax
callq 0x2030
leaq 0x17262(%rip), %r15     # 0x1aa38
movb 0x1(%r15), %al
cmpb $0x1, %al
jne 0x37f0
leaq 0xdd1a(%rip), %rdi      # 0x114ff
xorl %eax, %eax
callq 0x2030
movb 0x1(%r15), %al
testb $0x1, %al
je 0x3802
leaq 0xe480(%rip), %rdi      # 0x11c7b
xorl %eax, %eax
callq 0x2030
leaq 0xdbab(%rip), %rdi      # 0x113b4
leaq 0xe452(%rip), %rsi      # 0x11c62
xorl %eax, %eax
callq 0x2030
movb 0x1(%r15), %al
cmpb $0x1, %al
jne 0x3831
leaq 0xdcdf(%rip), %rdi      # 0x11505
xorl %eax, %eax
callq 0x2030
movb 0x1(%r15), %al
testb $0x1, %al
je 0x3843
leaq 0xdcc9(%rip), %rdi      # 0x11505
xorl %eax, %eax
callq 0x2030
movsbl %r14b, %esi
leaq 0xe15f(%rip), %rdi      # 0x119ad
leaq 0xe160(%rip), %rdx      # 0x119b5
movl %ebx, %ecx
callq 0x46e7
movl $0xa, %edi
callq 0x2160
movl %ebp, 0x16e34(%rip)     # 0x1a6a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbq %r14b, %rax
leaq 0x16e2a(%rip), %rcx     # 0x1a6b0
movzbl (%rax,%rcx), %eax
testb $0x10, %al
jne 0x38c2
testb $0xc, %al
je 0x3723
leaq 0xe0f1(%rip), %rdi      # 0x1198e
callq 0x391a
movl $0x2, 0x16dec(%rip)     # 0x1a698
movl $0x0, 0x16dea(%rip)     # 0x1a6a0
jmp 0x386c
movl $0x10, %ebx
jmp 0x3723
movl $0x8, %ebx
jmp 0x3723
leaq 0xe0fb(%rip), %rdi      # 0x119ce
callq 0x39d5
movq 0x16dc9(%rip), %rax     # 0x1a6a8
incq %rax
leaq 0x16dc7(%rip), %rcx     # 0x1a6b0
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movsbq -0x1(%rax), %rdx
testb $0x4, (%rdx,%rcx)
jne 0x390e
movzwl (%r12,%rdx,2), %edx
testl %edx, %edx
je 0x3866
cmpl %edx, %ebx
jbe 0x3866
movq %rax, 0x16d93(%rip)     # 0x1a6a8
incq %rax
jmp 0x38ee