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

	myOctree::create_lists_of_level_nodes();
	
	if(myOctree::level_nodes[level].empty()) {
                std::cerr << "Error! No blocks in level " << level << 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) {


		//skip if its a leaf node
		if((*it)->isLeafNode()) {	
			continue;
		}
		
            	//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];
               		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++) {
			
					//	std::cout << i << " " << j << " " << k << std::endl;
				
							f->val[i][j][k] = restrict_at((*it),l,i,j,k);

						}
          				}
                 		}
       			}
         	}
        }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, -0x30(%rbp)
movl %edi, %r14d
callq 0x3010
movslq %r14d, %rax
leaq (%rax,%rax,2), %rax
leaq 0x4c1f(%rip), %rcx      # 0x15250
leaq (%rcx,%rax,8), %rax
movq (%rax), %rbx
movq %rax, -0x50(%rbp)
cmpq %rax, %rbx
je 0x1076a
movq 0x10(%rbx), %rdi
callq 0x4040
testb %al, %al
jne 0x1074e
leaq 0x4fcb(%rip), %rcx      # 0x15628
movq 0x8(%rcx), %rax
cmpq (%rcx), %rax
je 0x1074e
xorl %r14d, %r14d
movq %rbx, -0x38(%rbp)
movq 0x10(%rbx), %rdi
callq 0x4064
movq 0x10(%rax), %rax
movq %r14, -0x40(%rbp)
movq (%rax,%r14,8), %rcx
movq 0x20(%rcx), %rdx
movq -0x30(%rbp), %rax
cmpq 0x8(%rax), %rdx
jne 0x10728
testq %rdx, %rdx
movq %rcx, -0x48(%rbp)
je 0x106b9
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq 0x18(%rcx), %rdi
callq 0x2210
movq -0x48(%rbp), %rcx
testl %eax, %eax
jne 0x10728
cmpl $0x0, (%rcx)
jle 0x10728
xorl %r15d, %r15d
cmpl $0x0, 0x4(%rcx)
jle 0x1071d
xorl %r12d, %r12d
cmpl $0x0, 0x8(%rcx)
movq -0x38(%rbp), %r14
movq -0x40(%rbp), %rbx
jle 0x10711
xorl %r13d, %r13d
movq 0x10(%r14), %rdi
movl %ebx, %esi
movl %r15d, %edx
movl %r12d, %ecx
movl %r13d, %r8d
callq 0xfa58
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r12,8), %rax
movsd %xmm0, (%rax,%r13,8)
incq %r13
movslq 0x8(%rcx), %rax
cmpq %rax, %r13
jl 0x106db
incq %r12
movslq 0x4(%rcx), %rax
cmpq %rax, %r12
jl 0x106ca
incq %r15
movslq (%rcx), %rax
cmpq %rax, %r15
jl 0x106c1
movq -0x40(%rbp), %r14
incq %r14
leaq 0x4ef2(%rip), %rcx      # 0x15628
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x5, %rax
cmpq %r14, %rax
movq -0x38(%rbp), %rbx
ja 0x10671
movq (%rbx), %rbx
cmpq -0x50(%rbp), %rbx
jne 0x10645
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x487f(%rip), %rdi      # 0x14ff0
leaq 0xe6c(%rip), %rsi       # 0x115e4
callq 0x21e0
movq %rax, %rdi
movl %r14d, %esi
callq 0x2330
movq %rax, %rdi
callq 0x2100
movl $0x1, %edi
callq 0x2250