// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %rsi, %rbx
movq %rdi, %r13
movq 0x129bd(%rip), %rdi     # 0x16fa8
leaq -0x2c(%rbp), %rsi
callq 0x33e0
movq 0x8(%rbx), %rdi
callq 0x3a4d
leaq 0x12d5c(%rip), %r14     # 0x17360
cmpl (%r14), %eax
jle 0x47a9
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 0x46ca
xorl %r12d, %r12d
leaq 0x12d57(%rip), %r14     # 0x17390
movq 0x8(%r13), %rax
movq 0x8(%rbx), %rcx
movq 0x8(%rcx), %rcx
movslq (%rcx,%r12,4), %rcx
shlq $0x6, %rcx
cmpl $0x0, 0x28(%rax,%rcx)
jne 0x465d
leaq 0x12d7d(%rip), %rdx     # 0x173d8
incl (%rdx)
addq %rcx, %rax
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x28(%rax)
movl $0x1, 0x30(%rax)
leaq 0x12d34(%rip), %rcx     # 0x173b0
movq (%rcx), %rcx
movslq 0x1c(%rax), %rdx
cmpl $0x1, (%rcx,%rdx,4)
je 0x46b3
movl $0x1, (%rcx,%rdx,4)
movl 0x1c(%rax), %eax
movq (%r14), %rsi
movl %eax, (%rsi)
leaq 0x12d41(%rip), %rax     # 0x173e0
movq (%rax), %rdi
callq 0x3c19
movq 0x58(%rbx), %rdi
movq (%r14), %rsi
callq 0x3c19
incq %r12
movq 0x8(%rbx), %rdi
callq 0x3a4d
cltq
cmpq %rax, %r12
jl 0x4639
movq 0x10(%rbx), %rdi
callq 0x3a4d
testl %eax, %eax
jle 0x4934
xorl %r12d, %r12d
movq 0x8(%r13), %rax
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %rcx
movslq (%rcx,%r12,4), %rcx
shlq $0x6, %rcx
movslq 0x1c(%rax,%rcx), %rdx
movl $0x1, 0x30(%rax,%rcx)
movq %rdx, %r9
shlq $0x6, %r9
movslq %r15d, %r11
shlq $0x6, %r11
movl 0x14(%rax,%r9), %edi
movl 0x14(%rax,%r11), %r10d
cmpl %r10d, %edi
je 0x4783
leaq (%rax,%r9), %rsi
leaq (%rax,%r11), %r8
leaq (%rax,%r9), %r14
addq $0x14, %r14
addq %rax, %r11
addq $0x14, %r11
movl %r15d, %r9d
cmpl %r10d, %edi
jge 0x474e
movl %r10d, (%r14)
cmpl %edx, %edi
je 0x4780
movslq %edi, %rsi
shlq $0x6, %rsi
addq %rax, %rsi
jmp 0x4768
movl %edi, (%r11)
movq %r14, %r11
cmpl %r9d, %r10d
je 0x4780
movslq %r10d, %r8
shlq $0x6, %r8
addq %rax, %r8
movl %r10d, %r9d
movl %edx, %edi
movl %edi, %edx
leaq 0x14(%rsi), %r14
movl 0x14(%rsi), %edi
leaq 0x14(%r8), %r11
movl 0x14(%r8), %r10d
cmpl %r10d, %edi
jne 0x4736
jmp 0x4783
movl (%r11), %r15d
addq %rcx, %rax
movl $0x1, 0x30(%rax)
incq %r12
movq 0x10(%rbx), %rdi
callq 0x3a4d
cltq
cmpq %rax, %r12
jl 0x46de
jmp 0x4934
movq 0x10(%rbx), %rdi
callq 0x3a4d
cmpl (%r14), %eax
jle 0x492d
movl $0x2, 0x20(%rbx)
movq 0x8(%r13), %rcx
movslq 0x30(%rbx), %rdx
shlq $0x6, %rdx
leaq (%rcx,%rdx), %rax
cmpl $0x0, 0x28(%rcx,%rdx)
jne 0x47e2
leaq 0x12bf8(%rip), %rcx     # 0x173d8
incl (%rcx)
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x28(%rax)
movl $0x1, 0x30(%rax)
leaq 0x12bb2(%rip), %rcx     # 0x173b0
movq (%rcx), %rcx
movslq 0x1c(%rax), %rdx
cmpl $0x1, (%rcx,%rdx,4)
je 0x483c
movl $0x1, (%rcx,%rdx,4)
movl 0x1c(%rax), %eax
leaq 0x12b74(%rip), %r14     # 0x17390
movq (%r14), %rsi
movl %eax, (%rsi)
leaq 0x12bb8(%rip), %rax     # 0x173e0
movq (%rax), %rdi
callq 0x3c19
movq 0x58(%rbx), %rdi
movq (%r14), %rsi
callq 0x3c19
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 0x4934
xorl %r12d, %r12d
movq 0x8(%r13), %rax
movq 0x10(%rbx), %rcx
movq 0x8(%rcx), %rcx
movslq (%rcx,%r12,4), %rcx
shlq $0x6, %rcx
movslq 0x1c(%rax,%rcx), %rdx
movl $0x1, 0x30(%rax,%rcx)
movq %rdx, %r10
shlq $0x6, %r10
movslq %r15d, %r11
shlq $0x6, %r11
movl 0x14(%rax,%r10), %r8d
movl 0x14(%rax,%r11), %r9d
cmpl %r9d, %r8d
je 0x490a
leaq (%rax,%r10), %rsi
leaq (%rax,%r11), %rdi
leaq (%rax,%r10), %r14
addq $0x14, %r14
addq %rax, %r11
addq $0x14, %r11
movl %r15d, %r10d
cmpl %r9d, %r8d
jge 0x48d2
movl %r9d, (%r14)
cmpl %edx, %r8d
je 0x4907
movslq %r8d, %rsi
shlq $0x6, %rsi
addq %rax, %rsi
jmp 0x48ed
movl %r8d, (%r11)
movq %r14, %r11
cmpl %r10d, %r9d
je 0x4907
movslq %r9d, %rdi
shlq $0x6, %rdi
addq %rax, %rdi
movl %edx, %r8d
movl %r9d, %r10d
movl %r8d, %edx
leaq 0x14(%rsi), %r14
movl 0x14(%rsi), %r8d
leaq 0x14(%rdi), %r11
movl 0x14(%rdi), %r9d
cmpl %r9d, %r8d
jne 0x48b9
jmp 0x490a
movl (%r11), %r15d
addq %rcx, %rax
movl $0x1, 0x30(%rax)
incq %r12
movq 0x10(%rbx), %rdi
callq 0x3a4d
cltq
cmpq %rax, %r12
jl 0x4861
jmp 0x4934
movl $0x1, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq