// File: /workspace/github_cpp_makefile_star2_O1/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 $0x27d8, %rsp           # imm = 0x27D8
movl %r9d, %r12d
movq %rdx, 0x80(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %rbx
callq 0x3060
movq %rax, 0x88(%rsp)
movl $0x10, %edi
callq 0x32b0
movq %rax, %rbp
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
leaq 0x60(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rbx, 0x10(%rsp)
movq (%rbx), %rsi
callq 0x597e
leaq 0x1450(%rsp), %rdi
callq 0x59b0
leaq 0x1450(%rsp), %rdi
callq 0x3370
movl %eax, %eax
movq %rax, 0xc8(%rsp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, 0xc8(%rsp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x4146
movq $0x270, 0x1448(%rsp) # imm = 0x270
leal -0x1(%r12), %eax
movl $0x0, 0x58(%rsp)
movl %eax, 0x5c(%rsp)
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
jle 0x41c9
xorl %r15d, %r15d
leaq 0xc8(%rsp), %rbx
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x6338
cltq
movq 0x60(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movq 0x10(%rsp), %rax
cmpq (%rax), %r15
jl 0x41a3
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
jle 0x4633
movslq %r12d, %r13
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movq %r12, 0x40(%rsp)
movq %rbp, 0x50(%rsp)
movq %r13, 0x48(%rsp)
movl $0x10, %edi
callq 0x32b0
movq %rax, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
movq $0x1, (%rax)
movl $0x8, %edi
callq 0x3030
movq %rax, 0x8(%rbx)
movq 0x18(%rsp), %rcx
movq %rcx, (%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %r15
movq (%r15,%rcx,8), %r13
movq 0x8(%r15,%rcx,8), %r12
movl $0x10, %edi
callq 0x32b0
movq %rax, %r14
subq %r13, %r12
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
movq %r12, (%rax)
leaq (,%r12,8), %rdi
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %r12
movq $-0x1, %rax
cmovaq %rax, %rdi
callq 0x3030
movq %rax, 0x8(%r14)
movq 0x18(%rsp), %rcx
movq (%r15,%rcx,8), %rsi
incq %rcx
shlq $0x3, %rsi
movq %rcx, 0x18(%rsp)
movq (%r15,%rcx,8), %rdx
shlq $0x3, %rdx
subq %rsi, %rdx
je 0x42b8
movq 0x30(%rsp), %rcx
addq 0x18(%rcx), %rsi
movq %rax, %rdi
callq 0x3440
movl $0x10, %edi
callq 0x32b0
movq 0x48(%rsp), %r13
movq %rax, %r15
movq %rbx, (%rax)
movq %r14, 0x8(%rax)
movl $0x10, %edi
callq 0x32b0
movq %r15, (%rax)
movq (%rbp), %rsi
movq %rsi, 0x8(%rax)
movl 0x8(%rbp), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x8(%rbp)
movq %rsi, (%rbp)
movq $0x0, 0x8(%rax)
movl %ecx, 0x8(%rbp)
movq 0x40(%rsp), %r12
movq %rax, 0x90(%rsp)
movq (%rax), %rax
movq (%rax), %r15
movq 0x8(%rax), %rbx
movq (%r15), %r14
movq (%rbx), %rax
movq %rax, 0x38(%rsp)
addq %r14, %rax
cmpq %r13, %rax
jl 0x458c
cmpq %r13, %r14
jne 0x434a
movsd 0x8(%rsp), %xmm0
addsd 0x5cc9(%rip), %xmm0     # 0xa008
movsd %xmm0, 0x8(%rsp)
jmp 0x458c
cmpq $0x0, 0x38(%rsp)
jle 0x458c
movq 0x60(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x1(%r14), %rcx
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
movq %rcx, 0xb8(%rsp)
cmpq %rax, %rcx
leaq 0x8(,%r14,8), %rcx
movq $-0x1, %rax
cmovaq %rax, %rcx
movq %rcx, 0xb0(%rsp)
leaq (,%r14,8), %rax
movq %rax, 0xa0(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %r13
movq 0x18(%rax), %rax
movq %rax, 0x98(%rsp)
xorl %ecx, %ecx
movq %r15, 0xa8(%rsp)
movq 0x8(%rbx), %rax
movq %rcx, 0xc0(%rsp)
movq (%rax,%rcx,8), %r12
testq %r14, %r14
jle 0x4402
movq 0x8(%r15), %rax
movq 0x28(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movq 0x28(%rsp), %rdi
cmpq %rcx, (%rdi,%rsi,8)
je 0x456c
incq %rdx
cmpq %rdx, %r14
jne 0x43e7
movl $0x10, %edi
callq 0x32b0
movq %rax, %rcx
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
movq 0xb8(%rsp), %rax
movq %rax, (%rcx)
movq 0xb0(%rsp), %rdi
movq %rcx, 0x20(%rsp)
callq 0x3030
movq 0x20(%rsp), %rcx
movq %rax, %rbp
movq %rax, 0x8(%rcx)
testq %r14, %r14
je 0x4459
movq 0x8(%r15), %rsi
movq %rbp, %rdi
movq 0xa0(%rsp), %rdx
callq 0x3440
movq (%r15), %rax
movq %r12, (%rbp,%rax,8)
movq (%r13,%r12,8), %r15
movq 0x8(%r13,%r12,8), %rbp
movl $0x10, %edi
callq 0x32b0
movq %rax, %rdx
subq %r15, %rbp
movq 0x38(%rsp), %rax
cmpl %ebp, %eax
cmovlq %rax, %rbp
movslq %ebp, %rax
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdx)
movq %rax, (%rdx)
leaq (,%rax,8), %rdi
movabsq $0x1fffffffffffffff, %rcx # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rcx, %rax
movq $-0x1, %rax
cmovaq %rax, %rdi
movq %rdx, %rbp
callq 0x3030
movq %rax, 0x8(%rbp)
cmpq $0x0, (%rbx)
jle 0x4520
movslq (%r13,%r12,8), %rcx
movq 0x98(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
xorl %edx, %edx
xorl %esi, %esi
movq 0x50(%rsp), %r11
movq 0x8(%r13,%r12,8), %rdi
subq (%r13,%r12,8), %rdi
jle 0x4510
movq 0x8(%rbx), %r8
movq (%r8,%rdx,8), %r8
xorl %r9d, %r9d
cmpq (%rcx,%r9,8), %r8
je 0x4507
incq %r9
cmpq %r9, %rdi
jne 0x44f7
jmp 0x4510
movslq %esi, %rsi
movq %r8, (%rax,%rsi,8)
incl %esi
incq %rdx
cmpq %rdx, (%rbx)
jg 0x44e0
movq %r11, %r15
movslq %esi, %rax
jmp 0x4527
xorl %eax, %eax
movq 0x50(%rsp), %r15
movq %rax, (%rbp)
movl $0x10, %edi
callq 0x32b0
movq %rax, %r12
movq 0x20(%rsp), %rax
movq %rax, (%r12)
movq %rbp, 0x8(%r12)
movl $0x10, %edi
callq 0x32b0
movq %r12, (%rax)
movq %r15, %rbp
movq (%r15), %rcx
movq %rcx, 0x8(%rax)
movq %rax, (%r15)
incl 0x8(%r15)
movq 0xa8(%rsp), %r15
movq 0xc0(%rsp), %rcx
incq %rcx
cmpq 0x38(%rsp), %rcx
jne 0x43c3
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %r13
cmpq $0x0, (%rbx)
js 0x45a0
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x45a0
callq 0x3350
movl $0x10, %esi
movq %rbx, %rdi
callq 0x32c0
cmpq $0x0, (%r15)
jle 0x45c1
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x45c1
callq 0x3350
movl $0x10, %esi
movq %r15, %rdi
callq 0x32c0
movq 0x90(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x45e8
movl $0x10, %esi
callq 0x32c0
movl $0x10, %esi
movq %rbx, %rdi
callq 0x32c0
movq (%rbp), %rax
testq %rax, %rax
je 0x4613
movq 0x8(%rax), %rcx
movq %rcx, (%rbp)
movq $0x0, 0x8(%rax)
decl 0x8(%rbp)
jmp 0x4615
xorl %eax, %eax
testq %rax, %rax
jne 0x4303
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq (%rax), %rcx
jl 0x41fd
jmp 0x463d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq $0x0, (%rbp)
movl $0x10, %esi
movq %rbp, %rdi
callq 0x32c0
callq 0x3060
subq 0x88(%rsp), %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %r15
testl %r12d, %r12d
jle 0x4695
movsd 0x598c(%rip), %xmm0     # 0xa008
movl %r12d, %eax
movapd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm1
decl %eax
jne 0x4687
jmp 0x469d
movsd 0x596b(%rip), %xmm2     # 0xa008
movsd %xmm2, 0x28(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movapd %xmm0, %xmm1
callq 0x3490
movsd %xmm0, 0x20(%rsp)
movq 0x990f(%rip), %rdi      # 0xdfd0
leaq 0x59d0(%rip), %rsi      # 0xa098
movl $0xb, %edx
callq 0x3300
movq %r15, %rax
shrq $0x3f, %rax
sarq $0x7, %r15
addq %rax, %r15
movq 0x98e9(%rip), %rdi      # 0xdfd0
movq %r15, %rsi
callq 0x3260
movq %rax, %rbx
movq (%rax), %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
movq 0x98b0(%rip), %rdi      # 0xdfd0
leaq 0x5996(%rip), %rsi      # 0xa0bd
movl $0x14, %edx
callq 0x3300
movq 0x9898(%rip), %rdi      # 0xdfd0
movsd 0x8(%rsp), %xmm0
callq 0x3430
movq %rax, %rbx
movq (%rax), %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
movq 0x985c(%rip), %rdi      # 0xdfd0
leaq 0x5929(%rip), %rsi      # 0xa0a4
movl $0xe, %edx
callq 0x3300
movq 0x9844(%rip), %rdi      # 0xdfd0
movl %r12d, %esi
callq 0x3480
movq %rax, %rbx
movq (%rax), %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
movq 0x980b(%rip), %rdi      # 0xdfd0
leaq 0x58e7(%rip), %rsi      # 0xa0b3
movl $0x1e, %edx
callq 0x3300
movsd 0x8(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
divsd 0x28(%rsp), %xmm0
movq 0x97e1(%rip), %rdi      # 0xdfd0
movsd %xmm0, 0x8(%rsp)
callq 0x3430
movq %rax, %rbx
movq (%rax), %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
movq 0x80(%rsp), %rdi
movl %r12d, %esi
callq 0x3480
movq %rax, %rbx
leaq 0x58ad(%rip), %rsi      # 0xa0eb
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3430
movq %rax, %rbx
leaq 0x5888(%rip), %rsi      # 0xa0eb
movl $0x1, %edx
movq %rax, %rdi
callq 0x3300
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3260
movq %rax, %rbx
leaq 0x5866(%rip), %rsi      # 0xa0eb
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 0x1450(%rsp), %rdi
callq 0x3250
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x48dd
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0x27d8, %rsp           # imm = 0x27D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4935
jmp 0x4906
jmp 0x48f5
movq %rax, %rbx
jmp 0x4916
jmp 0x4906
jmp 0x4906
jmp 0x4906
jmp 0x4906
jmp 0x4906
jmp 0x4906
movq %rax, %rbx
leaq 0x1450(%rsp), %rdi
callq 0x3250
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x492d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x34a0
movq %rax, %rdi
callq 0x5b0d