// File: Wheatwizard[P]Waldo/Reactor.cpp
// Function: Reactor::handleInstruction(unsigned int)
void Reactor::handleInstruction(unsigned waldo) {
	Waldo& cur_waldo = waldos[waldo];
	Instruction instr = board[cur_waldo.getRow()][cur_waldo.getCol()].getInstruction(waldo);
	switch(instr.getVariety()) {
		case NO_INSTRUCTION:
			break;
		case BOND:
			bond();
			break;
		case DEBOND:
			debond();
			break;
		case FUSE:
			fuse();
			break;
		case SPLIT:
			split();
			break;
		case GRAB:
			cur_waldo.grab(*this);
			break;
		case DROP:
			cur_waldo.drop();
			break;
		case GRAB_DROP:
			cur_waldo.grabDrop(*this);
			break;
		case ROTATE:
			cur_waldo.rotate(*this, instr.getRotation());
			break;
		case SYNC:
			cur_waldo.sync(*this);
			break;
		case FLIP_FLOP:
			if (instr.isActive()) {
				cur_waldo.setDirection(instr.getDirection());
			}
			instr.flip();
			break;
		case SENSE:
			//Check that the sensor location is proper
			//Will be improper when unitialized
			if (!positionOnBoard(sensorx, sensory)) {throw 14;}

			//Check that there is a mat at the location
			if (board[sensorx][sensory].getMat() == SENSOR) {break;}

			//Check that the right atom is on the mat
			if (board[sensorx][sensory].getAtom() &&
			   *board[sensorx][sensory].getAtom() == instr.getAtom()) {
				cur_waldo.setDirection(instr.getDirection());
			}
			break;
		default:
			throw 1000000000;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x20(%rax), %rcx
movl -0xc(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movq %rcx, -0x18(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6620
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6640
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdi
movl -0xc(%rbp), %esi
callq 0x6f30
movl %eax, -0x1c(%rbp)
leaq -0x1c(%rbp), %rdi
callq 0x6660
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0xb, %eax
ja 0x58e5
movq -0x28(%rbp), %rax
leaq 0x59b3(%rip), %rcx      # 0xb0d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x5908
movq -0x40(%rbp), %rdi
callq 0x5910
jmp 0x5908
movq -0x40(%rbp), %rdi
callq 0x59b0
jmp 0x5908
movq -0x40(%rbp), %rdi
callq 0x5a50
jmp 0x5908
movq -0x40(%rbp), %rdi
callq 0x5cc0
jmp 0x5908
movq -0x40(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x78b0
jmp 0x5908
movq -0x18(%rbp), %rdi
callq 0x7890
jmp 0x5908
movq -0x40(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x7900
jmp 0x5908
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x1c(%rbp), %rdi
callq 0x6670
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl %eax, %edx
callq 0x7ba0
jmp 0x5908
movq -0x40(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x7800
jmp 0x5908
leaq -0x1c(%rbp), %rdi
callq 0x6680
testb $0x1, %al
jne 0x57df
jmp 0x57fb
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x1c(%rbp), %rdi
callq 0x6690
movq -0x50(%rbp), %rdi
movl %eax, %esi
callq 0x7c00
leaq -0x1c(%rbp), %rdi
callq 0x66a0
jmp 0x5908
movq -0x40(%rbp), %rdi
movl 0x10(%rdi), %esi
movl 0x14(%rdi), %edx
callq 0x5650
testb $0x1, %al
jne 0x583f
movl $0x4, %edi
callq 0x20d0
movq %rax, %rdi
movl $0xe, (%rdi)
movq 0xb76a(%rip), %rsi      # 0x10fa0
xorl %eax, %eax
movl %eax, %edx
callq 0x2280
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rcx
movl 0x10(%rax), %edx
movq (%rcx,%rdx,8), %rdi
movl 0x14(%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x6fb0
cmpl $0x2, %eax
jne 0x5867
jmp 0x5908
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rcx
movl 0x10(%rax), %edx
movq (%rcx,%rdx,8), %rdi
movl 0x14(%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x6f90
cmpq $0x0, %rax
je 0x58e3
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rcx
movl 0x10(%rax), %edx
movq (%rcx,%rdx,8), %rdi
movl 0x14(%rax), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x6f90
movq %rax, -0x58(%rbp)
leaq -0x1c(%rbp), %rdi
callq 0x66d0
movq -0x58(%rbp), %rdi
movl %eax, %esi
callq 0x66b0
testb $0x1, %al
jne 0x58c7
jmp 0x58e3
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x1c(%rbp), %rdi
callq 0x6690
movq -0x60(%rbp), %rdi
movl %eax, %esi
callq 0x7c00
jmp 0x5908
movl $0x4, %edi
callq 0x20d0
movq %rax, %rdi
movl $0x3b9aca00, (%rdi)     # imm = 0x3B9ACA00
movq 0xb6a1(%rip), %rsi      # 0x10fa0
xorl %eax, %eax
movl %eax, %edx
callq 0x2280
addq $0x60, %rsp
popq %rbp
retq
nop