// File: /workspace/github_cpp_makefile_star2_O1/liujan[P]MPI_multi_thread_randomforest/RandomForest.cpp
// Function: RandomForest::buildTree(int)
bool RandomForest::buildTree(int num){
	if (all_samples.empty()){
		cout << "[Error] all sample is empty" << endl;
		return false;
	}

	memset(result, 0, sizeof(result));
	r = new int*[numOfTest];
	for (int i = 0; i < numOfTest; i++){
		r[i] = new int[numOfTypes+1];
		for (int j = 0; j < numOfTypes + 1; j++)
			r[i][j] = 0;
	}

	for (int i = 0; i < num; i+=numOfThread){
		pthread_t thread[numOfThread];
		M *m = new M[numOfThread];
		for (int j = 0; j < numOfThread; j++){
			m[j].rf = this;
			m[j].i = j;
			pthread_create(&thread[j], NULL, build, &(m[j]));
		}
		for (int j = 0; j < numOfThread; j++)
			pthread_join(thread[j], NULL);
		
		delete[] m;
	}
	

	for (int i = 0; i < numOfTest; i++){
		for (int j = 0; j < numOfTypes + 1; j++){
			for (int k = 0; k < numOfThread; k++){
				r[i][j] += result[k][i][j];
			}
		}
	}
	
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, -0x2c(%rbp)
movq (%rdi), %r15
movq 0x8(%rdi), %r12
cmpq %r12, %r15
je 0x51cc
movq %rdi, %r14
movq %r12, -0x38(%rbp)
movq %r15, -0x40(%rbp)
leaq 0x5186(%rip), %rdi      # 0xa210
xorl %ebx, %ebx
movl $0x148da0, %edx         # imm = 0x148DA0
xorl %esi, %esi
callq 0x2120
movl $0x30b8, %edi           # imm = 0x30B8
callq 0x2030
movq %rax, 0x30(%r14)
movl $0x6c, %edi
callq 0x2030
movq 0x30(%r14), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x30(%r14), %rax
movq (%rax,%rbx,8), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x5c(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
incq %rbx
cmpq $0x617, %rbx            # imm = 0x617
jne 0x50a6
cmpl $0x0, -0x2c(%rbp)
jle 0x516f
xorl %eax, %eax
leaq -0x270(%rip), %r12      # 0x4e89
movq %rax, -0x50(%rbp)
movl $0x80, %edi
callq 0x2030
movq %rax, %r13
movq %rax, -0x48(%rbp)
leaq -0x90(%rbp), %r15
xorl %ebx, %ebx
movq %r14, (%r13)
movl %ebx, 0x8(%r13)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r13, %rcx
callq 0x2370
incq %rbx
addq $0x8, %r15
addq $0x10, %r13
cmpq $0x8, %rbx
jne 0x5117
xorl %ebx, %ebx
movq -0x90(%rbp,%rbx,8), %rdi
xorl %esi, %esi
callq 0x21d0
incq %rbx
cmpq $0x8, %rbx
jne 0x5142
movq -0x48(%rbp), %rdi
callq 0x2290
movq -0x50(%rbp), %rax
addl $0x8, %eax
cmpl -0x2c(%rbp), %eax
jl 0x50f9
movq 0x30(%r14), %rax
xorl %ecx, %ecx
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r12
leaq 0x508c(%rip), %r10      # 0xa210
movq (%rax,%rcx,8), %rdx
movq %r10, %rsi
xorl %edi, %edi
movl (%rdx,%rdi,4), %r8d
movq $-0x148da0, %r9         # imm = 0xFFEB7260
addl 0x148da0(%rsi,%r9), %r8d
movl %r8d, (%rdx,%rdi,4)
addq $0x291b4, %r9           # imm = 0x291B4
jne 0x5198
incq %rdi
addq $0x4, %rsi
cmpq $0x1b, %rdi
jne 0x518d
incq %rcx
addq $0x6c, %r10
cmpq $0x617, %rcx            # imm = 0x617
jne 0x5184
jmp 0x520e
movq 0x4dfd(%rip), %rbx      # 0x9fd0
leaq 0x1f66(%rip), %rsi      # 0x7140
movl $0x1b, %edx
movq %rbx, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpq %r12, %r15
setne %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop