// File: /workspace/github_cpp_makefile_star2_O1/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 0x6d16
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
cmpb $0x5f, (%r14,%rdx)
je 0x6dc3
incq %rdx
cmpq %rdx, %rcx
jne 0x6d03
decl %eax
movl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
testl %eax, %eax
js 0x6d5a
movl %eax, %edi
movb (%r14,%rdi), %dil
addb $-0x30, %dil
cmpb $0xa, %dil
movzbl %dil, %edi
cmovael %edx, %edi
movsbl %dil, %edi
imull %esi, %edi
movslq %edi, %rdi
addq %rdi, %rcx
leal (%rsi,%rsi), %edi
decl %eax
testq $-0x80000000, %rcx      # imm = 0x80000000
jne 0x6d58
leal (%rdi,%rdi,4), %esi
je 0x6d21
movl %ecx, 0x8(%rbx)
movl 0x8(%rbx), %eax
cmpl $-0x1, %eax
je 0x6db5
movq %rcx, %rdx
shrq $0x1f, %rdx
je 0x6db5
leaq 0x3768b(%rip), %r12     # 0x3e400
movq (%r12), %r15
addq $0x48, %r15
leaq 0x252bb(%rip), %rsi     # 0x2c03f
movl $0x12, %edx
movq %r15, %rdi
callq 0x6360
testq %r14, %r14
je 0x6e47
movq %r14, %rdi
callq 0x6130
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x6360
jmp 0x6e5f
cmpl $-0x1, %eax
jne 0x6e86
jmp 0x6e89
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
decq %rax
movl $0x1, %ecx
xorl %edx, %edx
movsbl (%r14,%rax), %esi
cmpl $0x5f, %esi
je 0x6df1
addl $-0x30, %esi
imull %ecx, %esi
addl %esi, %edx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
decq %rax
cmpl $0x25, %edx
jl 0x6dd2
movl $0x0, 0x8(%rbx)
cmpl $0x25, %edx
setl %cl
testl %edx, %edx
setne %sil
testb %sil, %cl
jne 0x6e95
leaq 0x375ec(%rip), %r15     # 0x3e400
movq (%r15), %rdi
addq $0x48, %rdi
leaq 0x251e7(%rip), %rsi     # 0x2c009
movl $0x35, %edx
callq 0x6360
movq (%r15), %rdi
movl (%rbx), %esi
movl 0x4(%rbx), %edx
callq 0x1a9e6
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
xorl %ecx, %ecx
jmp 0x6d5d
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x6500
leaq 0x251ec(%rip), %rsi     # 0x2c052
movl $0xd, %edx
movq %r15, %rdi
callq 0x6360
movq (%r12), %rdi
movl (%rbx), %esi
movl 0x4(%rbx), %edx
callq 0x1a9e6
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpl $0x1, %edx
jne 0x6ea2
movslq %eax, %rcx
jmp 0x6d5d
decl %eax
movl $0x1, %esi
xorl %ecx, %ecx
testl %eax, %eax
js 0x6d5d
movl %eax, %edi
movsbl (%r14,%rdi), %edi
leal -0x30(%rdi), %r8d
cmpb $0x9, %r8b
ja 0x6ece
addb $-0x30, %dil
movzbl %dil, %edi
jmp 0x6ee0
leal -0x41(%rdi), %r8d
cmpb $0x19, %r8b
ja 0x6edd
addl $-0x41, %edi
jmp 0x6ee0
addl $-0x61, %edi
cmpl %edx, %edi
jge 0x6f00
imull %esi, %edi
movslq %edi, %rdi
addq %rdi, %rcx
cmpq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
ja 0x6f07
imull %edx, %esi
decl %eax
movb $0x1, %dil
jmp 0x6f09
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
xorl %edi, %edi
testb %dil, %dil
jne 0x6eab
jmp 0x6d5d
nop