// File: 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
subq $0x50, %rsp
movq %rsi, -0x48(%rbp)
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x4a50
movslq -0x4(%rbp), %rax
leaq 0x61ad(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x12570
testb $0x1, %al
jne 0x20145
jmp 0x2017c
movq 0x5ea4(%rip), %rdi      # 0x25ff0
leaq 0x1445(%rip), %rsi      # 0x21598
callq 0x3240
movq %rax, %rdi
movl -0x4(%rbp), %esi
callq 0x3400
movq %rax, %rdi
movq 0x5e53(%rip), %rsi      # 0x25fc0
callq 0x3270
movl $0x1, %edi
callq 0x32e0
movslq -0x4(%rbp), %rax
leaq 0x6159(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x4490
movq %rax, -0x18(%rbp)
movslq -0x4(%rbp), %rax
leaq 0x613e(%rip), %rdi      # 0x262e0
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x44c0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x44f0
testb $0x1, %al
jne 0x201c8
jmp 0x2030f
leaq -0x18(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
callq 0x6da0
testb $0x1, %al
jne 0x201df
jmp 0x201e4
jmp 0x20301
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x64be(%rip), %rdi      # 0x266b8
callq 0x5b00
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x202ff
leaq -0x18(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
callq 0x6de0
movq -0x48(%rbp), %rsi
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
callq 0xd110
testb $0x1, %al
jne 0x2024a
jmp 0x202ef
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x202ed
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x202dd
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x202d0
leaq -0x18(%rbp), %rdi
callq 0x4520
movq (%rax), %rdi
movl -0x24(%rbp), %esi
movl -0x34(%rbp), %edx
movl -0x38(%rbp), %ecx
movl -0x3c(%rbp), %r8d
callq 0x1f050
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2027a
jmp 0x202d2
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x20267
jmp 0x202df
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x20251
jmp 0x202ef
jmp 0x202f1
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x201eb
jmp 0x20301
leaq -0x18(%rbp), %rdi
callq 0x4550
jmp 0x201b2
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)