// File: 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:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movl %esi, 0x5c(%rsp)
movl %edx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq 0x60(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x6e00
movq 0x8(%rsp), %rax
movl 0x5c(%rsp), %ecx
movl %ecx, (%rax)
movl 0x58(%rsp), %ecx
movl %ecx, 0x4(%rax)
movq 0x50(%rsp), %rdi
callq 0x6180
movl %eax, 0x4c(%rsp)
movb $0x0, 0x4b(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x7065
movq 0x50(%rsp), %rax
movslq 0x44(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5f, %eax
jne 0x7056
movb $0x1, 0x4b(%rsp)
jmp 0x7065
jmp 0x7058
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x7032
movq $0x0, 0x38(%rsp)
testb $0x1, 0x4b(%rsp)
je 0x72d1
movl 0x4c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x1, 0x2c(%rsp)
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5f, %eax
je 0x70e6
movl 0x2c(%rsp), %eax
movq 0x50(%rsp), %rcx
movslq 0x34(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
subl $0x30, %ecx
imull %ecx, %eax
addl 0x30(%rsp), %eax
movl %eax, 0x30(%rsp)
imull $0xa, 0x2c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x34(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x34(%rsp)
cmpl $0x24, 0x30(%rsp)
jle 0x70e4
jmp 0x70e6
jmp 0x7094
movq 0x8(%rsp), %rax
movl $0x0, 0x8(%rax)
movl $0x1, 0x2c(%rsp)
cmpl $0x24, 0x30(%rsp)
jg 0x7108
cmpl $0x0, 0x30(%rsp)
jne 0x7150
leaq 0x673c9(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x38, %rdi
addq $0x10, %rdi
leaq 0x4aee8(%rip), %rsi     # 0x52009
callq 0x6370
movq 0x8(%rsp), %rax
leaq 0x673a6(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl (%rax), %esi
movl 0x4(%rax), %edx
callq 0x2f440
movq 0x8(%rsp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
jmp 0x72cc
cmpl $0x1, 0x30(%rsp)
je 0x726d
movl 0x34(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x34(%rsp)
jl 0x726b
movl $0x0, 0x28(%rsp)
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %ecx
movl $0x30, %eax
cmpl %ecx, %eax
jg 0x71ba
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x39, %eax
jg 0x71ba
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x30, %eax
movl %eax, 0x28(%rsp)
jmp 0x7212
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %ecx
movl $0x41, %eax
cmpl %ecx, %eax
jg 0x71fb
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5a, %eax
jg 0x71fb
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x41, %eax
movl %eax, 0x28(%rsp)
jmp 0x7210
movq 0x50(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x61, %eax
movl %eax, 0x28(%rsp)
jmp 0x7212
movl 0x28(%rsp), %eax
cmpl 0x30(%rsp), %eax
jl 0x722a
movq 0x8(%rsp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
jmp 0x726b
movl 0x2c(%rsp), %eax
imull 0x28(%rsp), %eax
cltq
addq 0x38(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq $0x7fffffff, 0x38(%rsp) # imm = 0x7FFFFFFF
jbe 0x724c
jmp 0x726b
jmp 0x724e
movl 0x30(%rsp), %eax
imull 0x2c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x34(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x7166
jmp 0x72ca
movb $0x1, 0x27(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x72c0
xorl %eax, %eax
testb $0x1, 0x27(%rsp)
movb %al, 0x7(%rsp)
je 0x72a9
movq 0x50(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
sete %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
andb $0x1, %al
movb %al, 0x27(%rsp)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x727a
movslq 0x34(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x72cc
jmp 0x737e
movl 0x4c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x1c(%rsp)
movl $0x1, 0x18(%rsp)
cmpl $0x0, 0x1c(%rsp)
jl 0x7371
movl $0x0, 0x14(%rsp)
movq 0x50(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movsbl (%rax,%rcx), %ecx
movl $0x30, %eax
cmpl %ecx, %eax
jg 0x7336
movq 0x50(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x39, %eax
jg 0x7336
movq 0x50(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x30, %eax
movl %eax, 0x14(%rsp)
movl 0x18(%rsp), %eax
imull 0x14(%rsp), %eax
cltq
addq 0x38(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq $0x7fffffff, 0x38(%rsp) # imm = 0x7FFFFFFF
jbe 0x7358
jmp 0x7371
imull $0xa, 0x18(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x72e4
movq 0x8(%rsp), %rax
movq 0x38(%rsp), %rcx
movl %ecx, 0x8(%rax)
movq 0x8(%rsp), %rax
cmpl $-0x1, 0x8(%rax)
je 0x73f5
cmpq $0x7fffffff, 0x38(%rsp) # imm = 0x7FFFFFFF
jbe 0x73f5
leaq 0x6713d(%rip), %rax     # 0x6e4d8
movq (%rax), %rdi
addq $0x38, %rdi
addq $0x10, %rdi
leaq 0x4ac92(%rip), %rsi     # 0x5203f
callq 0x6370
movq %rax, %rdi
movq 0x50(%rsp), %rsi
callq 0x6370
movq %rax, %rdi
leaq 0x4ac89(%rip), %rsi     # 0x52052
callq 0x6370
movq 0x8(%rsp), %rax
leaq 0x670fe(%rip), %rcx     # 0x6e4d8
movq (%rcx), %rdi
movl (%rax), %esi
movl 0x4(%rax), %edx
callq 0x2f440
movq 0x8(%rsp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
jmp 0x740f
movq 0x8(%rsp), %rax
cmpl $-0x1, 0x8(%rax)
je 0x740d
movq 0x8(%rsp), %rax
movq 0x38(%rsp), %rcx
movl %ecx, 0x8(%rax)
jmp 0x740f
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)