// File: zerolfx[P]P-Machine/xor.cpp
// Function: Xor::execute(StackMachine*)
void Xor::execute(StackMachine *stack)
{
    // check if the stack contains at least two entries
    if(stack->fSP < 1)
        throw ExecutionError("instruction xor: requires 2 stackelements to be present.");

    StackBoolean p1;

    if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
        throw ExecutionError("instruction xor: SP does not point to element of type boolean.");
    if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
        throw ExecutionError("instruction xor: SP - 1 does not point to element of type boolean.");


    // actual xor-operation
    stack->fStore[stack->fSP - 1]->xori(stack->fStore[stack->fSP]);

    // SP := SP - 1
    delete stack->fStore[stack->fSP];
    stack->fStore[stack->fSP] = 0;
    stack->fStore.pop_back();
    --stack->fSP;

    // adding cost of this instruction
    stack->fTime.count("xor");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0xb4(%rax)
jge 0x957c
movb $0x1, -0x45(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0xe0(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x74f0
movq -0xd8(%rbp), %rdx
leaq 0x2dbfe(%rip), %rsi     # 0x370f5
leaq -0x30(%rbp), %rdi
callq 0x8940
jmp 0x9502
movq -0xe0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x283d0
jmp 0x9514
movq -0xe0(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0x4055a(%rip), %rsi     # 0x49a80
leaq 0x1eed3(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x995d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x955a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7170
leaq -0x31(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x45(%rbp)
jne 0x956b
jmp 0x9577
movq -0xe0(%rbp), %rdi
callq 0x71c0
jmp 0x9954
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x27d20
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
cmpq $0x0, %rax
jne 0x95b6
callq 0x7300
jmp 0x95b6
movq -0xe8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x416c5(%rip), %rdi     # 0x4ac90
callq 0x9370
testb $0x1, %al
jne 0x95d9
jmp 0x96a2
movb $0x1, -0x7a(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0xf8(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x74f0
movq -0xf0(%rbp), %rdx
leaq 0x2db22(%rip), %rsi     # 0x3712e
leaq -0x78(%rbp), %rdi
callq 0x8940
jmp 0x9617
movq -0xf8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x283d0
jmp 0x9629
movq -0xf8(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x40445(%rip), %rsi     # 0x49a80
leaq 0x1edbe(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x995d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x994b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x9680
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x7170
leaq -0x79(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x7a(%rbp)
jne 0x9691
jmp 0x969d
movq -0xf8(%rbp), %rdi
callq 0x71c0
jmp 0x994b
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, %rax
jne 0x96d6
callq 0x7300
jmp 0x96d6
movq -0x100(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x415a5(%rip), %rdi     # 0x4ac90
callq 0x9370
testb $0x1, %al
jne 0x96f9
jmp 0x97c9
movb $0x1, -0xa2(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x110(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x74f0
movq -0x108(%rbp), %rdx
leaq 0x2da3b(%rip), %rsi     # 0x3716d
leaq -0xa0(%rbp), %rdi
callq 0x8940
jmp 0x9740
movq -0x110(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x283d0
jmp 0x9755
movq -0x110(%rbp), %rdi
movb $0x0, -0xa2(%rbp)
leaq 0x40316(%rip), %rsi     # 0x49a80
leaq 0x1ec8f(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0x995d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x97a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7170
leaq -0xa1(%rbp), %rdi
callq 0x72e0
testb $0x1, -0xa2(%rbp)
jne 0x97b8
jmp 0x97c4
movq -0x110(%rbp), %rdi
callq 0x71c0
jmp 0x994b
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movl 0xb4(%rax), %eax
decl %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq -0x118(%rbp), %rdi
movq (%rax), %rsi
movq (%rdi), %rax
movq 0x40(%rax), %rax
callq *%rax
jmp 0x981a
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x120(%rbp)
cmpq $0x0, %rax
je 0x985f
movq -0x120(%rbp), %rdi
callq 0x26ca0
movq -0x120(%rbp), %rdi
movl $0x8, %esi
callq 0x7280
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
callq 0x8e90
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %ecx
decl %ecx
movl %ecx, 0xb4(%rax)
movq -0x10(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x130(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x74f0
movq -0x128(%rbp), %rdx
leaq 0x2d8e4(%rip), %rsi     # 0x371b0
leaq -0xc8(%rbp), %rdi
callq 0x8940
jmp 0x98da
movq -0x130(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2c4d0
jmp 0x98ef
leaq -0xc8(%rbp), %rdi
callq 0x7170
leaq -0xc9(%rbp), %rdi
callq 0x72e0
leaq -0x58(%rbp), %rdi
callq 0x27d70
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x993f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7170
leaq -0xc9(%rbp), %rdi
callq 0x72e0
leaq -0x58(%rbp), %rdi
callq 0x27d70
movq -0x40(%rbp), %rdi
callq 0x74e0
nopl (%rax)