// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq 0x10d91(%rip), %rdi     # 0x13fb0
leaq -0x2c(%rbp), %rsi
callq 0x2370
movq 0x8(%rbx), %rdi
callq 0x2831
leaq 0x110f8(%rip), %r15     # 0x14330
cmpl (%r15), %eax
jle 0x32f4
movq 0x8(%r14), %rax
movslq 0x30(%rbx), %rcx
shlq $0x6, %rcx
movl 0x1c(%rax,%rcx), %r15d
xorl %r12d, %r12d
leaq 0x11104(%rip), %r13     # 0x14360
movq 0x8(%rbx), %rdi
callq 0x2831
cltq
cmpq %rax, %r12
jge 0x3434
movq 0x8(%r14), %rax
movq 0x8(%rbx), %rcx
movq 0x8(%rcx), %rcx
movslq (%rcx,%r12,4), %rcx
shlq $0x6, %rcx
cmpl $0x0, 0x28(%rax,%rcx)
jne 0x3294
leaq 0x11116(%rip), %rdx     # 0x143a8
incl (%rdx)
addq %rcx, %rax
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x28(%rax)
movl $0x1, 0x30(%rax)
leaq 0x110cd(%rip), %rcx     # 0x14380
movq (%rcx), %rcx
movslq 0x1c(%rax), %rdx
cmpl $0x1, (%rcx,%rdx,4)
je 0x32ec
movl $0x1, (%rcx,%rdx,4)
movl 0x1c(%rax), %eax
movq (%r13), %rsi
movl %eax, (%rsi)
leaq 0x110d9(%rip), %rax     # 0x143b0
movq (%rax), %rdi
callq 0x29f0
movq 0x58(%rbx), %rdi
movq (%r13), %rsi
callq 0x29f0
incq %r12
jmp 0x325c
movq 0x10(%rbx), %rdi
callq 0x2831
cmpl (%r15), %eax
jle 0x34ce
movl $0x2, 0x20(%rbx)
movq 0x8(%r14), %rax
movslq 0x30(%rbx), %rcx
movq %rcx, %rsi
shlq $0x6, %rsi
leaq (%rax,%rsi), %rdx
cmpl $0x0, 0x28(%rax,%rsi)
jne 0x3330
leaq 0x1107a(%rip), %rsi     # 0x143a8
incl (%rsi)
movabsq $0x100000001, %rsi      # imm = 0x100000001
movq %rsi, 0x28(%rdx)
movl $0x1, 0x30(%rdx)
leaq 0x11034(%rip), %rsi     # 0x14380
movq (%rsi), %rsi
movslq 0x1c(%rdx), %rdi
cmpl $0x1, (%rsi,%rdi,4)
je 0x3392
movl $0x1, (%rsi,%rdi,4)
movl 0x1c(%rdx), %eax
leaq 0x10ff6(%rip), %r15     # 0x14360
movq (%r15), %rsi
movl %eax, (%rsi)
leaq 0x1103a(%rip), %rax     # 0x143b0
movq (%rax), %rdi
callq 0x29f0
movq 0x58(%rbx), %rdi
movq (%r15), %rsi
callq 0x29f0
movq 0x8(%r14), %rax
movslq 0x30(%rbx), %rcx
shlq $0x6, %rcx
movl 0x1c(%rax,%rcx), %r12d
movq 0x10(%rbx), %rdi
xorl %r15d, %r15d
callq 0x2831
cltq
cmpq %rax, %r15
jge 0x34d5
movq 0x8(%r14), %rcx
movq 0x10(%rbx), %rdi
movq 0x8(%rdi), %rax
movslq (%rax,%r15,4), %rdx
shlq $0x6, %rdx
leaq (%rcx,%rdx), %rax
movl 0x1c(%rcx,%rdx), %edx
movslq %r12d, %rsi
shlq $0x6, %rsi
addq %rcx, %rsi
movl %r12d, %r8d
movslq %edx, %r9
shlq $0x6, %r9
addq %rcx, %r9
addq $0x14, %r9
movl (%r9), %r13d
leaq 0x14(%rsi), %r10
movl 0x14(%rsi), %r11d
cmpl %r11d, %r13d
je 0x3425
jl 0x3412
movl %r13d, (%r10)
cmpl %r8d, %r11d
je 0x341f
movslq %r11d, %rsi
shlq $0x6, %rsi
addq %rcx, %rsi
movl %r11d, %r8d
jmp 0x33e9
movl %r11d, (%r9)
cmpl %edx, %r13d
movl %r13d, %edx
jne 0x33db
jmp 0x3422
movq %r9, %r10
movl (%r10), %r12d
movl $0x1, 0x30(%rax)
incq %r15
jmp 0x33a2
movq 0x10(%rbx), %rdi
xorl %r12d, %r12d
callq 0x2831
cltq
cmpq %rax, %r12
jge 0x34d5
movq 0x8(%r14), %rcx
movq 0x10(%rbx), %rdi
movq 0x8(%rdi), %rax
movslq (%rax,%r12,4), %rdx
shlq $0x6, %rdx
leaq (%rcx,%rdx), %rax
movslq 0x1c(%rcx,%rdx), %rsi
movq %rsi, %r8
shlq $0x6, %r8
addq %rcx, %r8
movl %r15d, %edx
movslq %edx, %r9
shlq $0x6, %r9
addq %rcx, %r9
addq $0x14, %r9
leaq 0x14(%r8), %r10
movl 0x14(%r8), %r11d
movl (%r9), %r13d
cmpl %r13d, %r11d
je 0x34bf
jge 0x34ac
movl %r13d, (%r10)
cmpl %esi, %r11d
je 0x34b9
movslq %r11d, %r8
shlq $0x6, %r8
addq %rcx, %r8
movl %r11d, %esi
jmp 0x3483
movl %r11d, (%r9)
cmpl %edx, %r13d
movl %r13d, %edx
jne 0x3475
jmp 0x34bc
movq %r9, %r10
movl (%r10), %r15d
movl $0x1, 0x30(%rax)
incq %r12
jmp 0x343b
movl $0x1, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq