// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movq %rdi, %r14
movq 0x18(%rdi), %rax
movq 0x20(%rdi), %rbx
movl %esi, %r15d
shlq $0x6, %r15
movl 0x20(%rbx,%r15), %ecx
movl 0x24(%rbx,%r15), %edx
imulq $0x28, %rdx, %rdi
addq (%rax,%rcx,8), %rdi
callq 0x3bfa
cmpl $0xb, %eax
ja 0x32ed
addq %r15, %rbx
movl %eax, %eax
leaq 0x1ef7(%rip), %rcx      # 0x50d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
popq %rbx
popq %r14
popq %r15
retq
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x4054
movl 0x10(%r14), %eax
cmpl %eax, 0x4(%r14)
jbe 0x32fd
movl 0x14(%r14), %ecx
cmpl %ecx, (%r14)
jbe 0x32fd
movq 0x18(%r14), %rdx
imulq $0x28, %rcx, %rdi
addq (%rdx,%rax,8), %rdi
callq 0x3c2c
cmpl $0x2, %eax
je 0x31e2
movq 0x18(%r14), %rax
movl 0x10(%r14), %ecx
movl 0x14(%r14), %edx
imulq $0x28, %rdx, %rdi
addq (%rax,%rcx,8), %rdi
callq 0x3c26
testq %rax, %rax
je 0x31e2
movq 0x18(%r14), %rax
movl 0x10(%r14), %ecx
movl 0x14(%r14), %edx
imulq $0x28, %rdx, %rdi
addq (%rax,%rcx,8), %rdi
callq 0x3c26
cmpl $0x0, 0x4(%rax)
jne 0x31e2
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %r15
jmp 0x4228
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x353a
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x41e4
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3372
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x331c
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x33c8
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x404e
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x4004
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x407c
pushq $0x4
popq %rdi
callq 0x20b0
movl $0x3b9aca00, (%rax)     # imm = 0x3B9ACA00
jmp 0x330b
pushq $0x4
popq %rdi
callq 0x20b0
movl $0xe, (%rax)
movq 0x5c8e(%rip), %rsi      # 0x8fa0
movq %rax, %rdi
xorl %edx, %edx
callq 0x21e0