// File: suhasjains[P]AMR-Solver/src/multigrid.cpp
// Function: amrsolver::prolongate_ghost(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void prolongate_ghost(int level, std::string name) {

	//relative locations wrt siblings
	int *loc_x, *loc_y, *loc_z;
	loc_x = new int;
	loc_y = new int;
	loc_z = new int;

	myOctree::create_lists_of_level_nodes();
	
	if(myOctree::level_nodes[level].empty()) {
                std::cerr << "Error! No blocks in level " << level << std::endl;
                exit(1);
        }
	
	if(level==0) {
                std::cerr << "Error! Level cannot be zero" << std::endl;
                exit(1);
        }

	//loop over nodes
	for (std::list<Octree*>::iterator it = level_nodes[level].begin(), end = level_nodes[level].end(); it != end; ++it) {

        	//get location relative to siblings
            	(*it)->get_relative_location(loc_x,loc_y,loc_z);

            	//loop over scalar fields
            	for(int l = 0; l<myOctree::scalar_fields.size() ; l++) {


			//field and block
       			Field *f = (*it)->get_block_data()->scalarfields[l];
       			Block *b = (*it)->get_block_data();

               		if( f->name == name ) {

  				for(int i=0; i<f->Nx; i++) {
         				for(int j=0; j<f->Ny; j++) {
                         			for(int k=0; k<f->Nz; k++) {
								

							if(*loc_x==1) {
								if(*loc_y==1) {
									if(*loc_z==1) {
										prolongate_ghost_for_child((*it),l,i,j,k,b->iNx/2,b->iNy/2,b->iNz/2);
									}
									else if(*loc_z==0) {
										prolongate_ghost_for_child((*it),l,i,j,k,b->iNx/2,b->iNy/2,0);
									}
								}
								else if(*loc_y==0) {
									if(*loc_z==1) {
										prolongate_ghost_for_child((*it),l,i,j,k,b->iNx/2,0,b->iNz/2);
									}
									else if(*loc_z==0) {
										prolongate_ghost_for_child((*it),l,i,j,k,b->iNx/2,0,0);
									}
								}
							}
							if(*loc_x==0) {
								if(*loc_y==1) {
									if(*loc_z==1) {
										prolongate_ghost_for_child((*it),l,i,j,k,0,b->iNy/2,b->iNz/2);
									}
									else if(*loc_z==0) {
										prolongate_ghost_for_child((*it),l,i,j,k,0,b->iNy/2,0);
									}
								}
								else if(*loc_y==0) {
									if(*loc_z==1) {
										prolongate_ghost_for_child((*it),l,i,j,k,0,0,b->iNz/2);
									}
									else if(*loc_z==0) {
										prolongate_ghost_for_child((*it),l,i,j,k,0,0,0);
									}
								}
							}
						}
          				}
                 		}
       			}
         	}
        }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rsi, -0x68(%rbp)
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x4, %edi
callq 0x3250
movq %rax, -0x18(%rbp)
movl $0x4, %edi
callq 0x3250
movq %rax, -0x20(%rbp)
movl $0x4, %edi
callq 0x3250
movq %rax, -0x28(%rbp)
callq 0x4a50
movslq -0x4(%rbp), %rax
leaq 0x6cc0(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x12570
testb $0x1, %al
jne 0x1f632
jmp 0x1f669
movq 0x69b7(%rip), %rdi      # 0x25ff0
leaq 0x1f58(%rip), %rsi      # 0x21598
callq 0x3240
movq %rax, %rdi
movl -0x4(%rbp), %esi
callq 0x3400
movq %rax, %rdi
movq 0x6966(%rip), %rsi      # 0x25fc0
callq 0x3270
movl $0x1, %edi
callq 0x32e0
cmpl $0x0, -0x4(%rbp)
jne 0x1f69b
movq 0x697a(%rip), %rdi      # 0x25ff0
leaq 0x1f36(%rip), %rsi      # 0x215b3
callq 0x3240
movq %rax, %rdi
movq 0x6934(%rip), %rsi      # 0x25fc0
callq 0x3270
movl $0x1, %edi
callq 0x32e0
movslq -0x4(%rbp), %rax
leaq 0x6c3a(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x4490
movq %rax, -0x30(%rbp)
movslq -0x4(%rbp), %rax
leaq 0x6c1f(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x44c0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x44f0
testb $0x1, %al
jne 0x1f6e7
jmp 0x1fb61
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x6f80
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq 0x6f9e(%rip), %rdi      # 0x266b8
callq 0x5b00
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jae 0x1fb51
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
callq 0x6de0
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
callq 0x6de0
movq -0x68(%rbp), %rsi
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
addq $0x18, %rdi
callq 0xd110
testb $0x1, %al
jne 0x1f77f
jmp 0x1fb41
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1fb3f
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x1fb2f
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x1fb1f
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1f98d
movq -0x20(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1f8be
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1f853
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
leaq 0x6edf(%rip), %rax      # 0x266e8
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl %eax, %r9d
leaq 0x6ecd(%rip), %rax      # 0x266ec
movl (%rax), %eax
movl $0x2, %r10d
cltd
idivl %r10d
movl %eax, %r10d
leaq 0x6ebb(%rip), %rax      # 0x266f0
movl (%rax), %eax
movl $0x2, %r11d
cltd
idivl %r11d
movl -0x74(%rbp), %edx
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1f8b9
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1f8b7
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
leaq 0x6e69(%rip), %rax      # 0x266e8
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl %eax, %r9d
leaq 0x6e57(%rip), %rax      # 0x266ec
movl (%rax), %eax
movl $0x2, %r10d
cltd
idivl %r10d
movl -0x78(%rbp), %edx
xorl %r10d, %r10d
movl %eax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1f8b9
jmp 0x1f98b
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1f989
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1f931
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
leaq 0x6df1(%rip), %rax      # 0x266e8
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl %eax, %r9d
leaq 0x6de3(%rip), %rax      # 0x266f0
movl (%rax), %eax
movl $0x2, %r10d
cltd
idivl %r10d
movl -0x7c(%rbp), %edx
xorl %r10d, %r10d
movl $0x0, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1f987
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1f985
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
leaq 0x6d8b(%rip), %rax      # 0x266e8
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl -0x80(%rbp), %edx
movl %eax, %r9d
xorl %eax, %eax
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1f987
jmp 0x1f989
jmp 0x1f98b
jmp 0x1f98d
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1fb0f
movq -0x20(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1fa6b
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1fa10
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
leaq 0x6d16(%rip), %rax      # 0x266ec
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl %eax, %r10d
leaq 0x6d04(%rip), %rax      # 0x266f0
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl -0x84(%rbp), %edx
xorl %r9d, %r9d
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1fa66
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1fa64
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
leaq 0x6cad(%rip), %rax      # 0x266ec
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl -0x88(%rbp), %edx
xorl %r9d, %r9d
movl %eax, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1fa66
jmp 0x1fb0d
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1fb0b
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x1face
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
leaq 0x6c49(%rip), %rax      # 0x266f0
movl (%rax), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl -0x8c(%rbp), %edx
xorl %r9d, %r9d
movl $0x0, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1fb09
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1fb07
leaq -0x30(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x3c(%rbp), %esi
movl -0x54(%rbp), %edx
movl -0x58(%rbp), %ecx
movl -0x5c(%rbp), %r8d
xorl %r9d, %r9d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x1a3f0
jmp 0x1fb09
jmp 0x1fb0b
jmp 0x1fb0d
jmp 0x1fb0f
jmp 0x1fb11
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1f7b3
jmp 0x1fb21
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1f79c
jmp 0x1fb31
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1f786
jmp 0x1fb41
jmp 0x1fb43
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1f70b
jmp 0x1fb53
leaq -0x30(%rbp), %rdi
callq 0x4550
jmp 0x1f6d1
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)