// File: /workspace/github_cpp_makefile_star2_O3/ADAPTLab[P]MuDBSCAN/clustering.cpp
// Function: get_clusters_distributed(dataHdr*)
struct result* get_clusters_distributed(DataHdr dataList)
{
	int rank, nproc, i;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &nproc);

	vector < vector <int > > merge_received;
	vector < vector <int > > merge_send1;
	vector < vector <int > > merge_send2;
	vector <int> init;

	merge_received.resize(nproc, init);
	merge_send1.resize(nproc, init);
	merge_send2.resize(nproc, init);

	int pid;

    for(pid = 0; pid < nproc; pid++)
	{
    	merge_received[pid].reserve(dataList->localCnt);
    	merge_send1[pid].reserve(dataList->localCnt);
		merge_send2[pid].reserve(dataList->localCnt);
	}

	vector < vector <int > >* pswap;
	vector < vector <int > >* p_cur_send;
	vector < vector <int > >* p_cur_insert;

	p_cur_send = &merge_send1;
	p_cur_insert = &merge_send2;


	int root, local_continue_to_run = 0, global_continue_to_run;
	for(i = 0; i < dataList->localCnt; i++)
	{
		// find the point containing i
		root = i;
		Data dataroot = dataList->dataClstElem + root;
		// Find highest ancestor in this node
		while(dataroot->parentProcessId == rank)
		{
			if(dataroot->parentId == root)
				break;
			root = dataroot->parentId;
			dataroot = dataList->dataClstElem + root;
		}
		
		// if the highest ancestor from the previous loop is local point
		if(dataroot->parentId == root && dataroot->parentProcessId == rank) // root is a local root
		{
			Data datai = dataList->dataClstElem + i;
			datai->parentId = root;
			dataroot->childCount = dataroot->childCount + 1;
		}
		else
		{
			(*p_cur_insert)[dataroot->parentProcessId].push_back(0); // flag: 0 means query and 1 means a reply
			(*p_cur_insert)[dataroot->parentProcessId].push_back(dataroot->parentId);
   			(*p_cur_insert)[dataroot->parentProcessId].push_back(i);
			(*p_cur_insert)[dataroot->parentProcessId].push_back(rank);
			local_continue_to_run++;
		}			
	}

	int pos, round = 0, quadraples, scount, tid, tag = 0, rtag, rsource, rcount, isend[nproc], irecv[nproc], flag;

	MPI_Request s_req_recv[nproc], s_req_send[nproc], d_req_send[nproc], d_req_recv[nproc]; // better to malloc the memory
	MPI_Status  s_stat, d_stat_send[nproc], d_stat;
	int target_point, source_point, source_pr;

	while(1)
	{
		global_continue_to_run = 0;

		MPI_Allreduce(&local_continue_to_run, &global_continue_to_run, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
		
		if(global_continue_to_run == 0)
    		break;

		pswap = p_cur_insert;
   		p_cur_insert = p_cur_send;
   		p_cur_send = pswap;

		for(tid = 0; tid < nproc; tid++)
   			(*p_cur_insert)[tid].clear();

		scount = 0;
		for(tid = 0; tid < nproc; tid++)
		{
			if(tid != rank)
			{
				isend[tid] = (*p_cur_send)[tid].size();
				if(isend[tid] > 0)
	    		{
	    			MPI_Isend(&(*p_cur_send)[tid][0], isend[tid], MPI_INT, tid, tag + 1, MPI_COMM_WORLD, &d_req_send[scount]);
	        		scount++;
	    		}	
			}
		}

		MPI_Alltoall(&isend[0], 1, MPI_INT, &irecv[0], 1, MPI_INT, MPI_COMM_WORLD);

		rcount = 0;
		for(tid = 0; tid < nproc; tid++)
		{
			if(tid != rank)
			{
				if(irecv[tid] > 0)
				{
					merge_received[tid].clear();
					merge_received[tid].assign(irecv[tid], -1);
					MPI_Irecv(&merge_received[tid][0], irecv[tid], MPI_INT, tid, tag + 1, MPI_COMM_WORLD, &d_req_recv[rcount]);
					rcount++;
				}
			}
		}

		local_continue_to_run = 0;
		Data dataroot;
		Data datatarget;
		for(tid = 0; tid < rcount; tid++)
		{
			MPI_Waitany(rcount, &d_req_recv[0], &pos, &d_stat);
		
			rtag = d_stat.MPI_TAG;
			rsource = d_stat.MPI_SOURCE;

			if(rtag == tag + 1)
			{
				quadraples = merge_received[rsource].size()/4;

				for(pid = 0; pid < quadraples; pid++)
				{
					source_pr = merge_received[rsource].back();
					merge_received[rsource].pop_back();

        			source_point = merge_received[rsource].back();
        			merge_received[rsource].pop_back();

        			target_point = merge_received[rsource].back();
        			merge_received[rsource].pop_back();
		
					flag = merge_received[rsource].back();
        			merge_received[rsource].pop_back();

					if(flag == 0)
					{					
						root = target_point;
						dataroot = dataList->dataClstElem + root;
						while(dataroot->parentProcessId == rank)
						{
							if(dataroot->parentId == root)
								break;
							root = dataroot->parentId;
							dataroot = dataList->dataClstElem + root;
						}
						if(dataroot->parentId == root && dataroot->parentProcessId == rank) // root is a local root
						{
							dataroot->childCount = dataroot->childCount + 1; // increase the child count by one
							// have to return the child about root
							
            				(*p_cur_insert)[source_pr].push_back(1);
            				(*p_cur_insert)[source_pr].push_back(source_point);
            				(*p_cur_insert)[source_pr].push_back(dataroot->parentId);
            				(*p_cur_insert)[source_pr].push_back(dataroot->parentProcessId);
							local_continue_to_run++;
						}
						else
						{
							(*p_cur_insert)[dataroot->parentProcessId].push_back(0);
							(*p_cur_insert)[dataroot->parentProcessId].push_back(dataroot->parentId);
		         			(*p_cur_insert)[dataroot->parentProcessId].push_back(source_point);
        	    			(*p_cur_insert)[dataroot->parentProcessId].push_back(source_pr);
							local_continue_to_run++;
						}
					}
					else
					{
						datatarget = dataList->dataClstElem + target_point;
						datatarget->parentId = source_point;
						datatarget->parentProcessId = source_pr;
					}
				}
			}
		}
		tag++;
		round++;

		if(scount > 0)
			MPI_Waitall(scount, &d_req_send[0], &d_stat_send[0]); // wait for all the sending operation
	}

	int final_cluster_root = 0, total_final_cluster_root = 0;
	int points_in_cluster_final = 0, total_points_in_cluster_final = 0;
	int noise = 0;

	/*FILE* debug;
	string currFile("");
	currFile = neighbourFileName + patch::to_string(rank);
	debug = fopen(currFile.c_str(), "w");
*/
	Data datai;
	for(i = 0; i < dataList->localCnt; i++)
	{

		datai = dataList->dataClstElem + i;

		if(datai->ClusterID == 0 && datai->haloPoint == FALSE) noise++;

		//fprintf(debug, "%d_%d\t%d_%d\t%d\t%d\n", datai->id, datai->actualProcessId, datai->parentId, datai->parentProcessId, datai->ClusterID, datai->core_tag);
		
		if(datai->parentId == i && datai->parentProcessId == rank && datai->childCount >= 1)
		{
			points_in_cluster_final += datai->childCount;
			final_cluster_root++;
		}

	}

	MPI_Allreduce(&final_cluster_root, &total_final_cluster_root, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);

	struct result* result = (struct result*)calloc(1, sizeof(struct result));

	result->noise = noise;
	result->clusters = total_final_cluster_root;
	result->corepoints = -1;

	merge_received.clear();
	merge_send1.clear();
	merge_send2.clear();
	init.clear();

	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %r12
movq 0x849e(%rip), %rbx      # 0x16fa8
leaq -0x34(%rbp), %rsi
movq %rbx, %rdi
callq 0x33e0
leaq -0x2c(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32e0
xorl %eax, %eax
leaq -0xb0(%rbp), %rdi
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq %rax, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
movq %rax, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
leaq -0x100(%rbp), %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
movslq (%r14), %rsi
callq 0xb622
movslq -0x2c(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movq %rdi, -0x88(%rbp)
callq 0xb622
movslq -0x2c(%rbp), %rsi
leaq -0x80(%rbp), %r14
leaq -0x100(%rbp), %rdx
movq %r14, %rdi
callq 0xb622
movl -0x2c(%rbp), %ecx
testl %ecx, %ecx
jle 0xebee
xorl %ebx, %ebx
xorl %r15d, %r15d
movq -0xb0(%rbp), %rdi
addq %rbx, %rdi
movslq 0x4(%r12), %rsi
callq 0x10030
movq -0xd0(%rbp), %rdi
addq %rbx, %rdi
movslq 0x4(%r12), %rsi
callq 0x10030
movq -0x80(%rbp), %rdi
addq %rbx, %rdi
movslq 0x4(%r12), %rsi
callq 0x10030
incq %r15
movslq -0x2c(%rbp), %rcx
addq $0x18, %rbx
cmpq %rcx, %r15
jl 0xeba5
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
movq $0x0, -0x50(%rbp)
movl %eax, -0x40(%rbp)
movl 0x4(%r12), %eax
testl %eax, %eax
movq %r12, -0x60(%rbp)
jle 0xed5a
xorl %ecx, %ecx
leaq -0x130(%rbp), %r15
leaq -0x40(%rbp), %r12
leaq -0x34(%rbp), %r13
movq -0x60(%rbp), %rdx
movq 0x8(%rdx), %rdx
movslq %ecx, %rsi
movl -0x34(%rbp), %edi
shlq $0x6, %rsi
leaq (%rdx,%rsi), %rbx
movl 0x18(%rdx,%rsi), %r8d
cmpl %edi, %r8d
jne 0xec62
movl 0x14(%rbx), %r9d
cmpl %ecx, %r9d
je 0xed3c
movslq %r9d, %rcx
shlq $0x6, %rcx
leaq (%rdx,%rcx), %rbx
movl 0x18(%rdx,%rcx), %r8d
movl %r9d, %ecx
jmp 0xec3b
movslq %r8d, %rcx
movq -0x80(%rbp), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movl $0x0, -0x130(%rbp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xec95
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xeca1
movq %r15, %rdx
callq 0x10274
movq -0x80(%rbp), %rax
leaq 0x14(%rbx), %rdx
movslq 0x18(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xecc9
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xecd2
callq 0x5002
movq -0x80(%rbp), %rax
movslq 0x18(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xecf7
movl -0x40(%rbp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xed03
movq %r12, %rdx
callq 0x5002
movq -0x80(%rbp), %rax
movslq 0x18(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xed28
movl -0x34(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xed30
movq %r13, %rdx
callq 0x5002
incl -0x3c(%rbp)
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
jmp 0xed43
movl %ecx, 0x14(%rdx,%rsi)
incl 0x24(%rbx)
movl -0x40(%rbp), %ecx
incl %ecx
movl %ecx, -0x40(%rbp)
cmpl %eax, %ecx
jl 0xec20
movl -0x2c(%rbp), %ecx
movq -0x60(%rbp), %r12
movq %rsp, -0x108(%rbp)
movl %ecx, %eax
movq %rsp, %rcx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xe0(%rbp)
movq %rcx, %rsp
movl -0x2c(%rbp), %eax
movq %rsp, %rdx
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
subq %rcx, %rdx
movq %rdx, -0x90(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rdx
movq %rdx, -0xd8(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, -0xe8(%rbp)
movq %rdx, %rsp
movq %rsp, %rcx
leaq (%rax,%rax,2), %rax
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x110(%rbp)
movq %rcx, %rsp
movq -0x88(%rbp), %r15
movq %r14, -0x88(%rbp)
movl $0x0, -0x68(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x1, %edx
movq 0x81bd(%rip), %rcx      # 0x16fd0
movq 0x8176(%rip), %r8       # 0x16f90
movq 0x8187(%rip), %r9       # 0x16fa8
callq 0x3350
cmpl $0x0, -0x68(%rbp)
je 0xf2f5
movslq -0x2c(%rbp), %rax
testq %rax, %rax
jle 0xef0c
movq (%r15), %rcx
movq %rax, %rdx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
movq (%rcx,%rsi), %rdi
cmpq %rdi, 0x8(%rcx,%rsi)
je 0xee5d
movq %rdi, 0x8(%rcx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0xee4d
movl $0x0, -0x44(%rbp)
testl %eax, %eax
jle 0xef13
movq -0x50(%rbp), %rcx
leal 0x1(%rcx), %r14d
xorl %r12d, %r12d
movl $0x2, %ebx
movl $0x0, -0x44(%rbp)
movl -0x34(%rbp), %ecx
cmpq %rcx, %r12
je 0xeefb
movq -0x88(%rbp), %rcx
movq (%rcx), %rcx
movq -0x8(%rcx,%rbx,4), %rdi
movq (%rcx,%rbx,4), %rsi
subq %rdi, %rsi
shrq $0x2, %rsi
movq -0xe0(%rbp), %rcx
movl %esi, (%rcx,%r12,4)
testl %esi, %esi
jle 0xeefb
movl -0x44(%rbp), %r13d
movslq %r13d, %rax
movq -0xd8(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
subq $0x8, %rsp
movq 0x80f6(%rip), %rdx      # 0x16fd0
movl %r12d, %ecx
movl %r14d, %r8d
movq 0x80c1(%rip), %r9       # 0x16fa8
pushq %rax
callq 0x3130
addq $0x10, %rsp
incl %r13d
movl %r13d, -0x44(%rbp)
movl -0x2c(%rbp), %eax
incq %r12
movslq %eax, %rcx
addq $0x6, %rbx
cmpq %rcx, %r12
jl 0xee8c
jmp 0xef13
movl $0x0, -0x44(%rbp)
subq $0x8, %rsp
movq -0xe0(%rbp), %rdi
movl $0x1, %esi
movq 0x80a6(%rip), %rdx      # 0x16fd0
movq -0x90(%rbp), %rcx
movl $0x1, %r8d
movq %rdx, %r9
movq 0x8067(%rip), %r14      # 0x16fa8
pushq %r14
callq 0x3170
addq $0x10, %rsp
movq -0x60(%rbp), %r12
movl -0x2c(%rbp), %eax
testl %eax, %eax
jle 0xf2bb
movq -0x50(%rbp), %rcx
incl %ecx
movl %ecx, -0x54(%rbp)
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %edi, %edi
movl -0x34(%rbp), %ecx
cmpq %rcx, %r13
je 0xf004
movq -0x90(%rbp), %rcx
movslq (%rcx,%r13,4), %rsi
testq %rsi, %rsi
jle 0xf004
movl %edi, %r14d
movq -0xb0(%rbp), %rcx
leaq (%rcx,%rbx), %rdi
movq (%rcx,%rbx), %rax
cmpq %rax, 0x8(%rcx,%rbx)
je 0xefa4
movq %rax, 0x8(%rdi)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
leaq -0x30(%rbp), %rdx
callq 0x1010e
movq -0xb0(%rbp), %rax
movq (%rax,%rbx), %rdi
movq -0x90(%rbp), %rax
movl (%rax,%r13,4), %esi
movslq %r14d, %rax
movq -0xe8(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
subq $0x8, %rsp
movq 0x7fed(%rip), %rdx      # 0x16fd0
movl %r13d, %ecx
movl -0x54(%rbp), %r8d
movq 0x7fb7(%rip), %r9       # 0x16fa8
pushq %rax
callq 0x33c0
addq $0x10, %rsp
incl %r14d
movl -0x2c(%rbp), %eax
movl %r14d, %edi
incq %r13
movslq %eax, %rcx
addq $0x18, %rbx
cmpq %rcx, %r13
jl 0xef6b
movl $0x0, -0x3c(%rbp)
testl %edi, %edi
jle 0xf2c2
xorl %ebx, %ebx
movl %edi, -0x94(%rbp)
movq -0xe8(%rbp), %rsi
leaq -0x114(%rbp), %rdx
leaq -0x130(%rbp), %rcx
callq 0x3390
movl %ebx, -0x50(%rbp)
movq %r15, %r14
movl -0x54(%rbp), %eax
cmpl %eax, -0x12c(%rbp)
jne 0xf29c
movslq -0x130(%rbp), %rax
movq -0xb0(%rbp), %rcx
leaq (%rax,%rax,2), %r12
movq 0x8(%rcx,%r12,8), %rbx
subq (%rcx,%r12,8), %rbx
shrq $0x4, %rbx
testl %ebx, %ebx
jle 0xf29c
xorl %r15d, %r15d
movq -0xb0(%rbp), %rax
movq 0x8(%rax,%r12,8), %rdi
movslq -0x4(%rdi), %rcx
movl %ecx, -0x38(%rbp)
movl -0x8(%rdi), %esi
movl %esi, -0x48(%rbp)
movl -0xc(%rdi), %edx
leaq -0x10(%rdi), %r8
cmpl $0x0, -0x10(%rdi)
movq %r8, 0x8(%rax,%r12,8)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
je 0xf0d1
movslq %edx, %rcx
shlq $0x6, %rcx
movl %esi, 0x14(%rax,%rcx)
movl -0x38(%rbp), %edx
movl %edx, 0x18(%rax,%rcx)
jmp 0xf290
movl -0x34(%rbp), %esi
movslq %edx, %rdi
shlq $0x6, %rdi
leaq (%rax,%rdi), %r13
movslq 0x18(%rax,%rdi), %rdi
cmpl %esi, %edi
jne 0xf129
movl 0x14(%r13), %edi
cmpl %edx, %edi
movl %edi, %edx
jne 0xf0d4
incl 0x24(%r13)
movq (%r14), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movl $0x1, -0x30(%rbp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf1ee
movl $0x1, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf1fa
movq (%r14), %rax
leaq (%rdi,%rdi,2), %rcx
leaq (%rax,%rcx,8), %rdi
movl $0x0, -0x30(%rbp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf155
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf161
leaq -0x30(%rbp), %rdx
callq 0x10274
movq (%r14), %rax
leaq 0x14(%r13), %rdx
movslq 0x18(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf189
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf191
callq 0x5002
movq (%r14), %rax
movslq 0x18(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf1b6
movl -0x48(%rbp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf1c2
leaq -0x48(%rbp), %rdx
callq 0x5002
movq (%r14), %rax
movslq 0x18(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf1e0
movl -0x38(%rbp), %eax
jmp 0xf279
leaq -0x38(%rbp), %rdx
callq 0x5002
jmp 0xf28d
leaq -0x30(%rbp), %rdx
callq 0x10274
movq (%r14), %rax
movslq -0x38(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf21f
movl -0x48(%rbp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf22b
leaq -0x48(%rbp), %rdx
callq 0x5002
movq (%r14), %rax
leaq 0x14(%r13), %rdx
movslq -0x38(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf253
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf25b
callq 0x5002
movq (%r14), %rax
addq $0x18, %r13
movslq -0x38(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf285
movl (%r13), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf28d
movq %r13, %rdx
callq 0x5002
incl -0x3c(%rbp)
incl %r15d
cmpl %ebx, %r15d
jne 0xf087
movl -0x50(%rbp), %ebx
incl %ebx
movl -0x94(%rbp), %edi
cmpl %edi, %ebx
movq -0x60(%rbp), %r12
movq %r14, %r15
jne 0xf02e
movl -0x54(%rbp), %eax
jmp 0xf2c8
movl $0x0, -0x3c(%rbp)
movq -0x50(%rbp), %rax
incl %eax
movq %rax, -0x50(%rbp)
movq %r15, %r14
movl -0x44(%rbp), %edi
testl %edi, %edi
jle 0xedea
movq -0xd8(%rbp), %rsi
movq -0x110(%rbp), %rdx
callq 0x3320
movq %r15, %r14
jmp 0xedea
xorl %r14d, %r14d
movl %r14d, -0x30(%rbp)
movl %r14d, -0x64(%rbp)
movslq 0x4(%r12), %rax
movl %r14d, -0x40(%rbp)
testq %rax, %rax
jle 0xf356
movq 0x8(%r12), %rcx
movl -0x34(%rbp), %edx
addq $0x8, %rcx
xorl %esi, %esi
xorl %r14d, %r14d
xorl %edi, %edi
cmpl $0x0, 0x28(%rcx)
jne 0xf32e
cmpl $0x1, (%rcx)
adcl $0x0, %r14d
movl 0xc(%rcx), %r8d
cmpq %r8, %rsi
jne 0xf347
cmpl %edx, 0x10(%rcx)
jne 0xf347
cmpl $0x0, 0x1c(%rcx)
jle 0xf347
incl %edi
movl %edi, -0x30(%rbp)
incq %rsi
movl %esi, -0x40(%rbp)
addq $0x40, %rcx
cmpq %rsi, %rax
jne 0xf321
movq 0x7c73(%rip), %rcx      # 0x16fd0
movq 0x7c2c(%rip), %r8       # 0x16f90
movq 0x7c3d(%rip), %r9       # 0x16fa8
leaq -0x30(%rbp), %rdi
leaq -0x64(%rbp), %rsi
movl $0x1, %edx
callq 0x3350
movl $0x1, %edi
movl $0xc, %esi
callq 0x31b0
movq %rax, %rbx
movl %r14d, (%rax)
movl -0x64(%rbp), %eax
movl %eax, 0x4(%rbx)
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
movq -0xb0(%rbp), %r14
movq -0xa8(%rbp), %r15
cmpq %r14, %r15
je 0xf3d3
movq %r14, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0xf3c3
callq 0x3270
addq $0x18, %r12
cmpq %r15, %r12
jne 0xf3b5
movq %r14, -0xa8(%rbp)
movq -0xd0(%rbp), %r14
movq -0xc8(%rbp), %r15
cmpq %r14, %r15
je 0xf407
movq %r14, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0xf3f7
callq 0x3270
addq $0x18, %r12
cmpq %r15, %r12
jne 0xf3e9
movq %r14, -0xc8(%rbp)
movq -0x80(%rbp), %r14
movq -0x78(%rbp), %r15
cmpq %r14, %r15
je 0xf432
movq %r14, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0xf425
callq 0x3270
addq $0x18, %r12
cmpq %r15, %r12
jne 0xf417
movq %r14, -0x78(%rbp)
movq -0x100(%rbp), %rax
cmpq %rax, -0xf8(%rbp)
je 0xf449
movq %rax, -0xf8(%rbp)
movq -0x108(%rbp), %rsp
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0xf461
callq 0x3270
leaq -0x80(%rbp), %rdi
callq 0xb6a4
leaq -0xd0(%rbp), %rdi
callq 0xb6a4
leaq -0xb0(%rbp), %rdi
callq 0xb6a4
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
jmp 0xf4ae
movq %rax, %rbx
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0xf4c2
callq 0x3270
leaq -0x80(%rbp), %rdi
callq 0xb6a4
leaq -0xd0(%rbp), %rdi
callq 0xb6a4
leaq -0xb0(%rbp), %rdi
callq 0xb6a4
movq %rbx, %rdi
callq 0x34c0