// File: /workspace/github_cpp_makefile_star2_O2/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, (%rsp)
movl %ecx, 0x28(%rsi)
leaq 0x30(%rsi), %rdi
movq %rdx, %rsi
callq 0x4870
movq 0x8(%r12), %rax
subq (%r12), %rax
pushq $0x28
popq %rcx
cqto
idivq %rcx
movl %eax, 0x2c(%r15)
movl %ebp, (%r15)
movq %r15, %rdi
callq 0x32d2
movl %ebx, 0xc(%rsp)
cmpl $0xc, %ebx
jg 0x3677
testl %eax, %eax
js 0x3677
cmpl $0x5, 0x2c(%r15)
jl 0x3677
movq %r15, %rdi
callq 0x32a2
testb %al, %al
jne 0x3677
leaq 0x78(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x276e
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x36da
movq %rax, 0x20(%r15)
leaq 0x78(%rsp), %rdi
callq 0x27c8
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x30(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq (%r12), %r13
movq 0x8(%r12), %rbx
leaq 0x98(%rsp), %r12
leaq 0x90(%rsp), %rbp
cmpq %rbx, %r13
je 0x3599
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2c00
movslq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x494e
movss 0x24(%r15), %xmm0
ucomiss (%rax), %xmm0
movq %r14, %rdi
jb 0x3583
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x4706
movq %r12, %rdi
callq 0x2878
addq $0x28, %r13
jmp 0x3554
pushq $0x58
popq %rdi
callq 0x2160
movq %rax, %r12
andl $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
andq $0x0, 0x50(%rax)
movq %rax, 0x48(%r15)
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x276e
movl 0xc(%rsp), %ebp
incl %ebp
movq %r15, %rdi
callq 0x3262
leaq 0x60(%rsp), %rdx
movq (%rsp), %rdi
movq %r12, %rsi
movl %ebp, %ebx
movl %ebp, %ecx
movl %eax, %r8d
callq 0x3474
leaq 0x60(%rsp), %rdi
callq 0x27c8
pushq $0x58
popq %rdi
callq 0x2160
movq %rax, %r12
andl $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
andq $0x0, 0x50(%rax)
movq %rax, 0x50(%r15)
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x276e
movq %r15, %rdi
callq 0x3262
leaq 0x48(%rsp), %rdx
movq (%rsp), %rdi
movq %r12, %rsi
movl %ebx, %ecx
movl %eax, %r8d
callq 0x3474
leaq 0x48(%rsp), %rdi
callq 0x27c8
leaq 0x30(%rsp), %rdi
callq 0x27c8
leaq 0x10(%rsp), %rdi
callq 0x27c8
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x369b
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x27c8
jmp 0x36be
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x36cd
jmp 0x36ae
movq %rax, %rbx
jmp 0x36be
movq %rax, %rbx
movq %r12, %rdi
callq 0x2878
leaq 0x30(%rsp), %rdi
callq 0x27c8
leaq 0x10(%rsp), %rdi
callq 0x27c8
movq %rbx, %rdi
callq 0x2230