// File: suhasjains[P]AMR-Solver/src/octreegrid.cpp
// Function: myOctree::reassign_neighbours()
void reassign_neighbours() {

	for (unsigned level=0; level <= max_level; level++) {


		for (std::list<Octree*>::iterator iter = level_nodes[level].begin(), end = level_nodes[level].end(); iter != end; ++iter) { 
			//if it is not leaf node	
			if(!((*iter)->isLeafNode())) {
	
				//setting neighbours to children
			        for(int k=0; k<2; k++) {
			                for(int j=0; j<2; j++) {
			                        for(int i=0; i<2; i++) {
			
			                               // if(i==0) {
			                               //         if((*iter)->west != NULL)  (*iter)->get_child_at(i, j, k)->west = (*iter)->west->get_child_at(i+1, j, k);
			                               // }
			                               // if(j==0) {
			                               //         if((*iter)->south != NULL) (*iter)->get_child_at(i, j, k)->south = (*iter)->south->get_child_at(i, j+1, k);
			                               // }
			                               // if(k==0) {
			                               //         if((*iter)->bottom != NULL)	(*iter)->get_child_at(i, j, k)->bottom = (*iter)->bottom->get_child_at(i, j, k+1);
			                               // }
			                               // if(i==1) {
			                               //         if((*iter)->east != NULL)  (*iter)->get_child_at(i, j, k)->east = (*iter)->east->get_child_at(i-1, j, k);
			                               // }
			                               // if(j==1) {
			                               //         if((*iter)->north != NULL) (*iter)->get_child_at(i, j, k)->north = (*iter)->north->get_child_at(i, j-1, k);
			                               // }
			                               // if(k==1) {
			                               //         if((*iter)->top != NULL)   (*iter)->get_child_at(i, j, k)->top = (*iter)->top->get_child_at(i, j, k-1);
			                               // }
			                                if(i==0) {
			                                        if((*iter)->neighbour[XDIR][LEFT] != NULL)  (*iter)->get_child_at(i, j, k)->neighbour[XDIR][LEFT] = (*iter)->neighbour[XDIR][LEFT]->get_child_at(i+1, j, k);
			                                }
			                                if(j==0) {
			                                        if((*iter)->neighbour[YDIR][LEFT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[YDIR][LEFT] = (*iter)->neighbour[YDIR][LEFT]->get_child_at(i, j+1, k);
			                                }
			                                if(k==0) {
			                                        if((*iter)->neighbour[ZDIR][LEFT] != NULL)	(*iter)->get_child_at(i, j, k)->neighbour[ZDIR][LEFT] = (*iter)->neighbour[ZDIR][LEFT]->get_child_at(i, j, k+1);
			                                }
			                                if(i==1) {
			                                        if((*iter)->neighbour[XDIR][RIGHT] != NULL)  (*iter)->get_child_at(i, j, k)->neighbour[XDIR][RIGHT] = (*iter)->neighbour[XDIR][RIGHT]->get_child_at(i-1, j, k);
			                                }
			                                if(j==1) {
			                                        if((*iter)->neighbour[YDIR][RIGHT] != NULL) (*iter)->get_child_at(i, j, k)->neighbour[YDIR][RIGHT] = (*iter)->neighbour[YDIR][RIGHT]->get_child_at(i, j-1, k);
			                                }
			                                if(k==1) {
			                                        if((*iter)->neighbour[ZDIR][RIGHT] != NULL)   (*iter)->get_child_at(i, j, k)->neighbour[ZDIR][RIGHT] = (*iter)->neighbour[ZDIR][RIGHT]->get_child_at(i, j, k-1);
			                                }
			                        }
			                }
			        }
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
leaq 0x2189b(%rip), %rcx     # 0x266a4
cmpl (%rcx), %eax
ja 0x5145
movl -0x4(%rbp), %eax
leaq 0x214c5(%rip), %rdi     # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x4490
movq %rax, -0x10(%rbp)
movl -0x4(%rbp), %eax
leaq 0x214ab(%rip), %rdi     # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x44c0
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x44f0
testb $0x1, %al
jne 0x4e5b
jmp 0x5135
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
callq 0x6da0
testb $0x1, %al
jne 0x5125
movl $0x0, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0x5123
movl $0x0, -0x20(%rbp)
cmpl $0x2, -0x20(%rbp)
jge 0x5113
movl $0x0, -0x24(%rbp)
cmpl $0x2, -0x24(%rbp)
jge 0x5103
cmpl $0x0, -0x24(%rbp)
jne 0x4f09
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x4f07
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
movq 0x10(%rax), %rdi
movl -0x24(%rbp), %esi
addl $0x1, %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq %rax, -0x30(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq -0x30(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x4f09
cmpl $0x0, -0x20(%rbp)
jne 0x4f6b
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
cmpq $0x0, 0x20(%rax)
je 0x4f69
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
movq 0x20(%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
addl $0x1, %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq %rax, -0x38(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq -0x38(%rbp), %rcx
movq %rcx, 0x20(%rax)
jmp 0x4f6b
cmpl $0x0, -0x1c(%rbp)
jne 0x4fcd
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
cmpq $0x0, 0x30(%rax)
je 0x4fcb
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
movq 0x30(%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
callq 0x6ee0
movq %rax, -0x40(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq -0x40(%rbp), %rcx
movq %rcx, 0x30(%rax)
jmp 0x4fcd
cmpl $0x1, -0x24(%rbp)
jne 0x502f
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x502d
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
movq 0x8(%rax), %rdi
movl -0x24(%rbp), %esi
subl $0x1, %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq %rax, -0x48(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x502f
cmpl $0x1, -0x20(%rbp)
jne 0x5091
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0x508f
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
movq 0x18(%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
subl $0x1, %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq %rax, -0x50(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq -0x50(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x5091
cmpl $0x1, -0x1c(%rbp)
jne 0x50f3
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x50f1
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rax
movq 0x28(%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
callq 0x6ee0
movq %rax, -0x58(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x6ee0
movq -0x58(%rbp), %rcx
movq %rcx, 0x28(%rax)
jmp 0x50f3
jmp 0x50f5
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4e9d
jmp 0x5105
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4e8c
jmp 0x5115
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4e7b
jmp 0x5125
jmp 0x5127
leaq -0x10(%rbp), %rdi
callq 0x4550
jmp 0x4e45
jmp 0x5137
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x4dff
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)