// File: /workspace/github_cpp_makefile_star2_O1/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 0x3d26
cmpl $0xb, %eax
ja 0x339b
addq %r15, %rbx
movl %eax, %eax
leaq 0x1e57(%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 0x41b8
movl 0x10(%r14), %eax
cmpl %eax, 0x4(%r14)
jbe 0x33ad
movl 0x14(%r14), %ecx
cmpl %ecx, (%r14)
jbe 0x33ad
movq 0x18(%r14), %rdx
leaq (%rcx,%rcx,4), %rdi
shlq $0x3, %rdi
addq (%rdx,%rax,8), %rdi
callq 0x3d5a
cmpl $0x2, %eax
je 0x3282
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 0x3d54
testq %rax, %rax
je 0x3282
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 0x3d54
cmpl $0x0, 0x4(%rax)
jne 0x3282
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
popq %r14
popq %r15
jmp 0x43cc
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3628
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
popq %rbx
popq %r14
popq %r15
jmp 0x4388
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x342c
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x33ce
movq %r14, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x348a
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x41ae
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x415c
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x4202
movl $0x4, %edi
callq 0x2090
movl $0x3b9aca00, (%rax)     # imm = 0x3B9ACA00
jmp 0x33bd
movl $0x4, %edi
callq 0x2090
movl $0xe, (%rax)
movq 0x4bdc(%rip), %rsi      # 0x7fa0
movq %rax, %rdi
xorl %edx, %edx
callq 0x21b0