// File: /workspace/github_cpp_makefile_star2_O1/8igMac[P]random-forest/src/decision_tree.cpp
// Function: decision_tree::build_tree(node*, std::vector<data_inst, std::allocator<data_inst>>, int, int)
void decision_tree::build_tree(node* nodePtr, vector<data_inst> sampleSet, int depth, int parentMaj)
{
//	cout << "depth: " << depth << " sample size: " << sampleSet.size() << endl; //debug
	nodePtr->depth = depth;
	nodePtr->samplePool = sampleSet;
	nodePtr->numSample = sampleSet.size();
	nodePtr->parentMajCls = parentMaj;
	if (nodePtr->set_size_of_class() < 0)
		return;

	if (depth <= MAXDEPTH && 
			nodePtr->numSample >= MINSAMPLE &&
			!(nodePtr->poolPure()))
	{
		// select attribut
		nodePtr->attr = selectAttr(sampleSet);

		// split sample into two group
		vector<data_inst> leftSample, rightSample;
		for (auto sample: sampleSet)
		{
			if (sample.attr.at(nodePtr->attr.first) <= nodePtr->attr.second)
				leftSample.push_back(sample);
			else
				rightSample.push_back(sample);
		}

		// generate next node
		nodePtr->leftChild = new node;
		build_tree(nodePtr->leftChild, leftSample, depth+1, nodePtr->majClass());
		nodePtr->rightChild = new node;
		build_tree(nodePtr->rightChild, rightSample, depth+1, nodePtr->majClass());
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %r8d, %ebp
movl %ecx, %ebx
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movl %ecx, 0x28(%rsi)
leaq 0x30(%rsi), %rdi
movq %rdx, %rsi
callq 0x54ca
movq 0x8(%r12), %rax
subq (%r12), %rax
shrq $0x3, %rax
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
movl %eax, 0x2c(%r15)
movl %ebp, (%r15)
movq %r15, %rdi
callq 0x3666
cmpl $0xc, %ebx
jg 0x3ae4
testl %eax, %eax
js 0x3ae4
cmpl $0x5, 0x2c(%r15)
jl 0x3ae4
movq 0x8(%r15), %rcx
movq 0x10(%r15), %rax
cmpq %rax, %rcx
setne %sil
je 0x3909
movq 0x38(%r15), %rdx
subq 0x30(%r15), %rdx
shrq $0x3, %rdx
imull $0xcccccccd, %edx, %edx # imm = 0xCCCCCCCD
cmpl %edx, (%rcx)
je 0x3ae4
addq $0x4, %rcx
cmpq %rax, %rcx
setne %sil
je 0x3909
leaq 0x4(%rcx), %rdi
cmpl %edx, (%rcx)
movq %rdi, %rcx
jne 0x38f5
testb %sil, %sil
jne 0x3ae4
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x29d8
movq %r14, 0x40(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x3b6a
movq %rax, 0x20(%r15)
leaq 0xa0(%rsp), %rdi
callq 0x2a72
xorl %eax, %eax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %rax, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq (%r12), %r13
movq 0x8(%r12), %r14
cmpq %r14, %r13
je 0x39f4
movq %rsp, %r12
leaq 0x48(%rsp), %rbp
movl (%r13), %eax
movl %eax, 0x48(%rsp)
addq $0x8, %r13
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x2db0
movq 0x18(%r13), %rax
movq %rax, 0x68(%rsp)
movslq 0x20(%r15), %rsi
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x3af6
movss 0x24(%r15), %xmm0
ucomiss (%rax,%rsi,4), %xmm0
movq %r12, %rdi
jb 0x39cc
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x5328
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x39eb
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
addq $0x20, %r13
cmpq %r14, %r13
jne 0x3978
movl $0x58, %edi
callq 0x2170
movq 0x40(%rsp), %r14
movq %rax, %r12
movl $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq $0x0, 0x50(%rax)
movq %rax, 0x48(%r15)
leaq 0x88(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x29d8
incl %ebx
movq %r15, %rdi
callq 0x35d8
leaq 0x88(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
movl %ebx, %ecx
movl %eax, %r8d
callq 0x385a
leaq 0x88(%rsp), %rdi
callq 0x2a72
movl $0x58, %edi
callq 0x2170
movq %rax, %r12
movl $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq $0x0, 0x50(%rax)
movq %rax, 0x50(%r15)
leaq 0x70(%rsp), %rdi
movq %rsp, %rsi
callq 0x29d8
movq %r15, %rdi
callq 0x35d8
leaq 0x70(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
movl %ebx, %ecx
movl %eax, %r8d
callq 0x385a
leaq 0x70(%rsp), %rdi
callq 0x2a72
movq %rsp, %rdi
callq 0x2a72
leaq 0x20(%rsp), %rdi
callq 0x2a72
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36c3(%rip), %rdi      # 0x71c0
xorl %eax, %eax
callq 0x21d0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x3b19
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2a72
jmp 0x3b50
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x3b5d
jmp 0x3b2f
movq %rax, %rbx
jmp 0x3b50
jmp 0x3b36
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3b50
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rsp, %rdi
callq 0x2a72
leaq 0x20(%rsp), %rdi
callq 0x2a72
movq %rbx, %rdi
callq 0x2240