// File: /workspace/github_cpp_makefile_star2_O2/suhasjains[P]AMR-Solver/src/multigrid.cpp
// Function: amrsolver::prolongate_domain_for_child(myOctree::Octree*, int, int, int, int, int, int, int)
void prolongate_domain_for_child(Octree* node, int l, int i, int j, int k, int addx, int addy, int addz) {
	//indices
	int i0, i1, j0, j1, k0, k1;	
	

	//grid and parent's grid
	VecField* mesh = node->get_block_data()->mesh;
	VecField* meshp = node->get_parent()->get_block_data()->mesh; 

	//field and parent's field
       	Field *f = node->get_block_data()->scalarfields[l];
       	Field *fp = node->get_parent()->get_block_data()->scalarfields[l];

	//domain
	if(node->get_block_data()->flag[i][j][k]==DOMAIN) {
		//change conditions
//		if((i-pad)%2==0) {
//			if((j-pad)%2==0) {
//				if((k-pad)%2==0) {
		if((((i-pad)%2==0)&&((i-pad)!=0))||((i-pad)==(f->Nx-1-2*pad))) {
			if((((j-pad)%2==0)&&((j-pad)!=0))||((j-pad)==(f->Ny-1-2*pad))) {
				if((((k-pad)%2==0)&&((k-pad)!=0))||((k-pad)==(f->Nz-1-2*pad))) {
					i0=addx+(i+pad)/2 - 1;
					i1=addx+(i+pad)/2;
					j0=addy+(j+pad)/2 - 1;
					j1=addy+(j+pad)/2;
					k0=addz+(k+pad)/2 - 1;
					k1=addz+(k+pad)/2;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
				else if((((k-pad)%2!=0)&&((k-pad)!=(f->Nz-1-2*pad)))||((k-pad)==0)) {
//				else if((k-pad)%2!=0) {
					i0=addx+(i+pad)/2 - 1;
					i1=addx+(i+pad)/2;
					j0=addy+(j+pad)/2 - 1;
					j1=addy+(j+pad)/2;
					k0=addz+(k+pad)/2 ;
					k1=addz+(k+pad)/2 + 1;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
			}
//			else if((j-pad)%2!=0) {
//				if((k-pad)%2==0) {
			else if((((j-pad)%2!=0)&&((j-pad)!=(f->Ny-1-2*pad)))||((j-pad)==0)) {
				if((((k-pad)%2==0)&&((k-pad)!=0))||((k-pad)==(f->Nz-1-2*pad))) {
					i0=addx+(i+pad)/2 - 1;
					i1=addx+(i+pad)/2;
					j0=addy+(j+pad)/2;
					j1=addy+(j+pad)/2 + 1;
					k0=addz+(k+pad)/2 - 1;
					k1=addz+(k+pad)/2;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
//				else if((k-pad)%2!=0) {
				else if((((k-pad)%2!=0)&&((k-pad)!=(f->Nz-1-2*pad)))||((k-pad)==0)) {
					i0=addx+(i+pad)/2 - 1;
					i1=addx+(i+pad)/2;
					j0=addy+(j+pad)/2;
					j1=addy+(j+pad)/2 + 1;
					k0=addz+(k+pad)/2; 
					k1=addz+(k+pad)/2 + 1;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
			}
		}
//		else if((i-pad)%2!=0) {
//			if((j-pad)%2==0) {
//				if((k-pad)%2==0) {
		else if((((i-pad)%2!=0)&&((i-pad)!=(f->Nx-1-2*pad)))||((i-pad)==0)) {
			if((((j-pad)%2==0)&&((j-pad)!=0))||((j-pad)==(f->Ny-1-2*pad))) {
				if((((k-pad)%2==0)&&((k-pad)!=0))||((k-pad)==(f->Nz-1-2*pad))) {
					i0=addx+(i+pad)/2; 
					i1=addx+(i+pad)/2 + 1;
					j0=addy+(j+pad)/2 - 1;
					j1=addy+(j+pad)/2;
					k0=addz+(k+pad)/2 - 1;
					k1=addz+(k+pad)/2;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
				else if((((k-pad)%2!=0)&&((k-pad)!=(f->Nz-1-2*pad)))||((k-pad)==0)) {
//				else if((k-pad)%2!=0) {
					i0=addx+(i+pad)/2; 
					i1=addx+(i+pad)/2 + 1;
					j0=addy+(j+pad)/2 - 1;
					j1=addy+(j+pad)/2;
					k0=addz+(k+pad)/2; 
					k1=addz+(k+pad)/2 + 1;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
			}
//			else if((j-pad)%2!=0) {
//				if((k-pad)%2==0) {
			else if((((j-pad)%2!=0)&&((j-pad)!=(f->Ny-1-2*pad)))||((j-pad)==0)) {
				if((((k-pad)%2==0)&&((k-pad)!=0))||((k-pad)==(f->Nz-1-2*pad))) {
					i0=addx+(i+pad)/2; 
					i1=addx+(i+pad)/2 + 1;
					j0=addy+(j+pad)/2; 
					j1=addy+(j+pad)/2 + 1;
					k0=addz+(k+pad)/2 - 1;
					k1=addz+(k+pad)/2;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
//				else if((k-pad)%2!=0) {
				else if((((k-pad)%2!=0)&&((k-pad)!=(f->Nz-1-2*pad)))||((k-pad)==0)) {
					i0=addx+(i+pad)/2; 
					i1=addx+(i+pad)/2 + 1;
					j0=addy+(j+pad)/2; 
					j1=addy+(j+pad)/2 + 1;
					k0=addz+(k+pad)/2; 
					k1=addz+(k+pad)/2 + 1;
					f->val[i][j][k] = Trilinear_interpolate(meshp->x[i0][j][k],meshp->x[i1][j][k],mesh->x[i][j][k], \
										meshp->y[i][j0][k],meshp->y[i][j1][k],mesh->y[i][j][k], \
										meshp->z[i][j][k0],meshp->z[i][j][k1],mesh->z[i][j][k], \
										fp->val[i0][j0][k1],fp->val[i0][j1][k1], \
										fp->val[i1][j0][k1],fp->val[i1][j1][k1], \
										fp->val[i0][j0][k0],fp->val[i0][j1][k0], \
										fp->val[i1][j0][k0],fp->val[i1][j1][k0]);
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, -0x30(%rbp)
movl %r8d, %ebx
movl %ecx, %r14d
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %r13
callq 0x3db0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq %r13, %rdi
callq 0x3e5e
movq %rax, %rdi
callq 0x3db0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq %r13, %rdi
callq 0x3db0
movq 0x10(%rax), %rax
movslq %r15d, %r15
movq (%rax,%r15,8), %rax
movq %rax, -0x38(%rbp)
movq %r13, %rdi
callq 0x3e5e
movq %rax, %rdi
callq 0x3db0
movq 0x10(%rax), %rax
movq (%rax,%r15,8), %rax
movq %rax, -0x48(%rbp)
movq %r13, %rdi
callq 0x3db0
movq 0x88(%rax), %rax
movslq %r12d, %rcx
movq (%rax,%rcx,8), %rax
movslq %r14d, %r15
movq (%rax,%r15,8), %rax
movslq %ebx, %r13
cmpl $0x7, (%rax,%r13,4)
jne 0xd426
movq %rcx, -0x40(%rbp)
movl 0x10(%rbp), %edi
leaq 0x61c1(%rip), %rax      # 0x131d0
movl (%rax), %esi
movl %r12d, %ecx
subl %esi, %ecx
setne %al
testb $0x1, %cl
sete %dl
testb %dl, %al
jne 0xd034
leal (%rsi,%rsi), %eax
notl %eax
movq -0x38(%rbp), %rdx
movl (%rdx), %edx
addl %eax, %edx
cmpl %edx, %ecx
jne 0xd09d
movl %r14d, %ecx
subl %esi, %ecx
setne %al
testb $0x1, %cl
sete %dl
testb %dl, %al
jne 0xd05c
leal (%rsi,%rsi), %eax
notl %eax
movq -0x38(%rbp), %rdx
movl 0x4(%rdx), %edx
addl %eax, %edx
cmpl %edx, %ecx
jne 0xd12a
movl %ebx, %eax
subl %esi, %eax
setne %cl
testb $0x1, %al
sete %dl
testb %dl, %cl
jne 0xd080
leal (%rsi,%rsi), %ecx
notl %ecx
movq -0x38(%rbp), %rdx
addl 0x8(%rdx), %ecx
cmpl %ecx, %eax
jne 0xd17d
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movq -0x30(%rbp), %rdx
leal (%rax,%rdx), %r8d
leal (%rax,%rdx), %r9d
decl %r9d
jmp 0xd0ff
movl %r14d, %ecx
subl %esi, %ecx
setne %dl
testb $0x1, %cl
sete %r8b
testb %r8b, %dl
jne 0xd0c2
movq -0x38(%rbp), %rdx
movl 0x4(%rdx), %edx
addl %eax, %edx
cmpl %edx, %ecx
jne 0xd1b1
movl %ebx, %ecx
subl %esi, %ecx
setne %dl
testb $0x1, %cl
sete %r8b
testb %r8b, %dl
jne 0xd0e4
movq -0x38(%rbp), %rdx
addl 0x8(%rdx), %eax
cmpl %eax, %ecx
jne 0xd213
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movq -0x30(%rbp), %rdx
leal (%rax,%rdx), %r9d
leal (%rax,%rdx), %r8d
incl %r8d
addl %esi, %r14d
movl %r14d, %eax
cltd
idivl %ecx
leal (%rax,%rdi), %r10d
leal (%rax,%rdi), %r11d
decl %r11d
addl %esi, %ebx
movl %ebx, %eax
cltd
idivl %ecx
movl 0x18(%rbp), %ecx
leal (%rax,%rcx), %edx
leal (%rax,%rcx), %esi
decl %esi
jmp 0xd2c6
movl %ebx, %ecx
subl %esi, %ecx
setne %dl
testb $0x1, %cl
sete %r8b
testb %r8b, %dl
jne 0xd14c
movq -0x38(%rbp), %rdx
addl 0x8(%rdx), %eax
cmpl %eax, %ecx
jne 0xd248
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movq -0x30(%rbp), %rdx
leal (%rax,%rdx), %r8d
leal (%rax,%rdx), %r9d
decl %r9d
addl %esi, %r14d
movl %r14d, %eax
cltd
idivl %ecx
leal (%rax,%rdi), %r11d
leal (%rax,%rdi), %r10d
incl %r10d
jmp 0xd113
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movq -0x30(%rbp), %rdx
leal (%rax,%rdx), %r8d
leal (%rax,%rdx), %r9d
decl %r9d
addl %esi, %r14d
movl %r14d, %eax
cltd
idivl %ecx
leal (%rax,%rdi), %r10d
leal (%rax,%rdi), %r11d
decl %r11d
jmp 0xd277
movl %ebx, %ecx
subl %esi, %ecx
setne %dl
testb $0x1, %cl
sete %r8b
testb %r8b, %dl
jne 0xd1d3
movq -0x38(%rbp), %rdx
addl 0x8(%rdx), %eax
cmpl %eax, %ecx
jne 0xd280
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movl %ecx, %r12d
movq -0x30(%rbp), %rcx
leal (%rax,%rcx), %r9d
leal (%rax,%rcx), %r8d
incl %r8d
addl %esi, %r14d
movl %r14d, %eax
cltd
idivl %r12d
leal (%rax,%rdi), %r11d
leal (%rax,%rdi), %r10d
incl %r10d
addl %esi, %ebx
movl %ebx, %eax
cltd
idivl %r12d
jmp 0xd11a
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movl %ecx, %r12d
movq -0x30(%rbp), %rcx
leal (%rax,%rcx), %r9d
leal (%rax,%rcx), %r8d
incl %r8d
addl %esi, %r14d
movl %r14d, %eax
cltd
idivl %r12d
leal (%rax,%rdi), %r10d
leal (%rax,%rdi), %r11d
decl %r11d
jmp 0xd2b3
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movq -0x30(%rbp), %rdx
leal (%rax,%rdx), %r8d
leal (%rax,%rdx), %r9d
decl %r9d
addl %esi, %r14d
movl %r14d, %eax
cltd
idivl %ecx
leal (%rax,%rdi), %r11d
leal (%rax,%rdi), %r10d
incl %r10d
addl %esi, %ebx
movl %ebx, %eax
cltd
idivl %ecx
jmp 0xd2bb
addl %esi, %r12d
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movl %ecx, %r12d
movq -0x30(%rbp), %rcx
leal (%rax,%rcx), %r9d
leal (%rax,%rcx), %r8d
incl %r8d
addl %esi, %r14d
movl %r14d, %eax
cltd
idivl %r12d
leal (%rax,%rdi), %r11d
leal (%rax,%rdi), %r10d
incl %r10d
addl %esi, %ebx
movl %ebx, %eax
cltd
idivl %r12d
movl 0x18(%rbp), %ecx
leal (%rax,%rcx), %esi
leal (%rax,%rcx), %edx
incl %edx
movslq %r9d, %rax
movslq %r8d, %rcx
movslq %r11d, %rdi
movslq %r10d, %r8
movq -0x50(%rbp), %r12
movq 0x20(%r12), %r9
movq -0x40(%rbp), %r14
movq (%r9,%r14,8), %r9
movq (%r9,%r15,8), %r9
movslq %esi, %rsi
movsd (%r9,%rsi,8), %xmm0
movsd %xmm0, -0x30(%rbp)
movslq %edx, %rdx
movsd (%r9,%rdx,8), %xmm7
movq -0x48(%rbp), %r9
movq 0x10(%r9), %r9
movq (%r9,%rax,8), %r10
movq (%r10,%rdi,8), %r11
movsd (%r11,%rdx,8), %xmm8
movq (%r10,%r8,8), %r10
movsd (%r10,%rdx,8), %xmm9
movq (%r9,%rcx,8), %r9
movq (%r9,%rdi,8), %rbx
movsd (%rbx,%rdx,8), %xmm10
movq (%r9,%r8,8), %r9
movsd (%r9,%rdx,8), %xmm11
movsd (%r11,%rsi,8), %xmm12
movsd (%r10,%rsi,8), %xmm13
movsd (%rbx,%rsi,8), %xmm14
movsd (%r9,%rsi,8), %xmm15
movq 0x10(%r12), %rdx
movq (%rdx,%rax,8), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r13,8), %xmm6
movq (%rdx,%rcx,8), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r13,8), %xmm1
movq -0x58(%rbp), %rdx
movq 0x10(%rdx), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r13,8), %xmm2
movq 0x18(%r12), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%rdi,8), %rcx
movsd (%rcx,%r13,8), %xmm3
movq (%rax,%r8,8), %rax
movsd (%rax,%r13,8), %xmm4
movq 0x18(%rdx), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r13,8), %xmm5
movq 0x20(%rdx), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r13,8), %xmm0
movsd %xmm15, 0x40(%rsp)
movsd %xmm14, 0x38(%rsp)
movsd %xmm13, 0x30(%rsp)
movsd %xmm12, 0x28(%rsp)
movsd %xmm11, 0x20(%rsp)
movsd %xmm10, 0x18(%rsp)
movsd %xmm9, 0x10(%rsp)
movsd %xmm8, 0x8(%rsp)
movsd %xmm0, (%rsp)
movaps %xmm6, %xmm0
movsd -0x30(%rbp), %xmm6
callq 0xc8b8
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rax
movsd %xmm0, (%rax,%r13,8)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq