// File: /workspace/github_cpp_makefile_star2_O1/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, 0x15fe7(%rip)     # 0x19698
movq 0x15ff0(%rip), %r14     # 0x196a8
movl $0xa, %ebx
cmpb $0x30, (%r14)
jne 0x3764
leaq 0x1(%r14), %rax
movq %rax, 0x15fd6(%rip)     # 0x196a8
movsbl 0x1(%r14), %ebx
movl %ebx, %edi
callq 0x2180
cmpl $0x78, %eax
jne 0x371f
leaq 0x2(%r14), %rax
movq %rax, 0x15fba(%rip)     # 0x196a8
movsbq 0x2(%r14), %rax
leaq 0x15fb6(%rip), %rcx     # 0x196b0
movl $0x10, %ebx
testb $0x8, (%rax,%rcx)
jne 0x3764
leaq 0xd2e9(%rip), %rdi      # 0x109f5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3901
movslq %ebx, %rax
leaq 0x15f87(%rip), %rcx     # 0x196b0
movzbl (%rax,%rcx), %eax
movl $0x8, %ebx
testb $0x10, %al
jne 0x3764
movl $0xa, %ebx
testb $0xc, %al
je 0x3764
leaq 0xd2cc(%rip), %rdi      # 0x10a12
callq 0x3901
movl $0x2, 0x15f43(%rip)     # 0x19698
movl $0x0, 0x15f41(%rip)     # 0x196a0
jmp 0x38f2
leaq 0x16045(%rip), %r14     # 0x197b0
leaq 0x15f3e(%rip), %r12     # 0x196b0
xorl %r15d, %r15d
movq 0x15f2c(%rip), %r13     # 0x196a8
movsbl (%r13), %ebp
movl %ebp, %edi
callq 0x2180
cltq
movzwl (%r14,%rax,2), %eax
cmpl $0x30, %ebp
je 0x379d
testw %ax, %ax
je 0x38ca
movzwl %ax, %eax
cmpl %eax, %ebx
jbe 0x3808
movl %eax, %ecx
xorl $0x7ffffffe, %ecx       # imm = 0x7FFFFFFE
imulq $0x66666667, %rcx, %rcx # imm = 0x66666667
shrq $0x22, %rcx
cmpl %ecx, %r15d
jle 0x38d6
leaq 0xd28b(%rip), %rdi      # 0x10a52
callq 0x39b8
movq 0x15ed5(%rip), %rcx     # 0x196a8
incq %rcx
movsbq -0x1(%rcx), %rax
testb $0x4, (%rax,%r12)
jne 0x37ff
movzwl (%r14,%rax,2), %edx
xorl %eax, %eax
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
testl %edx, %edx
je 0x38cc
cmpl %edx, %ebx
jbe 0x38cc
movq %rcx, 0x15ea2(%rip)     # 0x196a8
jmp 0x37d3
movl 0x15e82(%rip), %edx     # 0x19690
leaq 0x1622b(%rip), %rax     # 0x19a40
movq (%rax), %rsi
leaq 0xd4d7(%rip), %rdi      # 0x10cf6
xorl %eax, %eax
callq 0x2030
leaq 0x1620b(%rip), %rax     # 0x19a38
cmpb $0x1, 0x1(%rax)
jne 0x3841
leaq 0xccc5(%rip), %rdi      # 0x104ff
xorl %eax, %eax
callq 0x2030
leaq 0x161f0(%rip), %rax     # 0x19a38
cmpb $0x1, 0x1(%rax)
jne 0x385c
leaq 0xd4aa(%rip), %rdi      # 0x10cff
xorl %eax, %eax
callq 0x2030
leaq 0xcb51(%rip), %rdi      # 0x103b4
leaq 0xd47c(%rip), %rsi      # 0x10ce6
xorl %eax, %eax
callq 0x2030
leaq 0x161c0(%rip), %rax     # 0x19a38
cmpb $0x1, 0x1(%rax)
jne 0x388c
leaq 0xcc80(%rip), %rdi      # 0x10505
xorl %eax, %eax
callq 0x2030
leaq 0x161a5(%rip), %rax     # 0x19a38
cmpb $0x1, 0x1(%rax)
jne 0x38a7
leaq 0xcc65(%rip), %rdi      # 0x10505
xorl %eax, %eax
callq 0x2030
movsbl %bpl, %esi
leaq 0xd17f(%rip), %rdi      # 0x10a31
leaq 0xd180(%rip), %rdx      # 0x10a39
movl %ebx, %ecx
callq 0x46e0
movl $0xa, %edi
callq 0x2160
xorl %eax, %eax
testb %al, %al
jne 0x3775
jmp 0x38eb
imull %ebx, %r15d
addl %eax, %r15d
incq %r13
movq %r13, 0x15dc1(%rip)     # 0x196a8
movb $0x1, %al
jmp 0x38cc
movl %r15d, 0x15dae(%rip)    # 0x196a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq