// File: /workspace/github_cpp_makefile_star2_O3/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), %r13
cmpq %r13, %r15
je 0x51a0
movq %rdi, %r14
leaq 0x51ba(%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, %r12
movq %rax, 0x30(%r14)
movl $0x6c, %edi
callq 0x2030
movq %rax, (%r12,%rbx,8)
movq 0x30(%r14), %r12
movq (%r12,%rbx,8), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x5c(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
incq %rbx
cmpq $0x617, %rbx            # imm = 0x617
jne 0x5075
cmpl $0x0, -0x2c(%rbp)
jle 0x5152
movq %r13, -0x38(%rbp)
movq %r15, -0x40(%rbp)
xorl %eax, %eax
leaq -0x273(%rip), %r12      # 0x4e5d
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 0x50ee
xorl %ebx, %ebx
movq -0x90(%rbp,%rbx,8), %rdi
xorl %esi, %esi
callq 0x21d0
incq %rbx
cmpq $0x8, %rbx
jne 0x5119
movq -0x48(%rbp), %rdi
callq 0x2290
movq -0x50(%rbp), %rax
addl $0x8, %eax
cmpl -0x2c(%rbp), %eax
jl 0x50d0
movq 0x30(%r14), %r12
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r13
xorl %eax, %eax
leaq 0x50b5(%rip), %r9       # 0xa210
movq (%r12,%rax,8), %rcx
movq %r9, %rdx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
movq $-0x148da0, %r8         # imm = 0xFFEB7260
addl 0x148da0(%rdx,%r8), %edi
movl %edi, (%rcx,%rsi,4)
addq $0x291b4, %r8           # imm = 0x291B4
jne 0x516e
incq %rsi
addq $0x4, %rdx
cmpq $0x1b, %rsi
jne 0x5164
incq %rax
addq $0x6c, %r9
cmpq $0x617, %rax            # imm = 0x617
jne 0x515b
jmp 0x51e2
movq 0x4e29(%rip), %rbx      # 0x9fd0
leaq 0x1f92(%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 %r13, %r15
setne %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop