// File: liujan[P]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));
	memset(r, 0, sizeof(r));

	for (int i = 0; i < num; i+=numOfThread){
		pthread_t thread[numOfThread];
		M *m = new M[numOfThread];
		//memset(flag, false, sizeof(flag));
		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
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x6090
testb $0x1, %al
jne 0xdec8
jmp 0xdef3
movq 0xb109(%rip), %rdi      # 0x18fd8
leaq 0x224f(%rip), %rsi      # 0x10125
callq 0x21f0
movq %rax, %rdi
movq 0xb0e3(%rip), %rsi      # 0x18fc8
callq 0x2230
movb $0x0, -0x1(%rbp)
jmp 0xe0aa
leaq 0xb336(%rip), %rdi      # 0x19230
xorl %esi, %esi
movl $0x148da0, %edx         # imm = 0x148DA0
callq 0x2100
movq -0x88(%rbp), %rdi
addq $0x30, %rdi
xorl %esi, %esi
movl $0x291b4, %edx          # imm = 0x291B4
callq 0x2100
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xe009
movl $0x80, %edi
callq 0x2030
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
cmpl $0x8, -0x6c(%rbp)
jge 0xdfb2
movq -0x88(%rbp), %rcx
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x6c(%rbp), %ecx
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movslq -0x6c(%rbp), %rax
leaq -0x60(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
movq -0x68(%rbp), %rcx
movslq -0x6c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x3a2(%rip), %rdx      # 0xdc00
callq 0x23a0
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xdf45
movl $0x0, -0x70(%rbp)
cmpl $0x8, -0x70(%rbp)
jge 0xdfdc
movslq -0x70(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x21e0
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0xdfb9
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0xdff9
movq -0x90(%rbp), %rdi
callq 0x22c0
jmp 0xdffb
movl -0x18(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x18(%rbp)
jmp 0xdf24
movl $0x0, -0x74(%rbp)
cmpl $0x617, -0x74(%rbp)     # imm = 0x617
jge 0xe0a6
movl $0x0, -0x78(%rbp)
cmpl $0x1b, -0x78(%rbp)
jge 0xe096
movl $0x0, -0x7c(%rbp)
cmpl $0x8, -0x7c(%rbp)
jge 0xe089
movq -0x88(%rbp), %rax
movslq -0x7c(%rbp), %rdx
leaq 0xb1e7(%rip), %rcx      # 0x19230
imulq $0x291b4, %rdx, %rdx    # imm = 0x291B4
addq %rdx, %rcx
movslq -0x74(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rcx
movslq -0x78(%rbp), %rdx
movl (%rcx,%rdx,4), %edx
addq $0x30, %rax
movslq -0x74(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xe031
jmp 0xe08b
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0xe024
jmp 0xe098
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xe010
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)