// File: /workspace/github_cpp_makefile_star2_O3/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
leaq (%rdx,%rdx,4), %rdi
shlq $0x3, %rdi
addq (%rax,%rcx,8), %rdi
callq 0x3dc4
cmpl $0xb, %eax
ja 0x3359
addq %r15, %rbx
movl %eax, %eax
leaq 0x1e99(%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 0x4258
movl 0x10(%r14), %eax
cmpl %eax, 0x4(%r14)
jbe 0x336b
movl 0x14(%r14), %ecx
cmpl %ecx, (%r14)
jbe 0x336b
movq 0x18(%r14), %rdx
leaq (%rcx,%rcx,4), %rdi
shlq $0x3, %rdi
addq (%rdx,%rax,8), %rdi
callq 0x3df8
cmpl $0x2, %eax
je 0x3240
movq 0x18(%r14), %rax
movl 0x10(%r14), %ecx
movl 0x14(%r14), %edx
leaq (%rdx,%rdx,4), %rdi
shlq $0x3, %rdi
addq (%rax,%rcx,8), %rdi
callq 0x3df2
testq %rax, %rax
je 0x3240
movq 0x18(%r14), %rax
movl 0x10(%r14), %ecx
movl 0x14(%r14), %edx
leaq (%rdx,%rdx,4), %rdi
shlq $0x3, %rdi
addq (%rax,%rcx,8), %rdi
callq 0x3df2
cmpl $0x0, 0x4(%rax)
jne 0x3240
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %r15
jmp 0x446c
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3602
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
popq %rbx
popq %r14
popq %r15
jmp 0x4428
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x33f2
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x338c
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3458
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x424e
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x41fc
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x42a2
movl $0x4, %edi
callq 0x2090
movl $0x3b9aca00, (%rax)     # imm = 0x3B9ACA00
jmp 0x337b
movl $0x4, %edi
callq 0x2090
movl $0xe, (%rax)
movq 0x4c1e(%rip), %rsi      # 0x7fa0
movq %rax, %rdi
xorl %edx, %edx
callq 0x21b0