// File: tewalds[P]morat/pentago/agentmcts.cpp
// Function: Morat::Pentago::AgentMCTS::garbage_collect(Morat::Pentago::Board&, Morat::Pentago::AgentMCTS::Node*)
void AgentMCTS::garbage_collect(Board & board, Node * node){
	Node * child = node->children.begin(),
		 * end = node->children.end();

	Side to_play = board.to_play();
	for( ; child != end; child++){
		if(child->children.num() == 0)
			continue;

		if(	(node->outcome >= Outcome::DRAW && child->exp.num() > gcsolved && (node->outcome != to_play || child->outcome == to_play || child->outcome == Outcome::DRAW)) || //parent is solved, only keep the proof tree, plus heavy draws
			(node->outcome <  Outcome::DRAW && child->exp.num() > (child->outcome >= Outcome::DRAW ? gcsolved : gclimit)) ){ // only keep heavy nodes, with different cutoffs for solved and unsolved
			board.move(child->move);
			garbage_collect(board, child);
			board.undo(child->move);
		}else{
			nodes -= child->dealloc(ctmem);
		}
	}
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rdi
addq $0x18, %rdi
callq 0x1d7b0
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rdi
addq $0x18, %rdi
callq 0x1d800
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rdi
callq 0x14b50
movb %al, 0x1f(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x1b46c
movq 0x28(%rsp), %rdi
addq $0x18, %rdi
callq 0x1bc90
cmpl $0x0, %eax
jne 0x1b2e9
jmp 0x1b459
movq 0x30(%rsp), %rdi
addq $0x12, %rdi
leaq 0x40522(%rip), %rsi     # 0x5b81b
callq 0x140c0
testb $0x1, %al
jne 0x1b304
jmp 0x1b36a
movq 0x28(%rsp), %rdi
callq 0x1da00
movq 0x10(%rsp), %rcx
movl 0x70(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x1b36a
movq 0x30(%rsp), %rdi
addq $0x12, %rdi
leaq 0x1f(%rsp), %rsi
callq 0x1da90
testb $0x1, %al
jne 0x1b3df
movq 0x28(%rsp), %rdi
addq $0x12, %rdi
leaq 0x1f(%rsp), %rsi
callq 0x1d9c0
testb $0x1, %al
jne 0x1b3df
movq 0x28(%rsp), %rdi
addq $0x12, %rdi
leaq 0x404ba(%rip), %rsi     # 0x5b81b
callq 0x14ae0
testb $0x1, %al
jne 0x1b3df
movq 0x30(%rsp), %rdi
addq $0x12, %rdi
leaq 0x404a1(%rip), %rsi     # 0x5b81b
callq 0x163d0
testb $0x1, %al
jne 0x1b388
jmp 0x1b425
movq 0x28(%rsp), %rdi
callq 0x1da00
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rdi
addq $0x12, %rdi
leaq 0x40474(%rip), %rsi     # 0x5b81b
callq 0x140c0
testb $0x1, %al
jne 0x1b3b2
jmp 0x1b3c0
movq 0x10(%rsp), %rax
movl 0x70(%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0x1b3cf
movq 0x10(%rsp), %rax
movl 0xd0(%rax), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x1b425
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rax
movw 0x14(%rax), %ax
movw %ax, 0x1d(%rsp)
movzwl 0x1d(%rsp), %esi
callq 0x14c70
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x1b270
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
addq $0x14, %rsi
callq 0x1dad0
jmp 0x1b457
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdi
addq $0xe8, %rsi
callq 0x1d010
movl %eax, %ecx
movq 0x10(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0xc8(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0xc8(%rax)
jmp 0x1b459
movq 0x28(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x28(%rsp)
jmp 0x1b2c1
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)