// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
movq %rcx, %r14
movq %rdi, %rbx
movl %esi, (%rdi)
movl %edx, 0x4(%rdi)
movq %rcx, %rdi
callq 0x6110
xorl %ecx, %ecx
testl %eax, %eax
movl %eax, %edx
cmovlel %ecx, %edx
cmpq %rcx, %rdx
je 0x6bf4
cmpb $0x5f, (%r14,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x6b87
decl %eax
cltq
pushq $0x1
popq %rdx
xorl %ecx, %ecx
movsbl (%r14,%rax), %esi
cmpl $0x5f, %esi
je 0x6bbd
addl $-0x30, %esi
imull %edx, %esi
addl %esi, %ecx
imull $0xa, %edx, %edx
decq %rax
cmpl $0x25, %ecx
jl 0x6ba0
andl $0x0, 0x8(%rbx)
cmpl $0x25, %ecx
setl %dl
testl %ecx, %ecx
setne %sil
testb %sil, %dl
jne 0x6c3b
leaq 0x31827(%rip), %r14     # 0x38400
movq (%r14), %rdi
addq $0x48, %rdi
leaq 0x1c422(%rip), %rsi     # 0x23009
callq 0x62b0
movq (%r14), %rdi
jmp 0x6c88
movl %eax, %ecx
pushq $0x1
popq %rdx
xorl %esi, %esi
xorl %eax, %eax
testl %ecx, %ecx
jle 0x6c30
movb -0x1(%r14,%rcx), %dil
decq %rcx
addb $-0x30, %dil
cmpb $0xa, %dil
movzbl %dil, %edi
cmovael %esi, %edi
movsbl %dil, %edi
imull %edx, %edi
movslq %edi, %rdi
addq %rdi, %rax
imull $0xa, %edx, %edx
testq $-0x80000000, %rax      # imm = 0x80000000
je 0x6bfd
movl %eax, 0x8(%rbx)
cmpl $-0x1, %eax
setne %cl
jmp 0x6c44
cmpl $0x1, %ecx
jne 0x6ca5
cltq
movb $0x1, %cl
testb %cl, %cl
je 0x6c98
movq %rax, %rdx
shrq $0x1f, %rdx
je 0x6c98
leaq 0x317a8(%rip), %r15     # 0x38400
movq (%r15), %rdi
addq $0x48, %rdi
leaq 0x1c3d9(%rip), %rsi     # 0x2303f
callq 0x62b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x62b0
leaq 0x1c3d5(%rip), %rsi     # 0x23052
movq %rax, %rdi
callq 0x62b0
movq (%r15), %rdi
movl (%rbx), %esi
movl 0x4(%rbx), %edx
callq 0x16112
orl $-0x1, 0x8(%rbx)
jmp 0x6c9f
testb %cl, %cl
je 0x6c9f
movl %eax, 0x8(%rbx)
popq %rbx
popq %r14
popq %r15
retq
movl %eax, %edx
pushq $0x1
popq %rsi
xorl %eax, %eax
testl %edx, %edx
jle 0x6c9c
movsbl -0x1(%r14,%rdx), %edi
leal -0x30(%rdi), %r8d
cmpb $0x9, %r8b
jbe 0x6cca
leal -0x41(%rdi), %r8d
cmpb $0x19, %r8b
ja 0x6cd0
movzbl %r8b, %edi
jmp 0x6cd3
addl $-0x61, %edi
cmpl %ecx, %edi
jge 0x6c92
imull %esi, %edi
movslq %edi, %rdi
addq %rdi, %rax
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
ja 0x6c42
imull %ecx, %esi
decq %rdx
jmp 0x6cac