// File: /workspace/github_cpp_makefile_star2_O3/kelwinfc[P]ci4721-Fernandez-Gyomrey/src/token.cpp
// Function: tokenInt::tokenInt(int, int, char*)
tokenInt::tokenInt(int l, int c, char* num){
    line = l;
    column = c;
    
    int length = strlen(num);
    bool has_underscore = false;
    for (int i=0; i<length; i++){
        if ( num[i] == '_' ){
            has_underscore = true;
            break;
        }
    }
    
    // Previene overflow en el numero
    unsigned long long int number_long = 0;
    
    if ( has_underscore ){
        int i=length-1;
        int base = 0;
        int pow = 1;
        
        while( num[i] != '_' ){
            base += pow*(num[i] - '0');
            pow *= 10;
            i--;
            
            // Previene overflow en la base
            if ( base > 36 ){
                break;
            }
        }
        
        number = 0;
        pow = 1;
        
        if ( base > 36 || base == 0 ){
            logger->buf << "La base debe estar comprendida en el intervalo [0,36]";
            logger->error(line, column);
            number = -1;
        } else if ( base != 1 ){
            i--;
            while( i >= 0 ){
                int diff = 0;
                if ( '0' <= num[i] && num[i] <= '9' ){
                    diff = num[i] - '0';
                } else if ( 'A' <= num[i] && num[i] <= 'Z' ){
                    diff = num[i] - 'A';
                } else {
                    diff = num[i] - 'a';
                }
                
                if ( diff >= base ){
                    number = -1;
                    break;
                } else {
                    number_long += pow*diff;
                    
                    if ( number_long > (long long int)2147483647LL ){
                        break;
                    }
                }
                pow *= base;
                i--;
            }
        } else {
            bool check = true;
            for (int j=0; j<i; j++){
                check = check && ( num[j] == '0' );
            }
            number_long = i;
        }
        
    } else {
        
        int i=length-1;
        int pow=1;
        while( i >= 0 ){
            int diff = 0;
            if ( '0' <= num[i] && num[i] <= '9' ){
                diff = num[i] - '0';
            }
            
            number_long += pow*diff;
            
            if ( number_long > (long long int)2147483647LL ){
                break;
            }
            
            pow *= 10;
            i--;
        }
        number = number_long;
    }
    
    if ( number != -1 && number_long > (long long int)2147483647LL )
    {
        logger->buf << "Constante entera '" << num << "' muy grande.";
        logger->error(line, column);
        
        number = -1;
        
    } else if ( number != -1 ){
        number = (int)number_long;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdi, %rbx
movl %esi, (%rdi)
movl %edx, 0x4(%rdi)
movq %rcx, %rdi
callq 0x6130
testl %eax, %eax
jle 0x6d28
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
cmpb $0x5f, (%r14,%rcx)
je 0x6dde
incq %rcx
cmpq %rcx, %rdx
jne 0x6d13
jmp 0x6d2a
movl %eax, %edx
movl $0x1, %eax
xorl %esi, %esi
xorl %ecx, %ecx
testl %edx, %edx
jle 0x6d69
movb -0x1(%r14,%rdx), %dil
decq %rdx
addb $-0x30, %dil
cmpb $0xa, %dil
movzbl %dil, %edi
cmovael %esi, %edi
movsbl %dil, %edi
imull %eax, %edi
movslq %edi, %rdi
addq %rdi, %rcx
addl %eax, %eax
leal (%rax,%rax,4), %eax
testq $-0x80000000, %rcx      # imm = 0x80000000
je 0x6d33
movl %ecx, 0x8(%rbx)
cmpl $-0x1, %ecx
setne %al
movq %rcx, %rdx
shrq $0x1f, %rdx
sete %dl
movl %eax, %esi
xorb $0x1, %sil
orb %dl, %sil
jne 0x6dce
leaq 0x3867a(%rip), %r12     # 0x3f408
movq (%r12), %r15
addq $0x48, %r15
leaq 0x262a2(%rip), %rsi     # 0x2d03f
movl $0x12, %edx
movq %r15, %rdi
callq 0x6370
testq %r14, %r14
je 0x6e77
movq %r14, %rdi
callq 0x6130
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x6370
jmp 0x6e8f
testb %al, %al
je 0x6eb8
movl %ecx, 0x8(%rbx)
jmp 0x6eb8
movabsq $-0x100000000, %rdi     # imm = 0xFFFFFFFF00000000
movl %eax, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
decl %eax
movq %rsi, %rcx
shlq $0x20, %rcx
addq %rdi, %rcx
movl $0x1, %r8d
xorl %edx, %edx
movsbl -0x1(%r14,%rsi), %r9d
cmpl $0x5f, %r9d
je 0x6e38
addl $-0x30, %r9d
imull %r8d, %r9d
addl %r9d, %edx
addl %r8d, %r8d
leal (%r8,%r8,4), %r8d
decl %eax
addq %rdi, %rcx
decq %rsi
cmpl $0x25, %edx
jl 0x6e04
movl $0x0, 0x8(%rbx)
jmp 0x6e53
movl $0x0, 0x8(%rbx)
testl %edx, %edx
je 0x6e53
cmpl $0x1, %edx
jne 0x6ec4
sarq $0x20, %rcx
movb $0x1, %al
jmp 0x6d72
leaq 0x385ae(%rip), %r14     # 0x3f408
movq (%r14), %rdi
addq $0x48, %rdi
leaq 0x261a1(%rip), %rsi     # 0x2d009
movl $0x35, %edx
callq 0x6370
movq (%r14), %rdi
jmp 0x6ea7
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x6510
leaq 0x261bc(%rip), %rsi     # 0x2d052
movl $0xd, %edx
movq %r15, %rdi
callq 0x6370
movq (%r12), %rdi
movl (%rbx), %esi
movl 0x4(%rbx), %edx
callq 0x1aa40
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpq $0x2, %rsi
jl 0x6f28
leal -0x1(%rax), %ecx
movl %ecx, %esi
addq %r14, %rsi
movl $0x1, %edi
xorl %ecx, %ecx
movsbl (%rsi), %r8d
leal -0x30(%r8), %r9d
cmpb $0x9, %r9b
jbe 0x6ef1
leal -0x41(%r8), %r9d
cmpb $0x19, %r9b
ja 0x6ef7
movzbl %r9b, %r8d
jmp 0x6efb
addl $-0x61, %r8d
cmpl %edx, %r8d
jge 0x6eb1
imull %edi, %r8d
movslq %r8d, %r8
addq %r8, %rcx
cmpq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
ja 0x6e4c
imull %edx, %edi
decl %eax
decq %rsi
testl %eax, %eax
jg 0x6ed9
jmp 0x6dd6
xorl %ecx, %ecx
jmp 0x6dd6
nop