// File: ADAPTLab[P]MuDBSCAN/MuC.cpp
// Function: processGroupSequential(dataHdr*, group*)
void processGroupSequential(DataHdr dataList, Group g)
{
    int myrank;
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

    if(VECTOR_TOTAL(g->inner_points) >= MINPOINTS + 1)
    {
        int i;
        Data master = dataList->dataClstElem + g->master_id; // CORE POINT
        int root = master->id;

        for(i=0; i<VECTOR_TOTAL(g->inner_points); i++)
        {
            Data data = dataList->dataClstElem + g->inner_points->intItems[i];

            if(data->core_tag == FALSE) totalCore++;

            data->core_tag = TRUE; // ALL INNER POINTS ARE CORE POINTS
            data->isProcessed = TRUE;
            data->ClusterID = 1;
            if(visited[data->id] != 1)
            {
                visited[data->id] = 1;
                addHelper[0] = data->id;
                VECTOR_ADD(unprocessedCore, addHelper);
                VECTOR_ADD(g->corepoints, addHelper);
            }
        }
        i = 0;
        Data datalocal;
        Data dataroot1;
        Data dataroot2;
        for(i=0; i<VECTOR_TOTAL(g->total_points); i++)
        {
            datalocal = dataList->dataClstElem + g->total_points->intItems[i];

            int npid = datalocal->id;

            int root1 = npid;
            int root2 = root;

            datalocal->ClusterID = 1;

             dataroot1 = dataList->dataClstElem + root1;
             dataroot2 = dataList->dataClstElem + root2; //MASTER - CORE POINT

            while(dataroot1->parentId != dataroot2->parentId)
            {
                if(dataroot1->parentId < dataroot2->parentId)
                {
                    if(dataroot1->parentId == root1)
                    {
                        dataroot1->parentId = dataroot2->parentId;
                        root = dataroot2->parentId;
                        break;
                    }

                    // splicing comression technique
                    int z = dataroot1->parentId;
                    dataroot1->parentId = dataroot2->parentId;
                    root1 = z;
                    dataroot1 = dataList->dataClstElem + root1;
                }
                else
                {
                    if(dataroot2->parentId == root2)
                    {
                        dataroot2->parentId = dataroot1->parentId;
                        root = dataroot1->parentId;
                        break;
                    }

                    // splicing compressio technique
                    int z = dataroot2->parentId;
                    dataroot2->parentId = dataroot1->parentId;                
                    root2 = z;
                    dataroot2 = dataList->dataClstElem + root2;
                }
            }
            datalocal->ClusterID = 1;
        }
    }
    else if(VECTOR_TOTAL(g->total_points) >= MINPOINTS + 1)
    {
        int i;

        g->type = COREGROUP;
        Data data = dataList->dataClstElem + g->master_id;

        if(data->core_tag == FALSE) totalCore++;

        data->core_tag = TRUE;

        data->isProcessed = TRUE; //Later in the dbscan() method this point will not undergo neighbourhood query.
        data->ClusterID = 1; //These are core points. They are inherently members of a cluster.
       
        if(visited[data->id] != 1)
        {
            visited[data->id] = 1;
            addHelper[0] = data->id;
            VECTOR_ADD(unprocessedCore, addHelper);
            VECTOR_ADD(g->corepoints, addHelper);
        }

        Data master = dataList->dataClstElem + g->master_id;
        int root = master->id;
        Data datalocal;
        Data dataroot1;
        Data dataroot2;
        for(i=0; i<VECTOR_TOTAL(g->total_points); i++)
        {
            datalocal = dataList->dataClstElem + g->total_points->intItems[i];

            int npid = datalocal->id;

            int root1 = npid;
            int root2 = root;

            datalocal->ClusterID = 1;

            dataroot1 = dataList->dataClstElem + root1;
            dataroot2 = dataList->dataClstElem + root2;

            // REMS algorithm to (union) merge the trees
            // UNION OPERATION
            while(dataroot1->parentId != dataroot2->parentId)
            {
                if(dataroot1->parentId < dataroot2->parentId)
                {
                    if(dataroot1->parentId == root1)
                    {
                        dataroot1->parentId = dataroot2->parentId;
                        root = dataroot2->parentId;
                        break;
                    }

                    // splicing comression technique
                    int z = dataroot1->parentId;
                    dataroot1->parentId = dataroot2->parentId;
                    root1 = z;
                    dataroot1 = dataList->dataClstElem + root1;
                }
                else
                {
                    if(dataroot2->parentId == root2)
                    {
                        dataroot2->parentId = dataroot1->parentId;
                        root = dataroot1->parentId;
                        break;
                    }

                    // splicing compressio technique
                    int z = dataroot2->parentId;
                    dataroot2->parentId = dataroot1->parentId;                
                    root2 = z;
                    dataroot2 = dataList->dataClstElem + root2;
                }
            }

            datalocal->ClusterID = 1;
        }
    }
    else
    {
        g->type = SPARSEGROUP;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x276fe(%rip), %rdi     # 0x37fa8
leaq -0x14(%rbp), %rsi
callq 0x99e0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xa2b0
leaq 0x27f09(%rip), %rcx     # 0x387d0
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jl 0x10bbd
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x30(%rcx), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xa2b0
movl %eax, %ecx
movl -0xa8(%rbp), %eax
cmpl %ecx, %eax
jge 0x10a11
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movslq -0x18(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x1096c
leaq 0x27eea(%rip), %rax     # 0x38848
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x27ede(%rip), %rax     # 0x38848
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl $0x1, 0x28(%rax)
movq -0x30(%rbp), %rax
movl $0x1, 0x2c(%rax)
movq -0x30(%rbp), %rax
movl $0x1, 0x30(%rax)
leaq 0x27e8c(%rip), %rax     # 0x38820
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0x10a01
leaq 0x27e74(%rip), %rax     # 0x38820
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
movl $0x1, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %ecx
leaq 0x27e34(%rip), %rax     # 0x38800
movq (%rax), %rax
movl %ecx, (%rax)
leaq 0x27e78(%rip), %rax     # 0x38850
movq (%rax), %rdi
leaq 0x27e1e(%rip), %rax     # 0x38800
movq (%rax), %rsi
callq 0xa6e0
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
leaq 0x27e07(%rip), %rax     # 0x38800
movq (%rax), %rsi
callq 0xa6e0
jmp 0x10a03
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x10900
movl $0x0, -0x18(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xa2b0
movl %eax, %ecx
movl -0xac(%rbp), %eax
cmpl %ecx, %eax
jge 0x10bb8
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x8(%rcx), %rcx
movslq -0x18(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x50(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x54(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x14(%rcx), %eax
je 0x10b9f
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x10b3f
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x50(%rbp), %eax
jne 0x10b08
movq -0x48(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x48(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x10b9f
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x58(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x50(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x10b9a
movq -0x48(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0x10b65
movq -0x40(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x10b9f
movq -0x48(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x40(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x5c(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x54(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x10abb
movq -0x38(%rbp), %rax
movl $0x1, 0x30(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x10a1f
jmp 0x10f05
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xa2b0
leaq 0x27bff(%rip), %rcx     # 0x387d0
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jl 0x10ef8
movq -0x10(%rbp), %rax
movl $0x2, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x30(%rcx), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x10c23
leaq 0x27c33(%rip), %rax     # 0x38848
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x27c27(%rip), %rax     # 0x38848
movl %ecx, (%rax)
movq -0x68(%rbp), %rax
movl $0x1, 0x28(%rax)
movq -0x68(%rbp), %rax
movl $0x1, 0x2c(%rax)
movq -0x68(%rbp), %rax
movl $0x1, 0x30(%rax)
leaq 0x27bd5(%rip), %rax     # 0x38820
movq (%rax), %rax
movq -0x68(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
cmpl $0x1, (%rax,%rcx,4)
je 0x10cb8
leaq 0x27bbd(%rip), %rax     # 0x38820
movq (%rax), %rax
movq -0x68(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
movl $0x1, (%rax,%rcx,4)
movq -0x68(%rbp), %rax
movl 0x1c(%rax), %ecx
leaq 0x27b7d(%rip), %rax     # 0x38800
movq (%rax), %rax
movl %ecx, (%rax)
leaq 0x27bc1(%rip), %rax     # 0x38850
movq (%rax), %rdi
leaq 0x27b67(%rip), %rax     # 0x38800
movq (%rax), %rsi
callq 0xa6e0
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
leaq 0x27b50(%rip), %rax     # 0x38800
movq (%rax), %rsi
callq 0xa6e0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x30(%rcx), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x74(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xa2b0
movl %eax, %ecx
movl -0xb0(%rbp), %eax
cmpl %ecx, %eax
jge 0x10ef6
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x8(%rcx), %rcx
movslq -0x60(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0x80(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x98(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x90(%rbp), %rcx
cmpl 0x14(%rcx), %eax
je 0x10edd
movq -0x88(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x90(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x10e56
movq -0x88(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x98(%rbp), %eax
jne 0x10e04
movq -0x90(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x90(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x10edd
movq -0x88(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0xa0(%rbp)
movq -0x90(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0xa0(%rbp), %eax
movl %eax, -0x98(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x98(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
jmp 0x10ed8
movq -0x90(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x9c(%rbp), %eax
jne 0x10e8b
movq -0x88(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x90(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x88(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x10edd
movq -0x90(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0x88(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x90(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0xa4(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
jmp 0x10d98
movq -0x80(%rbp), %rax
movl $0x1, 0x30(%rax)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x10ce4
jmp 0x10f03
movq -0x10(%rbp), %rax
movl $0x1, 0x20(%rax)
jmp 0x10f05
addq $0xb0, %rsp
popq %rbp
retq
nop