// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r13
movq 0x12a5a(%rip), %rdi     # 0x16fa8
leaq -0x34(%rbp), %rsi
callq 0x33e0
movq 0x8(%rbx), %rdi
callq 0x3a4d
leaq 0x12df9(%rip), %r14     # 0x17360
cmpl (%r14), %eax
movq %r13, -0x30(%rbp)
jle 0x4717
movq 0x8(%r13), %rax
movslq 0x30(%rbx), %rcx
shlq $0x6, %rcx
movl 0x1c(%rax,%rcx), %r15d
movq 0x8(%rbx), %rdi
callq 0x3a4d
testl %eax, %eax
jle 0x4637
xorl %r12d, %r12d
leaq 0x12e10(%rip), %r14     # 0x173b0
leaq 0x12de9(%rip), %r13     # 0x17390
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rbx), %rdi
movq 0x8(%rdi), %rcx
movslq (%rcx,%r12,4), %rcx
shlq $0x6, %rcx
cmpl $0x0, 0x28(%rax,%rcx)
jne 0x45cf
leaq 0x12e0b(%rip), %rdx     # 0x173d8
incl (%rdx)
addq %rcx, %rax
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x28(%rax)
movl $0x1, 0x30(%rax)
movq (%r14), %rcx
movslq 0x1c(%rax), %rdx
cmpl $0x1, (%rcx,%rdx,4)
je 0x4624
movl $0x1, (%rcx,%rdx,4)
movl 0x1c(%rax), %eax
movq (%r13), %rsi
movl %eax, (%rsi)
leaq 0x12dd5(%rip), %rax     # 0x173e0
movq (%rax), %rdi
callq 0x3c20
movq 0x58(%rbx), %rdi
movq (%r13), %rsi
callq 0x3c20
movq 0x8(%rbx), %rdi
incq %r12
callq 0x3a4d
cltq
cmpq %rax, %r12
jl 0x45a7
movq 0x10(%rbx), %rdi
callq 0x3a4d
testl %eax, %eax
movq -0x30(%rbp), %r13
jle 0x489e
xorl %r12d, %r12d
movq 0x8(%r13), %rax
movq 0x10(%rbx), %rdi
movq 0x8(%rdi), %rcx
movslq (%rcx,%r12,4), %rcx
shlq $0x6, %rcx
movslq 0x1c(%rax,%rcx), %rsi
movq %rsi, %r10
shlq $0x6, %r10
movslq %r15d, %r14
shlq $0x6, %r14
movl 0x14(%rax,%r10), %r8d
movl 0x14(%rax,%r14), %r11d
cmpl %r11d, %r8d
je 0x46f5
leaq (%rax,%r10), %rdx
leaq (%rax,%r14), %r9
leaq (%rax,%r10), %r13
addq $0x14, %r13
addq %rax, %r14
addq $0x14, %r14
movl %r15d, %r10d
cmpl %r11d, %r8d
jge 0x46b9
movl %r11d, (%r13)
cmpl %esi, %r8d
je 0x46ee
movslq %r8d, %rdx
shlq $0x6, %rdx
addq %rax, %rdx
jmp 0x46d4
movl %r8d, (%r14)
movq %r13, %r14
cmpl %r10d, %r11d
je 0x46ee
movslq %r11d, %r9
shlq $0x6, %r9
addq %rax, %r9
movl %r11d, %r10d
movl %esi, %r8d
movl %r8d, %esi
leaq 0x14(%rdx), %r13
movl 0x14(%rdx), %r8d
leaq 0x14(%r9), %r14
movl 0x14(%r9), %r11d
cmpl %r11d, %r8d
jne 0x469f
jmp 0x46f1
movl (%r14), %r15d
movq -0x30(%rbp), %r13
addq %rcx, %rax
movl $0x1, 0x30(%rax)
incq %r12
callq 0x3a4d
cltq
cmpq %rax, %r12
jl 0x464f
jmp 0x489e
movq 0x10(%rbx), %rdi
callq 0x3a4d
cmpl (%r14), %eax
jle 0x4897
movl $0x2, 0x20(%rbx)
movq 0x8(%r13), %rax
movslq 0x30(%rbx), %rcx
movq %rcx, %rsi
shlq $0x6, %rsi
leaq (%rax,%rsi), %rdx
cmpl $0x0, 0x28(%rax,%rsi)
jne 0x4753
leaq 0x12c87(%rip), %rsi     # 0x173d8
incl (%rsi)
movabsq $0x100000001, %rsi      # imm = 0x100000001
movq %rsi, 0x28(%rdx)
movl $0x1, 0x30(%rdx)
leaq 0x12c41(%rip), %rsi     # 0x173b0
movq (%rsi), %rsi
movslq 0x1c(%rdx), %rdi
cmpl $0x1, (%rsi,%rdi,4)
je 0x47b5
movl $0x1, (%rsi,%rdi,4)
movl 0x1c(%rdx), %eax
leaq 0x12c03(%rip), %r14     # 0x17390
movq (%r14), %rsi
movl %eax, (%rsi)
leaq 0x12c47(%rip), %rax     # 0x173e0
movq (%rax), %rdi
callq 0x3c20
movq 0x58(%rbx), %rdi
movq (%r14), %rsi
callq 0x3c20
movq 0x8(%r13), %rax
movslq 0x30(%rbx), %rcx
shlq $0x6, %rcx
movl 0x1c(%rax,%rcx), %r15d
movq 0x10(%rbx), %rdi
callq 0x3a4d
testl %eax, %eax
jle 0x489e
xorl %r12d, %r12d
movq 0x8(%r13), %rax
movq 0x10(%rbx), %rdi
movq 0x8(%rdi), %rcx
movslq (%rcx,%r12,4), %rcx
shlq $0x6, %rcx
movslq 0x1c(%rax,%rcx), %rdx
movq %rdx, %r11
shlq $0x6, %r11
movslq %r15d, %r14
shlq $0x6, %r14
movl 0x14(%rax,%r11), %r9d
movl 0x14(%rax,%r14), %r10d
cmpl %r10d, %r9d
je 0x4878
leaq (%rax,%r11), %rsi
leaq (%rax,%r14), %r8
leaq (%rax,%r11), %r13
addq $0x14, %r13
addq %rax, %r14
addq $0x14, %r14
movl %r15d, %r11d
cmpl %r10d, %r9d
jge 0x483c
movl %r10d, (%r13)
cmpl %edx, %r9d
je 0x4871
movslq %r9d, %rsi
shlq $0x6, %rsi
addq %rax, %rsi
jmp 0x4857
movl %r9d, (%r14)
movq %r13, %r14
cmpl %r11d, %r10d
je 0x4871
movslq %r10d, %r8
shlq $0x6, %r8
addq %rax, %r8
movl %edx, %r9d
movl %r10d, %r11d
movl %r9d, %edx
leaq 0x14(%rsi), %r13
movl 0x14(%rsi), %r9d
leaq 0x14(%r8), %r14
movl 0x14(%r8), %r10d
cmpl %r10d, %r9d
jne 0x4822
jmp 0x4874
movl (%r14), %r15d
movq -0x30(%rbp), %r13
addq %rcx, %rax
movl $0x1, 0x30(%rax)
incq %r12
callq 0x3a4d
cltq
cmpq %rax, %r12
jl 0x47d2
jmp 0x489e
movl $0x1, 0x20(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq