// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %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 0x5672
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 0x36f0
cmpl $0xc, %ebx
jg 0x3b6d
testl %eax, %eax
js 0x3b6d
cmpl $0x5, 0x2c(%r15)
jl 0x3b6d
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
cmpq %rcx, %rax
je 0x3980
movq 0x38(%r15), %rdx
subq 0x30(%r15), %rdx
shrq $0x3, %rdx
imull $0xcccccccd, %edx, %edx # imm = 0xCCCCCCCD
cmpl %edx, (%rax)
je 0x3b6d
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x396f
movl %ebx, 0xc(%rsp)
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x29d4
movq %r14, 0x50(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x3bf8
movq %rax, 0x20(%r15)
leaq 0xb0(%rsp), %rdi
callq 0x2a6e
xorl %eax, %eax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq (%r12), %r13
movq 0x8(%r12), %r14
cmpq %r14, %r13
je 0x3a6c
leaq 0x60(%rsp), %r12
leaq 0x10(%rsp), %rbx
leaq 0x58(%rsp), %rbp
movl (%r13), %eax
movl %eax, 0x58(%rsp)
addq $0x8, %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x2dc4
movq 0x18(%r13), %rax
movq %rax, 0x78(%rsp)
movslq 0x20(%r15), %rsi
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x3b7f
movss 0x24(%r15), %xmm0
ucomiss (%rax,%rsi,4), %xmm0
movq %rbx, %rdi
jb 0x3a44
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x53c4
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x3a63
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
addq $0x20, %r13
cmpq %r14, %r13
jne 0x39f2
movl $0x58, %edi
callq 0x2170
movl 0xc(%rsp), %ebx
movq 0x50(%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 0x98(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x29d4
incl %ebx
movq %r15, %rdi
callq 0x3664
leaq 0x98(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
movl %ebx, %ecx
movl %eax, %r8d
callq 0x38e4
leaq 0x98(%rsp), %rdi
callq 0x2a6e
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 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x29d4
movq %r15, %rdi
callq 0x3664
leaq 0x80(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
movl %ebx, %ecx
movl %eax, %r8d
callq 0x38e4
leaq 0x80(%rsp), %rdi
callq 0x2a6e
leaq 0x10(%rsp), %rdi
callq 0x2a6e
leaq 0x30(%rsp), %rdi
callq 0x2a6e
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3666(%rip), %rdi      # 0x71ec
xorl %eax, %eax
callq 0x21d0
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x3ba5
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2a6e
jmp 0x3bdc
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x3beb
jmp 0x3bbb
movq %rax, %rbx
jmp 0x3bdc
jmp 0x3bc2
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x3bdc
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
leaq 0x10(%rsp), %rdi
callq 0x2a6e
leaq 0x30(%rsp), %rdi
callq 0x2a6e
movq %rbx, %rdi
callq 0x2240