// File: liujan[P]MPI_multi_thread_randomforest/RandomForest.cpp
// Function: build(void*)
void* build(void *arg){
	M t1 = (M)(*((M*)arg));
	RandomForest *rf = t1.rf;
	int t = t1.i;
	if (rf->test_samples.empty()){
		cout << "[Error] test sample is empty" << endl;
		return NULL;
	}

	Tree *tree = new Tree();
	if (tree->readSample(rf->all_samples)){
		cout << t  << "  ";
		tree->buildTree();
		for (int j = 0; j < rf->test_samples.size(); j++){
			int id = rf->test_samples[j].first;
			int type = tree->predict(rf->test_samples[j].second);
			result[t][id][type]++;
		}
	}
	delete tree;
	
	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
addq $0x18, %rdi
callq 0xda40
testb $0x1, %al
jne 0x15603
jmp 0x15632
movq 0x139c6(%rip), %rdi     # 0x28fd0
leaq 0x7af4(%rip), %rsi      # 0x1d105
callq 0x9660
movq %rax, %rdi
movq 0x13988(%rip), %rsi     # 0x28fa8
callq 0x96b0
movq $0x0, -0x8(%rbp)
jmp 0x15845
movl $0x8, %edi
callq 0x9670
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x90(%rbp)
callq 0xc400
jmp 0x15650
movq -0x90(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0xdc40
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0xc470
movb %al, -0x91(%rbp)
jmp 0x15695
leaq -0x60(%rbp), %rdi
callq 0xa330
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x156ad
jmp 0x1580f
movl -0x2c(%rbp), %esi
movq 0x13919(%rip), %rdi     # 0x28fd0
callq 0x9be0
movq %rax, %rdi
leaq 0x7a5c(%rip), %rsi      # 0x1d122
callq 0x9660
movq -0x38(%rbp), %rdi
callq 0xc630
movl $0x0, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rdi
addq $0x18, %rdi
callq 0xa860
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0x1580d
movq -0x28(%rbp), %rdi
addq $0x18, %rdi
movslq -0x64(%rbp), %rsi
callq 0xdaf0
movl (%rax), %eax
movl %eax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x18, %rdi
movslq -0x64(%rbp), %rsi
callq 0xdaf0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0xaea0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0xd740
movl %eax, -0xb4(%rbp)
jmp 0x1576d
leaq -0x88(%rbp), %rdi
callq 0xa580
movl -0xb4(%rbp), %eax
movl %eax, -0x6c(%rbp)
movslq -0x2c(%rbp), %rcx
leaq 0x13f83(%rip), %rax     # 0x29710
imulq $0x291b4, %rcx, %rcx    # imm = 0x291B4
addq %rcx, %rax
movslq -0x68(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x156db
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x8, %esi
callq 0x9690
jmp 0x15852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xa330
jmp 0x15852
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xa580
jmp 0x15852
jmp 0x1580f
movq -0x38(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
je 0x1583d
movq -0xd0(%rbp), %rdi
callq 0xd930
movq -0xd0(%rbp), %rdi
movl $0x8, %esi
callq 0x9690
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x9c10
nopl (%rax,%rax)