// File: zerolfx[P]P-Machine/and.cpp
// Function: And::execute(StackMachine*)
void And::execute(StackMachine *stack) 
{
	// check if the stack contains at least two entries
	if(stack->fSP < 1)
		throw ExecutionError("instruction and: requires 2 stackelements to be present.");
		
	StackBoolean p1;
	
	if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
		throw ExecutionError("instruction and: SP does not point to element of type boolean.");
	if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
		throw ExecutionError("instruction and: SP - 1 does not point to element of type boolean.");

	
	// actual and-operation
	stack->fStore[stack->fSP - 1]->andi(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("add");	
}

// 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 0xa3bc
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 0x2cfed(%rip), %rsi     # 0x37324
leaq -0x30(%rbp), %rdi
callq 0x8940
jmp 0xa342
movq -0xe0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x283d0
jmp 0xa354
movq -0xe0(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0x3f71a(%rip), %rsi     # 0x49a80
leaq 0x1e093(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0xa79d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa39a
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 0xa3ab
jmp 0xa3b7
movq -0xe0(%rbp), %rdi
callq 0x71c0
jmp 0xa794
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 0xa3f6
callq 0x7300
jmp 0xa3f6
movq -0xe8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x40885(%rip), %rdi     # 0x4ac90
callq 0x9370
testb $0x1, %al
jne 0xa419
jmp 0xa4e2
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 0x2cf11(%rip), %rsi     # 0x3735d
leaq -0x78(%rbp), %rdi
callq 0x8940
jmp 0xa457
movq -0xf8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x283d0
jmp 0xa469
movq -0xf8(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x3f605(%rip), %rsi     # 0x49a80
leaq 0x1df7e(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0xa79d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa78b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa4c0
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 0xa4d1
jmp 0xa4dd
movq -0xf8(%rbp), %rdi
callq 0x71c0
jmp 0xa78b
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 0xa516
callq 0x7300
jmp 0xa516
movq -0x100(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x40765(%rip), %rdi     # 0x4ac90
callq 0x9370
testb $0x1, %al
jne 0xa539
jmp 0xa609
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 0x2ce2a(%rip), %rsi     # 0x3739c
leaq -0xa0(%rbp), %rdi
callq 0x8940
jmp 0xa580
movq -0x110(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x283d0
jmp 0xa595
movq -0x110(%rbp), %rdi
movb $0x0, -0xa2(%rbp)
leaq 0x3f4d6(%rip), %rsi     # 0x49a80
leaq 0x1de4f(%rip), %rdx     # 0x28400
callq 0x74a0
jmp 0xa79d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa5e1
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 0xa5f8
jmp 0xa604
movq -0x110(%rbp), %rdi
callq 0x71c0
jmp 0xa78b
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 0x30(%rax), %rax
callq *%rax
jmp 0xa65a
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 0xa69f
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 0x2cc0a(%rip), %rsi     # 0x37316
leaq -0xc8(%rbp), %rdi
callq 0x8940
jmp 0xa71a
movq -0x130(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2c4d0
jmp 0xa72f
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 0xa77f
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)