// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST/constant_folding.cpp
// Function: AST_un_op::constant_folding()
AST_expression* AST_un_op::constant_folding(){
    
    if ( typeid(*expr) == typeid(AST_boolean) && oper_type == NOT){
        tokenBoolean* tk = 
                new tokenBoolean(expr->line,expr->column,(char*)"true");
        AST_boolean* sol = new AST_boolean(tk);
        
        sol->value = !((AST_boolean*)expr)->value;
        return sol;
        
    } else if ( typeid(*expr) == typeid(AST_int) && oper_type == NEG){
        tokenInt* tk = 
                new tokenInt(expr->line,expr->column,(char*)"0");
        AST_int* sol = new AST_int(tk);
        
        sol->value = -((AST_int*)expr)->value;
        return sol;
    } else if ( typeid(*expr) == typeid(AST_float) && oper_type == NEG){
        tokenFloat* tk = 
                new tokenFloat(expr->line,expr->column,(char*)"0.0");
        AST_float* sol = new AST_float(tk);
        
        sol->value = -((AST_float*)expr)->value;
        return sol;
    }
    return this;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x50(%rax), %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, %rax
jne 0x12600
callq 0x6420
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rdi
leaq 0x5a9cd(%rip), %rsi     # 0x6cfe0
callq 0x20340
testb $0x1, %al
jne 0x12621
jmp 0x12719
movq 0x48(%rsp), %rax
cmpl $0x1, 0x48(%rax)
jne 0x12719
movl $0xc, %edi
callq 0x6390
movq %rax, %rdi
movq 0x48(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x40(%rsp)
movq 0x50(%rax), %rax
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
leaq 0x3f9a9(%rip), %rcx     # 0x52004
callq 0x6e90
jmp 0x12662
movq 0x40(%rsp), %rax
movq %rax, 0x90(%rsp)
movl $0x50, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x38(%rsp)
movq 0x90(%rsp), %rsi
callq 0x1dab0
jmp 0x12693
movq 0x48(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %rcx, 0x78(%rsp)
movq 0x50(%rax), %rax
movb 0x48(%rax), %cl
xorb $-0x1, %cl
movq 0x78(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x48(%rax)
movq 0x78(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x12980
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
movl $0xc, %esi
callq 0x63a0
jmp 0x12990
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
movl $0x50, %esi
callq 0x63a0
jmp 0x12990
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
jne 0x12732
callq 0x6420
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rdi
leaq 0x5a86b(%rip), %rsi     # 0x6cfb0
callq 0x20340
testb $0x1, %al
jne 0x12753
jmp 0x12841
movq 0x48(%rsp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x12841
movl $0xc, %edi
callq 0x6390
movq %rax, %rdi
movq 0x48(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x28(%rsp)
movq 0x50(%rax), %rax
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
leaq 0x407ba(%rip), %rcx     # 0x52f47
callq 0x6fe0
jmp 0x12794
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
movl $0x50, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rsi
callq 0x1d9a0
jmp 0x127bf
movq 0x48(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, 0x68(%rsp)
movq 0x50(%rax), %rax
xorl %ecx, %ecx
subl 0x48(%rax), %ecx
movq 0x68(%rsp), %rax
movl %ecx, 0x48(%rax)
movq 0x68(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x12980
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
movl $0xc, %esi
callq 0x63a0
jmp 0x12990
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
movl $0x50, %esi
callq 0x63a0
jmp 0x12990
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
jne 0x1285a
callq 0x6420
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rdi
leaq 0x5a75b(%rip), %rsi     # 0x6cfc8
callq 0x20340
testb $0x1, %al
jne 0x1287b
jmp 0x1296f
movq 0x48(%rsp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x1296f
movl $0xc, %edi
callq 0x6390
movq %rax, %rdi
movq 0x48(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x10(%rsp)
movq 0x50(%rax), %rax
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
leaq 0x40690(%rip), %rcx     # 0x52f45
callq 0x6e30
jmp 0x128bc
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x50, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rsi
callq 0x1da20
jmp 0x128e7
movq 0x48(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movq 0x50(%rax), %rax
movss 0x48(%rax), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movq 0x58(%rsp), %rax
movss %xmm0, 0x48(%rax)
movq 0x58(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x12980
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
movl $0xc, %esi
callq 0x63a0
jmp 0x12990
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
movl $0x50, %esi
callq 0x63a0
jmp 0x12990
jmp 0x12971
jmp 0x12973
movq 0x48(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
addq $0xa8, %rsp
retq
movq 0x88(%rsp), %rdi
callq 0x66b0
nopl (%rax)