// File: /workspace/github_cpp_makefile_star2_O3/sjain12[P]CliqueCounting/tests/../Escape/CliquesColorCoding.h
// Function: cliques_color_coding(Escape::CGraph&, CDAG&, std::basic_ofstream<char, std::char_traits<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void cliques_color_coding(CGraph &CG, CDAG &DG, ofstream &of, string gname, string fname, int clique_size)
{    
    high_resolution_clock::time_point t_elim_s = high_resolution_clock::now();
    
    Stack* stack = newStack();
    VertexSet *path = NULL, *nbrs = NULL;
    vector<VertexIdx> color;
    color.resize(CG.nVertices);
    double num_cliques = 0, est = 0;
    std::random_device rd{}; // use to seed the rng 
    std::mt19937 rng{rd()}; // rng

    std::uniform_int_distribution<int> distribution(0,clique_size-1);
    int col = 0;
    for (VertexIdx i=0; i<CG.nVertices; i++)
    {
        col = distribution(rng); 
        color[i] = col;
    }

    for (VertexIdx c=0; c<CG.nVertices; c++)
    {
        path = newVertexSet(1);
        path->vertices[0] = c;
        nbrs = newVertexSet(DG.outlist.offsets[c+1] - DG.outlist.offsets[c]);
        std::copy(DG.outlist.nbors+DG.outlist.offsets[c], DG.outlist.nbors+DG.outlist.offsets[c+1], nbrs->vertices);
        PartialClique* pc = newPartialClique(path, nbrs);
        stack->push(pc);

        StackItem* si = stack->pop();
        while (si != NULL)
        {
            path = si->pc->path;
            nbrs = si->pc->nbrs;  // get the current path and its nbrs
            VertexIdx psize = path->nVertices, nsize = nbrs->nVertices;

            if (psize + nsize < clique_size)
            {
            }
            else if (psize == clique_size)
            {   
                num_cliques++;
            }
            else
            {
                for (VertexIdx i=0; i<nsize; i++)
                {
                    VertexIdx v = nbrs->vertices[i];
                    int flag = 0;
                    for (int j=0; j<psize; j++)
                    {
                        if (color[path->vertices[j]] == color[v])
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 1) continue;

                    VertexSet *new_path = newVertexSet(psize+1);
                    std::copy(path->vertices, path->vertices + psize, new_path->vertices);
                    new_path->vertices[path->nVertices] = v;   //added i to path

                    int s = DG.outlist.offsets[v+1]-DG.outlist.offsets[v], l = nsize;
                    if (l < s)
                    {
                        l = s;
                        s = nsize;
                    }

                    VertexSet *common = newVertexSet(s);
                    int k = 0, offset = DG.outlist.offsets[v];
                    for (int l =0; l < nbrs->nVertices; l++) {
                        for (int j=0; j<DG.outlist.offsets[v+1]-DG.outlist.offsets[v]; j++) {
                            if (nbrs->vertices[l] == DG.outlist.nbors[offset + j])
                            {
                                common->vertices[k] = nbrs->vertices[l];
                                k++;
                                break;
                            }
                        }
                    }

                    common->nVertices = k; 
                    PartialClique *pc = newPartialClique(new_path, common);
                    stack->push(pc);
                }
            }
            
        	if (nbrs->nVertices >= 0) delete[] nbrs->vertices;
            delete nbrs;
            if (path->nVertices > 0) delete[] path->vertices;
            delete path;
            delete si->pc;
            delete si;
            si = stack->pop();
        }
    }

    delStack(stack);

    high_resolution_clock::time_point t_elim_e = high_resolution_clock::now();
    auto duration_program = std::chrono::duration_cast<std::chrono::microseconds>( t_elim_e - t_elim_s ).count();
    
    double kfac = 1;

    for (int i=1; i<=clique_size; i++)
        kfac *= i;
    est = num_cliques * pow(clique_size, clique_size) / kfac; 

    cout << "time reqd: " << duration_program << endl;
	cout << "number of cliques = " << num_cliques << endl;
	cout << "clique size = " << clique_size << endl;
    cout << "estimated number of cliques = " << est << endl;

	of << clique_size << "," << est << "," << duration_program << "," << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x27e8, %rsp           # imm = 0x27E8
movl %r9d, %ebx
movq %rdx, 0x90(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, %r14
callq 0x3060
movq %rax, 0x98(%rsp)
movl $0x10, %edi
callq 0x32b0
movq %rax, %r13
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
leaq 0x70(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %r14, 0x38(%rsp)
movq (%r14), %rsi
callq 0x58f2
leaq 0x1460(%rsp), %rdi
callq 0x5924
leaq 0x1460(%rsp), %rdi
callq 0x3370
movl %eax, %eax
movq %rax, 0xd8(%rsp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, 0xd8(%rsp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x40cb
movq $0x270, 0x1458(%rsp) # imm = 0x270
movq %rbx, 0x18(%rsp)
leal -0x1(%rbx), %eax
movl $0x0, 0x68(%rsp)
movl %eax, 0x6c(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
jle 0x45dd
xorl %r15d, %r15d
leaq 0xd8(%rsp), %rbx
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x62a6
cltq
movq 0x70(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movq 0x38(%rsp), %rax
movq (%rax), %rax
cmpq %rax, %r15
jl 0x4139
testq %rax, %rax
jle 0x45dd
movslq 0x18(%rsp), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movq %r13, 0x48(%rsp)
movq %r15, 0xa0(%rsp)
movl $0x10, %edi
callq 0x32b0
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq $0x1, (%rax)
movl $0x8, %edi
callq 0x3030
movq 0x10(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rbx
movq (%rbx,%rcx,8), %r14
movq 0x8(%rbx,%rcx,8), %r12
movl $0x10, %edi
callq 0x32b0
movq %rax, %rbp
subq %r14, %r12
movq %r12, (%rax)
leaq (,%r12,8), %rdi
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %r12
movq $-0x1, %rax
cmovaq %rax, %rdi
callq 0x3030
movq %r12, %r14
movq %rax, 0x8(%rbp)
movq 0x20(%rsp), %rcx
movq (%rbx,%rcx,8), %rsi
incq %rcx
shlq $0x3, %rsi
movq %rcx, 0x20(%rsp)
movq (%rbx,%rcx,8), %rdx
shlq $0x3, %rdx
subq %rsi, %rdx
je 0x424a
movq 0x40(%rsp), %rcx
addq 0x18(%rcx), %rsi
movq %rax, %rdi
callq 0x3440
movl $0x10, %edi
callq 0x32b0
movq %rax, %r12
movq %r14, %rbx
movq 0x10(%rsp), %rax
movq %rax, (%r12)
movq %rbp, 0x8(%r12)
movl $0x10, %edi
callq 0x32b0
movq %rax, %r14
movq %r12, (%rax)
movq (%r13), %rsi
movl 0x8(%r13), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x8(%r13)
movq $0x0, 0x8(%r14)
movl $0x1, %ecx
movl %edx, 0x8(%r13)
leaq (%rbx,%rcx), %rax
cmpq %r15, %rax
jl 0x4530
cmpq %r15, %rcx
jne 0x42c3
movsd 0x8(%rsp), %xmm0
addsd 0x5d50(%rip), %xmm0     # 0xa008
movsd %xmm0, 0x8(%rsp)
jmp 0x4530
testq %rbx, %rbx
jle 0x4530
movq %rsi, 0x50(%rsp)
movq %rdx, 0x58(%rsp)
movq %r14, 0xa8(%rsp)
movq %rbx, 0x60(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x1(%rcx), %rdx
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
movq %rdx, 0xc8(%rsp)
cmpq %rax, %rdx
leaq 0x8(,%rcx,8), %rdx
movq $-0x1, %rax
cmovaq %rax, %rdx
movq %rdx, 0xc0(%rsp)
movq %rcx, %r14
leaq (,%rcx,8), %rax
movq %rax, 0xb8(%rsp)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %r12
movq 0x18(%rax), %rax
movq %rax, 0xb0(%rsp)
xorl %ecx, %ecx
movq 0x10(%rsp), %r15
movq %rbp, %rbx
movq 0x8(%rbp), %rax
movq %rcx, 0xd0(%rsp)
movq (%rax,%rcx,8), %rbp
testq %r14, %r14
jle 0x4392
movq 0x8(%r15), %rax
movq 0x30(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movq 0x30(%rsp), %rdi
cmpq %rcx, (%rdi,%rsi,8)
je 0x4503
incq %rdx
cmpq %rdx, %r14
jne 0x4377
movl $0x10, %edi
callq 0x32b0
movq %rax, %rcx
movq 0xc8(%rsp), %rax
movq %rax, (%rcx)
movq 0xc0(%rsp), %rdi
movq %rcx, 0x28(%rsp)
callq 0x3030
movq 0x28(%rsp), %rcx
movq %rax, %r13
movq %rax, 0x8(%rcx)
testq %r14, %r14
je 0x43e1
movq 0x8(%r15), %rsi
movq %r13, %rdi
movq 0xb8(%rsp), %rdx
callq 0x3440
movq (%r15), %rax
movq %rbp, (%r13,%rax,8)
movq (%r12,%rbp,8), %r15
movq 0x8(%r12,%rbp,8), %r13
movl $0x10, %edi
callq 0x32b0
movq %rax, %rdx
subq %r15, %r13
movq 0x60(%rsp), %rax
cmpl %r13d, %eax
cmovlq %rax, %r13
movslq %r13d, %rax
movq %rax, (%rdx)
leaq (,%rax,8), %rdi
movabsq $0x1fffffffffffffff, %rcx # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rcx, %rax
movq $-0x1, %rax
cmovaq %rax, %rdi
movq %rdx, %r15
callq 0x3030
movq %r15, %r11
movq %rax, 0x8(%r15)
movq (%rbx), %rsi
testq %rsi, %rsi
jle 0x44a6
movslq (%r12,%rbp,8), %rcx
movq 0xb0(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
xorl %edx, %edx
xorl %edi, %edi
movq 0x48(%rsp), %r13
movq 0x8(%r12,%rbp,8), %r8
subq (%r12,%rbp,8), %r8
jle 0x4496
movq 0x8(%rbx), %r9
movq (%r9,%rdx,8), %r9
xorl %r10d, %r10d
cmpq (%rcx,%r10,8), %r9
je 0x448a
incq %r10
cmpq %r10, %r8
jne 0x447a
jmp 0x4496
movslq %edi, %rdi
movq %r9, (%rax,%rdi,8)
incl %edi
movq (%rbx), %rsi
incq %rdx
cmpq %rdx, %rsi
jg 0x4464
movq %r13, %r15
movslq %edi, %rax
jmp 0x44ad
xorl %eax, %eax
movq 0x48(%rsp), %r15
movq %rax, (%r11)
movl $0x10, %edi
movq %r11, %r13
callq 0x32b0
movq %rax, %rbp
movq 0x28(%rsp), %rax
movq %rax, (%rbp)
movq %r13, 0x8(%rbp)
movl $0x10, %edi
callq 0x32b0
movq %rbp, (%rax)
movq 0x50(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq %r15, %r13
movq %rax, (%r15)
movq 0x58(%rsp), %rcx
incl %ecx
movq %rcx, 0x58(%rsp)
movl %ecx, 0x8(%r15)
movq %rax, 0x50(%rsp)
movq 0x10(%rsp), %r15
movq 0xd0(%rsp), %rcx
incq %rcx
cmpq 0x60(%rsp), %rcx
movq %rbx, %rbp
jne 0x4350
movq (%rbp), %rbx
movq 0xa0(%rsp), %r15
movq 0xa8(%rsp), %r14
testq %rbx, %rbx
js 0x4543
movq 0x8(%rbp), %rdi
testq %rdi, %rdi
je 0x4543
callq 0x3350
movl $0x10, %esi
movq %rbp, %rdi
callq 0x32c0
movq 0x10(%rsp), %rbx
cmpq $0x0, (%rbx)
jle 0x4569
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x4569
callq 0x3350
movl $0x10, %esi
movq %rbx, %rdi
callq 0x32c0
movq (%r14), %rdi
movl $0x10, %esi
callq 0x32c0
movl $0x10, %esi
movq %r14, %rdi
callq 0x32c0
movq (%r13), %r14
testq %r14, %r14
je 0x45ca
movq 0x8(%r14), %rsi
movq %rsi, (%r13)
movq $0x0, 0x8(%r14)
movl 0x8(%r13), %edx
decl %edx
movq (%r14), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rbp
movq %rcx, 0x10(%rsp)
movq (%rcx), %rcx
movq (%rbp), %rbx
jmp 0x4294
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
cmpq (%rax), %rcx
jl 0x4190
movl $0x10, %esi
movq %r13, %rdi
callq 0x32c0
callq 0x3060
subq 0x98(%rsp), %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rbx
movq 0x18(%rsp), %rax
testl %eax, %eax
jle 0x462e
movsd 0x59f0(%rip), %xmm0     # 0xa008
movapd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm1
decl %eax
jne 0x4620
jmp 0x4636
movsd 0x59d2(%rip), %xmm2     # 0xa008
movsd %xmm2, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x18(%rsp), %xmm0
movapd %xmm0, %xmm1
callq 0x3490
movsd %xmm0, 0x28(%rsp)
movq 0x9975(%rip), %rdi      # 0xdfd0
leaq 0x5a56(%rip), %rsi      # 0xa0b8
movl $0xb, %edx
callq 0x3300
movq %rbx, %rax
shrq $0x3f, %rax
sarq $0x7, %rbx
addq %rax, %rbx
movq 0x994f(%rip), %rdi      # 0xdfd0
movq %rbx, %rsi
callq 0x3260
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x9916(%rip), %rdi      # 0xdfd0
leaq 0x5a1c(%rip), %rsi      # 0xa0dd
movl $0x14, %edx
callq 0x3300
movq 0x98fe(%rip), %rdi      # 0xdfd0
movsd 0x8(%rsp), %xmm0
callq 0x3430
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x98c2(%rip), %rdi      # 0xdfd0
leaq 0x59af(%rip), %rsi      # 0xa0c4
movl $0xe, %edx
callq 0x3300
movq 0x98aa(%rip), %rdi      # 0xdfd0
movq 0x18(%rsp), %rsi
callq 0x3480
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x986f(%rip), %rdi      # 0xdfd0
leaq 0x596b(%rip), %rsi      # 0xa0d3
movl $0x1e, %edx
callq 0x3300
movsd 0x8(%rsp), %xmm0
mulsd 0x28(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
movq 0x9845(%rip), %rdi      # 0xdfd0
movsd %xmm0, 0x8(%rsp)
callq 0x3430
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x90(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x3480
movq %rax, %r14
leaq 0x592f(%rip), %rsi      # 0xa10b
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3430
movq %rax, %r14
leaq 0x590a(%rip), %rsi      # 0xa10b
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %rbx
leaq 0x58e8(%rip), %rsi      # 0xa10b
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x1460(%rsp), %rdi
callq 0x3250
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x487e
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0x27e8, %rsp           # imm = 0x27E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x48d9
jmp 0x48a7
jmp 0x4896
movq %rax, %rbx
jmp 0x48b7
jmp 0x48a7
jmp 0x48a7
jmp 0x48a7
jmp 0x48a7
jmp 0x48a7
jmp 0x48a7
movq %rax, %rbx
leaq 0x1460(%rsp), %rdi
callq 0x3250
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x48d1
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x34a0
movq %rax, %rdi
callq 0x5a84