// File: /workspace/github_cpp_makefile_star2_O3/ADAPTLab[P]MuDBSCAN/clustering.cpp
// Function: get_clusters_sequential(dataHdr*)
struct result* get_clusters_sequential(DataHdr dataList)
{
	int rank, nproc, i;
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	int root;
	int clusters = 0;
	int noise = 0;
	int totalcore = 0;

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

		if(datai->core_tag == TRUE)totalcore++;
		if(datai->ClusterID == 0) noise++;
		
		if(dataroot->parentId == dataroot->id && dataroot->parentProcessId == rank && dataroot->ClusterID==1) // root is a local root
		{
			datai = dataList->dataClstElem + i;
			datai->parentId = root;
			clusters++;
			dataroot->childCount = dataroot->childCount + 1;
		}

		// if(debug!=NULL){
		// 	fprintf(debug,"%lf\t%lf\t%lf\t%d\n",datai->iData[0],datai->iData[1],datai->iData[2],(int)datai->core_tag);
		// }

	}

	struct result* r;
	r = (struct result*)calloc(1, sizeof(struct result));
	r->noise = noise;
	r->clusters = clusters;
	r->corepoints = totalcore;
	
	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x7135(%rip), %rdi      # 0x16fa8
leaq -0x2c(%rbp), %r14
movq %r14, %rsi
callq 0x33e0
leaq -0x40(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x219b(%rip), %rdx      # 0x12029
leaq -0x50(%rbp), %rdi
movq %rdx, %rsi
callq 0xbad8
leaq -0x70(%rbp), %rdi
movq %r14, %rsi
callq 0xb3f7
leaq 0x7433(%rip), %r14      # 0x172e0
movq %r14, %rdi
callq 0x3120
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r14, %rcx
movq %rax, %r8
callq 0x32c0
leaq -0x80(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xfef0
movq %rdx, -0x90(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x80(%rbp)
jmp 0xfef8
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq -0x90(%rbp), %r14
movq %rdx, 0x8(%r14)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x3340
movq (%r14), %rdi
cmpq %r12, %rdi
je 0xff2f
callq 0x3270
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xff41
callq 0x3270
movq -0x50(%rbp), %rdi
leaq 0x2328(%rip), %rsi      # 0x12274
callq 0x3300
movslq 0x4(%rbx), %rax
testq %rax, %rax
jle 0xffb9
movq 0x8(%rbx), %rcx
addq $0x14, %rcx
xorl %edx, %edx
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %esi, %esi
cmpl $0x1, 0x14(%rcx)
movl (%rcx), %r9d
sete %dil
movl 0x1c(%rcx), %r8d
cmpl $0x1, %r8d
adcl $0x0, %r13d
cmpl 0x8(%rcx), %r9d
jne 0xffa5
movl 0x4(%rcx), %r9d
xorl -0x2c(%rbp), %r9d
xorl $0x1, %r8d
orl %r9d, %r8d
jne 0xffa5
movl %edx, (%rcx)
incl %r12d
incl 0x10(%rcx)
movb %dil, %sil
addl %esi, %r14d
incq %rdx
addq $0x40, %rcx
cmpq %rdx, %rax
jne 0xff6d
jmp 0xffc2
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
movl $0x1, %edi
movl $0xc, %esi
callq 0x31b0
movq %rax, %rbx
movl %r13d, (%rax)
movl %r12d, 0x4(%rax)
movl %r14d, 0x8(%rax)
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0xffed
callq 0x3270
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x10019
callq 0x3270
jmp 0x10019
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0x10027
callq 0x3270
movq %rbx, %rdi
callq 0x34c0
nop