// File: 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
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq 0xf5c2(%rip), %rdi      # 0x37fa8
leaq -0xc(%rbp), %rsi
callq 0x99e0
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x9c80
movq -0xc8(%rbp), %rdx
leaq 0x36d9(%rip), %rsi      # 0x2c0fb
leaq -0x50(%rbp), %rdi
callq 0x9960
jmp 0x28a2d
leaq -0x51(%rbp), %rdi
callq 0x9720
leaq -0xa8(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x1be20
jmp 0x28a48
leaq 0xfd01(%rip), %rsi      # 0x38750
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
callq 0x28e60
jmp 0x28a64
leaq -0x50(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
leaq -0x88(%rbp), %rsi
movq %rsi, -0xe0(%rbp)
callq 0x9820
movq -0xe0(%rbp), %rdi
callq 0x93d0
leaq -0xa8(%rbp), %rdi
callq 0x93d0
movq -0xd8(%rbp), %rdi
callq 0x9240
movq %rax, %rdi
leaq 0x3854(%rip), %rsi      # 0x2c304
callq 0x97b0
movq %rax, -0xd0(%rbp)
jmp 0x28abe
movq -0xd0(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x28c0d
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jne 0x28b6e
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x28b6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x9720
jmp 0x28c79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x28c70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x93d0
jmp 0x28c70
movq -0xb8(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x28b84
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0xb0(%rbp), %rax
movl 0x14(%rax), %eax
movq -0xb0(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x28bfd
movq -0xb0(%rbp), %rax
movl 0x18(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x28bfd
movq -0xb0(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jne 0x28bfd
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movl -0x18(%rbp), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0xb0(%rbp), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movq -0xb0(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0x28bff
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x28ad0
movl $0x1, %edi
movl $0xc, %esi
callq 0x9400
movq %rax, -0xc0(%rbp)
movl -0x20(%rbp), %ecx
movq -0xc0(%rbp), %rax
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0xc0(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x24(%rbp), %ecx
movq -0xc0(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0xc0(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x93d0
movq -0xe8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x93d0
movq -0x60(%rbp), %rdi
callq 0x9c70
nopw %cs:(%rax,%rax)
nopl (%rax)