// File: 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
subq $0xc0, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6de0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6de0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6de0
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6de0
movq 0x10(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6de0
movq 0x88(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
cmpl $0x7, (%rax,%rcx,4)
jne 0x1f03f
movq -0x8(%rbp), %rdi
callq 0x6de0
movq 0x88(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq 0x72c8(%rip), %rdi      # 0x25fd0
callq 0x3400
movq %rax, %rdi
movq 0x72a9(%rip), %rsi      # 0x25fc0
callq 0x3270
movl 0x10(%rbp), %eax
movl -0x18(%rbp), %ecx
shll %ecx
addl %ecx, %eax
leaq 0x753b(%rip), %rcx      # 0x26268
subl (%rcx), %eax
movl %eax, -0x24(%rbp)
movl 0x10(%rbp), %eax
movl -0x18(%rbp), %ecx
shll %ecx
addl %ecx, %eax
leaq 0x7525(%rip), %rcx      # 0x26268
subl (%rcx), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl 0x18(%rbp), %eax
movl -0x1c(%rbp), %ecx
shll %ecx
addl %ecx, %eax
leaq 0x750c(%rip), %rcx      # 0x26268
subl (%rcx), %eax
movl %eax, -0x2c(%rbp)
movl 0x18(%rbp), %eax
movl -0x1c(%rbp), %ecx
shll %ecx
addl %ecx, %eax
leaq 0x74f6(%rip), %rcx      # 0x26268
subl (%rcx), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl 0x20(%rbp), %eax
movl -0x20(%rbp), %ecx
shll %ecx
addl %ecx, %eax
leaq 0x74dd(%rip), %rcx      # 0x26268
subl (%rcx), %eax
movl %eax, -0x34(%rbp)
movl 0x20(%rbp), %eax
movl -0x20(%rbp), %ecx
shll %ecx
addl %ecx, %eax
leaq 0x74c7(%rip), %rcx      # 0x26268
subl (%rcx), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm3
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm4
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm5
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm6
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm7
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm8
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm15
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm14
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm13
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm12
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm11
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm10
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm9
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm8, (%rsp)
movsd -0x68(%rbp), %xmm8
movsd %xmm15, 0x8(%rsp)
movsd %xmm14, 0x10(%rsp)
movsd %xmm13, 0x18(%rsp)
movsd %xmm12, 0x20(%rsp)
movsd %xmm11, 0x28(%rsp)
movsd %xmm10, 0x30(%rsp)
movsd %xmm9, 0x38(%rsp)
movsd %xmm8, 0x40(%rsp)
callq 0x1a040
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)