// File: sjain12[P]CliqueCounting/tests/../Escape/CliquesBruteForce.h
// Function: cliques_brute_force(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>>, unsigned long long)
void cliques_brute_force(CGraph &CG, CDAG &DG, ofstream &of, string gname, string fname, unsigned long long clique_size)
{    
    high_resolution_clock::time_point t_elim_s = high_resolution_clock::now();
    
    Stack* stack = newStack();
    VertexSet *path = NULL, *nbrs = NULL;
    double num_cliques = 0;

    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;

            int flag = 0;
            if (psize + nsize < clique_size)
            {
            }
            else if (psize == clique_size)
            {   
                num_cliques++;
            }
            else if (psize == clique_size - 1)
            {
                num_cliques += nsize;
            }
            else if (psize == clique_size - 2)
            {
                for (int i=0; i<nsize-1; i++)
                    for (int j=i+1; j<nsize; j++)
                        if (CG.isEdge(nbrs->vertices[i], nbrs->vertices[j]) != -1)
                            num_cliques++;
            }
            else
            {
                for (VertexIdx i=0; i<nsize; i++)
                {
                    VertexIdx v = nbrs->vertices[i];
                    VertexSet *new_path = newVertexSet(psize+1);

                    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;
                            }
                        }
                    }
                    if (k == 0) 
                    {
                        delete[] common->vertices;
                        delete common;
                        delete[] new_path->vertices;
                        continue;
                    }
                    else
                    {
                        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();
    
    cout << "time reqd: " << duration_program << endl;
	cout << "number of cliques = " << num_cliques << endl;
	cout << "clique size = " << clique_size << endl;

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
callq 0x3060
movq %rax, -0x38(%rbp)
callq 0x4350
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x4bbb
movl $0x1, %edi
callq 0x3fd0
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
subq (%rax,%rcx,8), %rdi
callq 0x3fd0
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x5a90
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x4270
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x43f0
movq -0x40(%rbp), %rdi
callq 0x4450
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x4ba8
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x78(%rbp), %rax
addq -0x80(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x46ff
jmp 0x4ab1
movq -0x78(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x4720
movsd 0xf8f7(%rip), %xmm0     # 0x14008
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x4aaf
movq -0x78(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x4746
cvtsi2sdq -0x80(%rbp), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x4aad
movq -0x78(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x2, %rcx
cmpq %rcx, %rax
jne 0x480d
movl $0x0, -0x88(%rbp)
movslq -0x88(%rbp), %rax
movq -0x80(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x4808
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
movslq -0x8c(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x47f2
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x88(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
callq 0x8770
cmpl $-0x1, %eax
je 0x47df
movsd 0xf833(%rip), %xmm0     # 0x14008
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x47e1
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x478c
jmp 0x47f4
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x4765
jmp 0x4aab
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x4aa9
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x98(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movq -0x78(%rbp), %rdi
addq $0x1, %rdi
callq 0x3fd0
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xa0(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xa0(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
movl %eax, -0xac(%rbp)
movq -0x80(%rbp), %rax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
cmpl -0xac(%rbp), %eax
jge 0x48b2
movl -0xac(%rbp), %eax
movl %eax, -0xb0(%rbp)
movq -0x80(%rbp), %rax
movl %eax, -0xac(%rbp)
movslq -0xac(%rbp), %rdi
callq 0x3fd0
movq %rax, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xa0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
movslq -0xc4(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x49dd
movl $0x0, -0xc8(%rbp)
movslq -0xc8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xa0(%rbp), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
movq -0x10(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0xa0(%rbp), %rsi
subq (%rdx,%rsi,8), %rcx
cmpq %rcx, %rax
jge 0x49c7
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xc4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0xc0(%rbp), %edx
addl -0xc8(%rbp), %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jne 0x49b1
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xc4(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0xb8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xbc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x49c7
jmp 0x49b3
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x4910
jmp 0x49c9
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x48f2
cmpl $0x0, -0xbc(%rbp)
jne 0x4a55
movq -0xb8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0x4a0a
movq -0xf8(%rbp), %rdi
callq 0x33d0
movq -0xb8(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, %rax
je 0x4a2f
movq -0x100(%rbp), %rdi
movl $0x10, %esi
callq 0x3310
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x108(%rbp)
cmpq $0x0, %rax
je 0x4a53
movq -0x108(%rbp), %rdi
callq 0x33d0
jmp 0x4a92
movslq -0xbc(%rbp), %rcx
movq -0xb8(%rbp), %rax
movq %rcx, (%rax)
movq -0xa8(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x4270
movq %rax, -0xd0(%rbp)
movq -0x40(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x43f0
jmp 0x4a92
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x4818
jmp 0x4aab
jmp 0x4aad
jmp 0x4aaf
jmp 0x4ab1
movq -0x50(%rbp), %rax
cmpq $0x0, (%rax)
jle 0x4ade
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, %rax
je 0x4adc
movq -0x110(%rbp), %rdi
callq 0x33d0
jmp 0x4ade
movq -0x50(%rbp), %rax
movq %rax, -0x118(%rbp)
cmpq $0x0, %rax
je 0x4b00
movq -0x118(%rbp), %rdi
movl $0x10, %esi
callq 0x3310
movq -0x48(%rbp), %rax
cmpq $0x0, (%rax)
jle 0x4b2d
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x120(%rbp)
cmpq $0x0, %rax
je 0x4b2b
movq -0x120(%rbp), %rdi
callq 0x33d0
jmp 0x4b2d
movq -0x48(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpq $0x0, %rax
je 0x4b4f
movq -0x128(%rbp), %rdi
movl $0x10, %esi
callq 0x3310
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x130(%rbp)
cmpq $0x0, %rax
je 0x4b74
movq -0x130(%rbp), %rdi
movl $0x10, %esi
callq 0x3310
movq -0x70(%rbp), %rax
movq %rax, -0x138(%rbp)
cmpq $0x0, %rax
je 0x4b96
movq -0x138(%rbp), %rdi
movl $0x10, %esi
callq 0x3310
movq -0x40(%rbp), %rdi
callq 0x4450
movq %rax, -0x70(%rbp)
jmp 0x46a4
jmp 0x4baa
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x45d5
movq -0x40(%rbp), %rdi
callq 0x43a0
callq 0x3060
movq %rax, -0xd8(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x5b00
movq %rax, -0xf0(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x5ad0
movq %rax, -0xe8(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x5b50
movq %rax, -0xe0(%rbp)
movq 0x183bc(%rip), %rdi     # 0x1cfd0
leaq 0xf505(%rip), %rsi      # 0x14120
callq 0x32e0
movq %rax, %rdi
movq -0xe0(%rbp), %rsi
callq 0x3570
movq %rax, %rdi
movq 0x1837f(%rip), %rsi     # 0x1cfb8
callq 0x3330
movq 0x1838b(%rip), %rdi     # 0x1cfd0
leaq 0xf4e0(%rip), %rsi      # 0x1412c
callq 0x32e0
movq %rax, %rdi
movsd -0x58(%rbp), %xmm0
callq 0x35a0
movq %rax, %rdi
movq 0x18350(%rip), %rsi     # 0x1cfb8
callq 0x3330
movq 0x1835c(%rip), %rdi     # 0x1cfd0
leaq 0xf4c6(%rip), %rsi      # 0x14141
callq 0x32e0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x32b0
movq %rax, %rdi
movq 0x18322(%rip), %rsi     # 0x1cfb8
callq 0x3330
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x32b0
movq %rax, %rdi
leaq 0xf54a(%rip), %rsi      # 0x141fc
callq 0x32e0
movq %rax, %rdi
movsd -0x58(%rbp), %xmm0
callq 0x35a0
movq %rax, %rdi
leaq 0xf52e(%rip), %rsi      # 0x141fc
callq 0x32e0
movq %rax, %rdi
movq -0xe0(%rbp), %rsi
callq 0x3570
movq %rax, %rdi
leaq 0xf510(%rip), %rsi      # 0x141fc
callq 0x32e0
movq %rax, %rdi
movq 0x182bd(%rip), %rsi     # 0x1cfb8
callq 0x3330
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopl (%rax)