// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $0x1, 0x20(%rdi)
jne 0x4062
movl %ecx, %r14d
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
movl %ecx, %r13d
testl %edx, %edx
je 0x3f67
leal -0x1(%r12), %eax
cmpl %eax, 0x4(%r15)
jbe 0x406c
movq 0x18(%r15), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
leaq (,%r13,4), %rcx
addq %r13, %rcx
cmpl $0x1, 0x20(%rax,%rcx,8)
jne 0x3f67
movq 0x18(%rbx), %rdi
cmpq $0x0, 0x28(%rdi)
je 0x3f53
addq $0x28, %rdi
callq 0x3c1c
jmp 0x3f67
movq 0x18(%rax,%rcx,8), %rax
movq %rax, 0x28(%rdi)
movl 0x4c(%rax), %eax
cmpl %eax, 0x4c(%rdi)
jbe 0x3f67
movl %eax, 0x4c(%rdi)
leal 0x1(%r12), %eax
cmpl 0x4(%r15), %eax
jae 0x3fba
movq 0x18(%r15), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
leaq (,%r13,4), %rdx
addq %r13, %rdx
cmpl $0x1, 0x20(%rcx,%rdx,8)
jne 0x3fba
movq 0x18(%rbx), %rax
leaq 0x48(%rax), %rdi
cmpq $0x0, 0x48(%rax)
je 0x3fa4
callq 0x3c1c
jmp 0x3fba
movq 0x18(%rcx,%rdx,8), %rdx
movq %rdx, (%rdi)
movl 0x4c(%rdx), %ecx
shrq $0x20, %rdx
cmpl %edx, %ecx
jae 0x3fba
movl %ecx, 0x4c(%rax)
movl %r12d, %r13d
testl %r14d, %r14d
je 0x400d
cmpl %r12d, 0x4(%r15)
jbe 0x406c
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rax
leal -0x1(%r14), %ecx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x1, 0x20(%rax,%rcx,8)
jne 0x400d
movq 0x18(%rbx), %rdi
cmpq $0x0, 0x38(%rdi)
je 0x3ff9
addq $0x38, %rdi
callq 0x3c1c
jmp 0x400d
movq 0x18(%rax,%rcx,8), %rax
movq %rax, 0x38(%rdi)
movl 0x4c(%rax), %eax
cmpl %eax, 0x4c(%rdi)
jbe 0x400d
movl %eax, 0x4c(%rdi)
incl %r14d
cmpl (%r15), %r14d
jae 0x4062
cmpl %r12d, 0x4(%r15)
jbe 0x406c
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rax
movl %r14d, %ecx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x1, 0x20(%rax,%rcx,8)
jne 0x4062
movq 0x18(%rbx), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x404e
addq $0x18, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x3c1c
movq 0x18(%rax,%rcx,8), %rax
movq %rax, 0x18(%rdi)
movl 0x4c(%rax), %eax
cmpl %eax, 0x4c(%rdi)
jbe 0x4062
movl %eax, 0x4c(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xf9a(%rip), %rdi       # 0x500d
leaq 0xfa8(%rip), %rsi       # 0x5022
leaq 0xfad(%rip), %rcx       # 0x502e
movl $0x32, %edx
callq 0x20d0
nop