// File: /workspace/github_cpp_makefile_star2_O3/biotomas[P]ipasir/app/genipafolio/genipafolio.cpp
// Function: main
int main(int argc, char** argv) {

	puts("c [genipafolio] USAGE: ./pfolio dimacs.cnf [#threads=4]");

	srand(2015);
	char* filename = argv[1];
	int cores = 4;
	if (argc > 2) {
		cores = atoi(argv[2]);
	}

	void** solvers = (void**)malloc(cores*sizeof(void*));
	Thread** threads = (Thread**)malloc(cores*sizeof(Thread*));

	printf("c [genipafolio] Solving %s with %d cores using %s and shuffling.\n", filename, cores, ipasir_signature());

	vector<vector<int> > fla;
	loadFormula(fla, filename);

	for (int i = 0; i < cores; i++) {
		// initialize the solver
		solvers[i] = ipasir_init();
		// set temination callback
		ipasir_set_terminate(solvers[i], NULL, terminator);
		// add the clauses (might be shuffled)
		for (size_t j = 0; j < fla.size(); j++) {
			vector<int>& cls = fla[j];
			for (size_t k = 0; k < cls.size(); k++) {
				ipasir_add(solvers[i], cls[k]);
			}
			ipasir_add(solvers[i], 0);
		}
		// start the solver
		threads[i] = new Thread(solverThread, solvers[i]);
		// shuffle the clauses for the next solver
		random_shuffle(fla.begin(), fla.end(), randGen);
	}
	// wait for each solver to stop and release them
	for (int i = 0; i < cores; i++) {
		threads[i]->join();
		ipasir_release(solvers[i]);
	}
	free(solvers);
	free(threads);
	printf("c [genipafolio] All done, result = %d\n", result);
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xe694(%rip), %rdi      # 0x1002e
callq 0x11f0
movl $0x7df, %edi            # imm = 0x7DF
callq 0x1110
movq 0x8(%rbx), %r15
movl $0x4, %eax
cmpl $0x3, %ebp
jl 0x19c0
movq 0x10(%rbx), %rdi
callq 0x1200
movslq %eax, %r12
movl %eax, %ebx
leaq (,%r12,8), %r14
movq %r14, %rdi
callq 0x11c0
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x11c0
movq %rax, 0x8(%rsp)
callq 0x2038
leaq 0xe673(%rip), %rdi      # 0x10066
movq %r15, %rsi
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1030
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %r15, %rsi
callq 0x177c
testl %ebx, %ebx
jle 0x1bc0
movl %ebx, 0x1c(%rsp)
movl %ebx, %eax
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
callq 0x2040
movq %rax, %r13
movq 0x10(%rsp), %rax
movq %r13, (%rax,%r12,8)
movq %r13, %rdi
xorl %esi, %esi
leaq -0x117(%rip), %rdx      # 0x1944
callq 0x20e0
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x1ad4
xorl %ebp, %ebp
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
movq (%rax,%rdx,8), %rcx
cmpq %rcx, 0x8(%rax,%rdx,8)
je 0x1aad
leaq (%rax,%rdx,8), %r14
xorl %r15d, %r15d
movl (%rcx,%r15,4), %esi
movq %r13, %rdi
callq 0x20b1
incq %r15
movq (%r14), %rcx
movq 0x8(%r14), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %rax, %r15
jb 0x1a8b
movq %r13, %rdi
xorl %esi, %esi
callq 0x20b1
incq %rbp
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %rbx, %rcx
cmpq %rcx, %rbp
jb 0x1a6e
movl $0x8, %edi
callq 0x1130
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
leaq -0x1a2(%rip), %rdx      # 0x194b
movq %r13, %rcx
callq 0x1250
movq 0x8(%rsp), %rax
movq %rbp, (%rax,%r12,8)
movq 0x20(%rsp), %r13
movq 0x28(%rsp), %rbp
cmpq %rbp, %r13
je 0x1b7e
leaq 0x18(%r13), %rax
cmpq %rbp, %rax
je 0x1b7e
movl $0x18, %r14d
movq %r14, %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %r15d # imm = 0xAAAAAAAB
incl %r15d
callq 0x1060
cltd
idivl %r15d
movslq %edx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
cmpq %rax, %r14
je 0x1b6d
addq %r13, %rax
movq 0x10(%r13,%r14), %rcx
movq (%rax), %rdx
movups (%r13,%r14), %xmm0
movq %rdx, (%r13,%r14)
movups 0x8(%rax), %xmm1
movups %xmm1, 0x8(%r13,%r14)
movups %xmm0, (%rax)
movq %rcx, 0x10(%rax)
leaq (%r14,%r13), %rax
addq $0x18, %rax
addq $0x18, %r14
cmpq %rbp, %rax
jne 0x1b1c
incq %r12
cmpq 0x40(%rsp), %r12
jne 0x1a3e
cmpl $0x0, 0x1c(%rsp)
jle 0x1bc0
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10f0
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x209f
incq %rbx
cmpq %rbx, 0x40(%rsp)
jne 0x1b95
movq 0x10(%rsp), %rdi
callq 0x1190
movq 0x8(%rsp), %rdi
callq 0x1190
movl 0x15572(%rip), %esi     # 0x1714c
leaq 0xe4c7(%rip), %rdi      # 0x100a8
xorl %eax, %eax
callq 0x1030
movl 0x1555e(%rip), %ebx     # 0x1714c
leaq 0x20(%rsp), %rdi
callq 0x1ca6
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c11
jmp 0x1c11
jmp 0x1c11
jmp 0x1c11
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1ca6
movq %rbx, %rdi
callq 0x1240