// File: /workspace/github_cpp_makefile_star2_O2/sjain12[P]CliqueCounting/tests/test_cliques_edge_sampling.cpp
// Function: main
int main(int argc, char *argv[])
{
    if(argc < 11) {
        usage();
        exit(1);
    }

    std::vector<std::string> graphs; // input files
	srand (time(NULL));
    int min_clique_size = 0, max_clique_size = 0, runs = 0, i = 0;
    float start_threshold = 0.0, end_threshold = 0.0, threshold_interval = 0.0, p;
	int num_samples=0, full=0;
    char c;
    printf("*****************************\n");
    while ((c = getopt(argc, argv, "i:m:M:r:p:")) != -1) {
        switch (c) {
            case 'i': {
                // multiple input files
                char *token = std::strtok(optarg, ",");
                printf("Input Files: ");
                while (token != NULL) {
                    graphs.push_back(std::string(token));
                    printf("%s,",token);
                    token = std::strtok(NULL, ",");
                }
                printf("\n");
            }
            break;

            case 'm':
                min_clique_size = atoi(optarg);
                cout << "Min Clique Size: " << min_clique_size << endl;
            break;

            case 'M':
                max_clique_size = atoi(optarg);
                cout << "Max Clique Size: " << max_clique_size << endl;
            break;

            case 'r':
                runs = atoi(optarg);
                cout << "Runs: " << runs << endl;
            break;

            case 'p':
                p = atof(optarg);
                cout << "Probability: " << p << endl;
            break;

        }
    }
    printf("*****************************\n\n");

    
    populate_nCr();
    
    for (std::vector<std::string>::iterator it=graphs.begin(); it!=graphs.end(); ++it)
    {
        std::string fname = "../graphs/" + *it;
        std::cout << fname << std::endl;
        string f = *it;
        char *token = std::strtok(strdup(f.c_str()), ".");
        string gname(token);
        cout << "GNAME = " << gname << endl;

        for(i=min_clique_size; i<=max_clique_size; i++)
        {
			string outfile(gname + "_" + to_string(i) + "_0." + to_string(int(p*100)) + "_" + to_string(runs) + "_es");
			std::string ofname = "../results/cliques/" + outfile;
    		std::cout << ofname << std::endl;
    		std::ofstream of;
    		of.open(ofname);
    		if (!of.is_open())
    		{
        		std::cout << "Could not open output file." << std::endl;
        		exit(1);
  			}
    		printf("Output File: %s\n", ofname.c_str());

			of << "csize,estimate,time,edges,num_cliques," << endl;
       	
			for (int run=0; run < runs; run++)
			{
                Graph g;
                printf("Loading graph\n");
                if (loadGraph_p(fname.c_str(), g, 1, IOFormat::escape, p))
                    exit(1);
                cout << "vertices: " << g.nVertices << " edges = " << g.nEdges << std::endl;

                printf("Converting to CSR\n");
                CGraph cg = makeCSR(g);

                printf("Creating DAG\n");
                CDAG dag = degreeOrdered(&cg);

                cout << "vertices: " << g.nVertices << " edges = " << g.nEdges << std::endl;

                cliques_edge_sampling_1(cg, dag, of, gname, "", i, p);
            	of << std::endl;
                delGraph(g);
            	delCGraph(cg);
                delCDAG(dag);

            }
			of.close();

        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
movq %rsi, 0x48(%rsp)
movl %edi, 0x34(%rsp)
cmpl $0xa, %edi
jle 0x4ab0
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
xorl %edi, %edi
callq 0x3240
movl %eax, %edi
callq 0x3270
leaq 0x4fac(%rip), %rdi      # 0x929f
callq 0x33f0
leaq 0x4e0a(%rip), %r15      # 0x9109
leaq 0x288(%rsp), %r12
leaq 0xe0(%rsp), %r13
leaq 0x4df1(%rip), %rbx      # 0x9107
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x34(%rsp), %edi
movq 0x48(%rsp), %rsi
leaq 0x4db0(%rip), %rdx      # 0x90ee
callq 0x30a0
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x44f1
sarl $0x18, %eax
leal -0x69(%rax), %ecx
cmpl $0x9, %ecx
ja 0x43e2
leaq 0x4cad(%rip), %rdx      # 0x9014
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x9c49(%rip), %rax      # 0xdfc0
movq (%rax), %rdi
movq %r15, %rsi
callq 0x3410
movq %rax, %rbp
leaq 0x4d6d(%rip), %rdi      # 0x90f9
xorl %eax, %eax
callq 0x3040
testq %rbp, %rbp
je 0x43d5
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x4c3c
movq %r14, %rdi
movq %r12, %rsi
callq 0x5620
movq %r12, %rdi
callq 0x3120
movq %rbx, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3040
xorl %edi, %edi
movq %r15, %rsi
callq 0x3410
movq %rax, %rbp
jmp 0x4393
pushq $0xa
popq %rdi
callq 0x3390
jmp 0x432e
cmpl $0x4d, %eax
jne 0x432e
movq 0x9bce(%rip), %rax      # 0xdfc0
movq (%rax), %rdi
callq 0x3400
movl %eax, 0x30(%rsp)
movq 0x9bcb(%rip), %rdi      # 0xdfd0
leaq 0x4d11(%rip), %rsi      # 0x911d
callq 0x3290
movq %rax, %rdi
movl 0x30(%rsp), %esi
callq 0x34b0
movq %rax, %rdi
callq 0x3140
jmp 0x432e
movq 0x9b8f(%rip), %rax      # 0xdfc0
movq (%rax), %rdi
callq 0x3400
movl %eax, 0x38(%rsp)
movq 0x9b8c(%rip), %rdi      # 0xdfd0
leaq 0x4cc0(%rip), %rsi      # 0x910b
callq 0x3290
movq %rax, %rdi
movl 0x38(%rsp), %esi
callq 0x34b0
movq %rax, %rdi
callq 0x3140
jmp 0x432e
movq 0x9b50(%rip), %rax      # 0xdfc0
movq (%rax), %rdi
callq 0x3320
movsd %xmm0, 0x40(%rsp)
movq 0x9b4b(%rip), %rdi      # 0xdfd0
leaq 0x4caa(%rip), %rsi      # 0x9136
callq 0x3290
cvtsd2ss 0x40(%rsp), %xmm0
movq %rax, %rdi
movss %xmm0, 0x40(%rsp)
callq 0x31d0
movq %rax, %rdi
callq 0x3140
jmp 0x432e
movq 0x9b07(%rip), %rax      # 0xdfc0
movq (%rax), %rdi
callq 0x3400
movl %eax, 0x2c(%rsp)
movq 0x9b04(%rip), %rdi      # 0xdfd0
leaq 0x4c5c(%rip), %rsi      # 0x912f
callq 0x3290
movq %rax, %rdi
movl 0x2c(%rsp), %esi
callq 0x34b0
movq %rax, %rdi
callq 0x3140
jmp 0x432e
leaq 0x4dc5(%rip), %rdi      # 0x92bd
callq 0x33f0
callq 0x3859
movq 0xa0(%rsp), %rdx
movss 0x4afe(%rip), %xmm0     # 0x9010
mulss 0x40(%rsp), %xmm0
cvttss2si %xmm0, %eax
movl %eax, 0x34(%rsp)
movl 0x2c(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movl %ecx, 0x54(%rsp)
movslq 0x38(%rsp), %rax
movq %rax, 0x78(%rsp)
movslq 0x30(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x1a8(%rsp), %r15
leaq 0x288(%rsp), %r14
leaq 0x168(%rsp), %rbx
leaq 0x128(%rsp), %rbp
cmpq 0xa8(%rsp), %rdx
je 0x4a6c
movq %r15, %rdi
leaq 0x4bc6(%rip), %rsi      # 0x9144
movq %rdx, 0x38(%rsp)
callq 0x4c77
movq 0x9a41(%rip), %rdi      # 0xdfd0
movq %r15, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3140
leaq 0x188(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3370
movq 0x188(%rsp), %rdi
callq 0x34f0
movq %rax, %rdi
leaq 0x4b94(%rip), %rsi      # 0x915c
callq 0x3410
leaq 0xc0(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4c3c
movq 0x99e9(%rip), %rdi      # 0xdfd0
leaq 0x4b61(%rip), %rsi      # 0x914f
callq 0x3290
movq %rax, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq 0x78(%rsp), %r12
cmpq 0x48(%rsp), %r12
jg 0x4a3c
movq %rbx, %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x4b2b(%rip), %rdx      # 0x9158
callq 0x4d73
leaq 0x248(%rsp), %r15
movq %r15, %rdi
movl %r12d, %esi
callq 0x4dab
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x4d0c
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
leaq 0x4af0(%rip), %rdx      # 0x915a
callq 0x4ced
leaq 0x228(%rsp), %r15
movq %r15, %rdi
movl 0x34(%rsp), %esi
callq 0x4dab
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
movq %r15, %rdx
callq 0x4d0c
leaq 0xe0(%rsp), %rdi
movq %rbp, %rsi
leaq 0x4ab0(%rip), %rdx      # 0x9158
callq 0x4ced
leaq 0x208(%rsp), %r15
movq %r15, %rdi
movl 0x2c(%rsp), %esi
callq 0x4dab
movq %r14, %rdi
leaq 0xe0(%rsp), %rsi
movq %r15, %rdx
callq 0x4d0c
leaq 0x268(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
leaq 0x4a75(%rip), %rdx      # 0x915e
callq 0x4ced
movq %r14, %rdi
callq 0x3120
leaq 0x208(%rsp), %rdi
callq 0x3120
leaq 0xe0(%rsp), %rdi
callq 0x3120
movq %rbp, %rdi
callq 0x3120
leaq 0x228(%rsp), %rdi
callq 0x3120
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x3120
leaq 0x58(%rsp), %rdi
callq 0x3120
leaq 0x248(%rsp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3120
movq %r15, %rdi
leaq 0x4a04(%rip), %rsi      # 0x9162
movq %r13, %rdx
callq 0x4c77
movq 0x9863(%rip), %rdi      # 0xdfd0
movq %r15, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq %r14, %rdi
callq 0x34a0
movq %r14, %rdi
leaq 0x80(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x3130
leaq 0x2f8(%rsp), %rdi
callq 0x30b0
testb %al, %al
je 0x4a8d
movq 0x80(%rsp), %rsi
leaq 0x49ba(%rip), %rdi      # 0x9176
xorl %eax, %eax
callq 0x3040
movq %r14, %rdi
leaq 0x49ba(%rip), %rsi      # 0x9187
callq 0x3290
movq %rax, %rdi
callq 0x3140
movl 0x54(%rsp), %r15d
subl $0x1, %r15d
jb 0x4a02
leaq 0x4aec(%rip), %rdi      # 0x92dc
callq 0x33f0
movq 0x1a8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
pushq $0x1
popq %rcx
movl %ecx, %edx
movss 0x40(%rsp), %xmm0
callq 0x84d7
testl %eax, %eax
jne 0x4aa8
movq 0x97af(%rip), %rdi      # 0xdfd0
leaq 0x4986(%rip), %rsi      # 0x91ae
callq 0x3290
movq 0x58(%rsp), %rsi
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
leaq 0x4975(%rip), %rsi      # 0x91b9
callq 0x3290
movq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3140
leaq 0x4a85(%rip), %rdi      # 0x92ea
callq 0x33f0
movups 0x58(%rsp), %xmm0
movups 0x68(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5da4
leaq 0x4a6e(%rip), %rdi      # 0x92fc
callq 0x33f0
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x36a5
movq 0x972b(%rip), %rdi      # 0xdfd0
leaq 0x4902(%rip), %rsi      # 0x91ae
callq 0x3290
movq 0x58(%rsp), %rsi
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
leaq 0x48f1(%rip), %rsi      # 0x91b9
callq 0x3290
movq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
callq 0x3140
leaq 0x1e8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3370
leaq 0x1c8(%rsp), %rdi
leaq 0x4c19(%rip), %rsi      # 0x951f
leaq 0xe0(%rsp), %rdx
callq 0x4c3c
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r12, %r9
movss 0x40(%rsp), %xmm0
callq 0x3dae
leaq 0x1c8(%rsp), %rdi
callq 0x3120
leaq 0x1e8(%rsp), %rdi
callq 0x3120
movq %r14, %rdi
callq 0x3140
movups 0x58(%rsp), %xmm0
movups 0x68(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x5941
movups 0x168(%rsp), %xmm0
movups 0x178(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x5abd
movups 0x128(%rsp), %xmm0
movups 0x138(%rsp), %xmm1
movups 0x148(%rsp), %xmm2
movups 0x158(%rsp), %xmm3
movaps %xmm3, 0x110(%rsp)
movaps %xmm2, 0x100(%rsp)
movaps %xmm1, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movups 0x128(%rsp), %xmm0
movups 0x138(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x5abd
leaq 0x100(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x5abd
jmp 0x47df
movq %r14, %rdi
callq 0x33a0
leaq 0x1a8(%rsp), %r15
movq %r14, %rdi
callq 0x33d0
leaq 0x80(%rsp), %rdi
callq 0x3120
leaq 0x268(%rsp), %rdi
callq 0x3120
incq %r12
jmp 0x4610
leaq 0xc0(%rsp), %rdi
callq 0x3120
leaq 0x188(%rsp), %rdi
callq 0x3120
movq %r15, %rdi
callq 0x3120
movq 0x38(%rsp), %rdx
addq $0x20, %rdx
jmp 0x4566
leaq 0xa0(%rsp), %rdi
callq 0x4e04
xorl %eax, %eax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x953c(%rip), %rdi      # 0xdfd0
leaq 0x45da(%rip), %rsi      # 0x9075
callq 0x3290
movq %rax, %rdi
callq 0x3140
pushq $0x1
popq %rdi
callq 0x3310
callq 0x429b
jmp 0x4aa8
jmp 0x4adc
jmp 0x4adc
jmp 0x4adc
jmp 0x4adc
jmp 0x4adc
jmp 0x4acd
jmp 0x4adc
movq %rax, %rbx
jmp 0x4c0c
movq %rax, %rbx
jmp 0x4c19
jmp 0x4b4e
jmp 0x4bd5
movq %rax, %rbx
jmp 0x4c26
movq %rax, %rbx
leaq 0x288(%rsp), %rdi
jmp 0x4c21
movq %rax, %rbx
jmp 0x4b32
movq %rax, %rbx
jmp 0x4b8f
jmp 0x4ba6
movq %rax, %rbx
jmp 0x4b85
movq %rax, %rbx
jmp 0x4b25
movq %rax, %rbx
jmp 0x4b78
movq %rax, %rbx
leaq 0x288(%rsp), %rdi
callq 0x3120
leaq 0x208(%rsp), %rdi
callq 0x3120
leaq 0xe0(%rsp), %rdi
callq 0x3120
jmp 0x4b5e
movq %rax, %rbx
jmp 0x4bf2
movq %rax, %rbx
jmp 0x4b6b
movq %rax, %rbx
jmp 0x4bff
movq %rax, %rbx
jmp 0x4b9c
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x3120
leaq 0x228(%rsp), %rdi
callq 0x3120
leaq 0x80(%rsp), %rdi
callq 0x3120
leaq 0x58(%rsp), %rdi
callq 0x3120
leaq 0x248(%rsp), %rdi
callq 0x3120
leaq 0x168(%rsp), %rdi
jmp 0x4bfa
movq %rax, %rbx
jmp 0x4be5
jmp 0x4bd5
jmp 0x4bd5
movq %rax, %rbx
jmp 0x4bc4
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0x3120
leaq 0x1e8(%rsp), %rdi
callq 0x3120
jmp 0x4bd8
jmp 0x4bd5
movq %rax, %rbx
leaq 0x288(%rsp), %rdi
callq 0x33d0
leaq 0x80(%rsp), %rdi
callq 0x3120
leaq 0x268(%rsp), %rdi
callq 0x3120
leaq 0xc0(%rsp), %rdi
callq 0x3120
leaq 0x188(%rsp), %rdi
callq 0x3120
leaq 0x1a8(%rsp), %rdi
callq 0x3120
leaq 0xa0(%rsp), %rdi
callq 0x4e04
movq %rbx, %rdi
callq 0x34d0
nop