// File: Wheatwizard[P]Waldo/Tile.cpp
// Function: Tile::bond(Reactor&, unsigned int, unsigned int)
void Tile::bond( Reactor& board, unsigned row, unsigned col) {
	if (mat != BONDER) return;
	if (row > 0 && board[row-1][col].mat == BONDER) {
		Bond& bond = atom->getBond(UP);
		if (bond.getAtom()) {
			++bond;
		} else {
			Atom* otherAtom = board[row-1][col].getAtom();
			bond.setAtom(otherAtom);
			if (atom->getPriority() > otherAtom->getPriority()) {
				atom->setPriority(otherAtom->getPriority());
			}
		}
	}
	if (row+1 < board.getNumRows() && board[row+1][col].mat == BONDER) {
		Bond& bond = atom->getBond(DOWN);
		if (bond.getAtom()) {
			++bond;
		} else {
			Atom* otherAtom = board[row+1][col].getAtom();
			bond.setAtom(otherAtom);
			if (atom->getPriority() > otherAtom->getPriority()) {
				atom->setPriority(otherAtom->getPriority());
			}
		}
	}
	if (col > 0 && board[row][col-1].mat == BONDER) {
		Bond& bond = atom->getBond(LEFT);
		if (bond.getAtom()) {
			++bond;
		} else {
			Atom* otherAtom = board[row][col-1].getAtom();
			bond.setAtom(otherAtom);
			if (atom->getPriority() > otherAtom->getPriority()) {
				atom->setPriority(otherAtom->getPriority());
			}
		}
	}
	if (col+1 < board.getNumCols() && board[row][col+1].mat == BONDER) {
		Bond& bond = atom->getBond(RIGHT);
		if (bond.getAtom()) {
			++bond;
		} else {
			Atom* otherAtom = board[row][col+1].getAtom();
			bond.setAtom(otherAtom);
			if (atom->getPriority() > otherAtom->getPriority()) {
				atom->setPriority(otherAtom->getPriority());
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpl $0x1, 0x20(%rax)
je 0x71ac
jmp 0x7556
cmpl $0x0, -0x14(%rbp)
jbe 0x7281
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
subl $0x1, %esi
callq 0x2880
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x20(%rax)
jne 0x7281
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2, %esi
callq 0x66e0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3250
cmpq $0x0, %rax
je 0x7209
movq -0x20(%rbp), %rdi
callq 0x6ab0
jmp 0x727f
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
subl $0x1, %esi
callq 0x2880
movq %rax, %rdi
movl -0x18(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x6f90
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x77a0
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x77c0
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rdi
callq 0x77c0
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jbe 0x727d
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rdi
callq 0x77c0
movq -0x70(%rbp), %rdi
movl %eax, %esi
callq 0x77e0
jmp 0x727f
jmp 0x7281
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2970
movl %eax, %ecx
movl -0x74(%rbp), %eax
cmpl %ecx, %eax
jae 0x736b
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
addl $0x1, %esi
callq 0x2880
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x20(%rax)
jne 0x736b
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x4, %esi
callq 0x66e0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3250
cmpq $0x0, %rax
je 0x72f3
movq -0x30(%rbp), %rdi
callq 0x6ab0
jmp 0x7369
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
addl $0x1, %esi
callq 0x2880
movq %rax, %rdi
movl -0x18(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x6f90
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x77a0
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x77c0
movl %eax, -0x78(%rbp)
movq -0x38(%rbp), %rdi
callq 0x77c0
movl %eax, %ecx
movl -0x78(%rbp), %eax
cmpl %ecx, %eax
jbe 0x7367
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rdi
callq 0x77c0
movq -0x80(%rbp), %rdi
movl %eax, %esi
callq 0x77e0
jmp 0x7369
jmp 0x736b
cmpl $0x0, -0x18(%rbp)
jbe 0x7453
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2880
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x20(%rax)
jne 0x7453
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x3, %esi
callq 0x66e0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x3250
cmpq $0x0, %rax
je 0x73cd
movq -0x40(%rbp), %rdi
callq 0x6ab0
jmp 0x7451
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2880
movq %rax, %rdi
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x6f90
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x77a0
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x77c0
movl %eax, -0x84(%rbp)
movq -0x48(%rbp), %rdi
callq 0x77c0
movl %eax, %ecx
movl -0x84(%rbp), %eax
cmpl %ecx, %eax
jbe 0x744f
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x48(%rbp), %rdi
callq 0x77c0
movq -0x90(%rbp), %rdi
movl %eax, %esi
callq 0x77e0
jmp 0x7451
jmp 0x7453
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6700
movl %eax, %ecx
movl -0x94(%rbp), %eax
cmpl %ecx, %eax
jae 0x7556
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2880
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x20(%rax)
jne 0x7556
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1, %esi
callq 0x66e0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x3250
cmpq $0x0, %rax
je 0x74d0
movq -0x50(%rbp), %rdi
callq 0x6ab0
jmp 0x7554
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2880
movq %rax, %rdi
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
callq 0x6f90
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x77a0
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x77c0
movl %eax, -0x98(%rbp)
movq -0x58(%rbp), %rdi
callq 0x77c0
movl %eax, %ecx
movl -0x98(%rbp), %eax
cmpl %ecx, %eax
jbe 0x7552
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x58(%rbp), %rdi
callq 0x77c0
movq -0xa0(%rbp), %rdi
movl %eax, %esi
callq 0x77e0
jmp 0x7554
jmp 0x7556
addq $0xa0, %rsp
popq %rbp
retq
nop