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

	//grid and child's grid
	VecField* mesh = node->get_block_data()->mesh;
	VecField* meshc = child->get_block_data()->mesh; 

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

	//domain
	if(node->get_block_data()->flag[i][j][k]==DOMAIN) {
		std::cout << node->get_block_data()->flag[i][j][k] << std::endl;
		i0=addx+2*i-pad;
		i1=addx+2*i-pad+1;
		j0=addy+2*j-pad; 
		j1=addy+2*j-pad+1;
		k0=addz+2*k-pad;
		k1=addz+2*k-pad+1;
		result = Trilinear_interpolate(meshc->x[i0][j][k],meshc->x[i1][j][k],mesh->x[i][j][k], \
							meshc->y[i][j0][k],meshc->y[i][j1][k],mesh->y[i][j][k], \
							meshc->z[i][j][k0],meshc->z[i][j][k1],mesh->z[i][j][k], \
							fc->val[i0][j0][k1],fc->val[i0][j1][k1], \
							fc->val[i1][j0][k1],fc->val[i1][j1][k1], \
							fc->val[i0][j0][k0],fc->val[i0][j1][k0], \
							fc->val[i1][j0][k0],fc->val[i1][j1][k0]);
	}

	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, -0x30(%rbp)
movl %r8d, -0x34(%rbp)
movl %ecx, %r12d
movl %edx, %r13d
movq %rsi, %rbx
movq %rdi, %r15
callq 0x3db0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq %rbx, %rdi
callq 0x3db0
movq (%rax), %r14
movq %r15, %rdi
callq 0x3db0
movslq %r13d, %r13
movq %rbx, %rdi
callq 0x3db0
movq 0x10(%rax), %rax
movq (%rax,%r13,8), %rax
movq %rax, -0x48(%rbp)
movq %r15, %rdi
callq 0x3db0
movslq %r12d, %r12
movslq -0x34(%rbp), %r13
movslq -0x30(%rbp), %rbx
movq %r15, %rdi
callq 0x3db0
movq 0x88(%rax), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r13,8), %rax
movl (%rax,%rbx,4), %esi
movq 0x5b0c(%rip), %rdi      # 0x12fd0
callq 0x2310
movq %rax, %rdi
callq 0x2110
leal (%r12,%r12), %eax
addl 0x10(%rbp), %eax
leaq 0x5cf1(%rip), %rcx      # 0x131d0
movl (%rcx), %edx
subl %edx, %eax
leal (,%r13,2), %esi
addl 0x18(%rbp), %esi
subl %edx, %esi
leal (%rbx,%rbx), %ecx
addl 0x20(%rbp), %ecx
subl %edx, %ecx
cltq
movq 0x10(%r14), %rdx
movq 0x18(%r14), %rdi
movq (%rdx,%rax,8), %r8
movq 0x8(%rdx,%rax,8), %rdx
movq (%r8,%r13,8), %r8
movsd (%r8,%rbx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
movq (%rdx,%r13,8), %rdx
movsd (%rdx,%rbx,8), %xmm1
movq -0x40(%rbp), %r9
movq 0x10(%r9), %rdx
movq 0x18(%r9), %r8
movq (%rdx,%r12,8), %rdx
movq (%rdx,%r13,8), %rdx
movsd (%rdx,%rbx,8), %xmm2
movq (%rdi,%r12,8), %rdx
movslq %esi, %rsi
movq (%rdx,%rsi,8), %rdi
movq 0x8(%rdx,%rsi,8), %rdx
movsd (%rdi,%rbx,8), %xmm3
movsd (%rdx,%rbx,8), %xmm4
movq (%r8,%r12,8), %rdx
movq (%rdx,%r13,8), %rdx
movsd (%rdx,%rbx,8), %xmm5
movq 0x20(%r14), %rdx
movq (%rdx,%r12,8), %rdx
movq (%rdx,%r13,8), %rdx
movslq %ecx, %rcx
movsd (%rdx,%rcx,8), %xmm6
movsd 0x8(%rdx,%rcx,8), %xmm7
movq 0x20(%r9), %rdx
movq (%rdx,%r12,8), %rdx
movq (%rdx,%r13,8), %rdx
movsd (%rdx,%rbx,8), %xmm8
movq -0x48(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq (%rdx,%rax,8), %rdi
movq 0x8(%rdx,%rax,8), %rax
movq (%rdi,%rsi,8), %rdx
movq 0x8(%rdi,%rsi,8), %rdi
movsd (%rdx,%rcx,8), %xmm9
movsd 0x8(%rdx,%rcx,8), %xmm10
movsd (%rdi,%rcx,8), %xmm11
movsd 0x8(%rdi,%rcx,8), %xmm12
movq (%rax,%rsi,8), %rdx
movq 0x8(%rax,%rsi,8), %rax
movsd (%rdx,%rcx,8), %xmm13
movsd 0x8(%rdx,%rcx,8), %xmm14
movsd (%rax,%rcx,8), %xmm15
movsd 0x8(%rax,%rcx,8), %xmm0
movsd %xmm15, 0x40(%rsp)
movsd %xmm13, 0x38(%rsp)
movsd %xmm11, 0x30(%rsp)
movsd %xmm9, 0x28(%rsp)
movsd %xmm0, 0x20(%rsp)
movsd %xmm14, 0x18(%rsp)
movsd %xmm12, 0x10(%rsp)
movsd %xmm10, 0x8(%rsp)
movsd %xmm8, (%rsp)
movsd -0x30(%rbp), %xmm0
callq 0xc8b8
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq