// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xe691(%rip), %rdi      # 0x1002e
callq 0x11f0
movl $0x7df, %edi            # imm = 0x7DF
callq 0x1110
movq 0x8(%rbx), %r15
movl $0x4, %eax
cmpl $0x3, %ebp
jl 0x19c3
movq 0x10(%rbx), %rdi
callq 0x1200
movslq %eax, %r12
movl %eax, %ebx
leaq (,%r12,8), %r14
movq %r14, %rdi
callq 0x11c0
movq %rax, (%rsp)
movq %r14, %rdi
callq 0x11c0
movq %rax, 0x28(%rsp)
callq 0x2050
leaq 0xe671(%rip), %rdi      # 0x10066
movq %r15, %rsi
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1030
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %r15, %rsi
callq 0x177c
movl %ebx, %r15d
movl %ebx, 0xc(%rsp)
testl %ebx, %ebx
jle 0x1b99
xorl %r12d, %r12d
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
movq %r15, 0x30(%rsp)
callq 0x2058
movq %rax, %r13
movq (%rsp), %rax
movq %r13, (%rax,%r12,8)
movq %r13, %rdi
xorl %esi, %esi
leaq -0x116(%rip), %rdx      # 0x1947
callq 0x20f8
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x1ad6
xorl %ebp, %ebp
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
movq (%rax,%rdx,8), %rcx
cmpq %rcx, 0x8(%rax,%rdx,8)
je 0x1aaf
leaq (%rax,%rdx,8), %r14
xorl %r15d, %r15d
movl (%rcx,%r15,4), %esi
movq %r13, %rdi
callq 0x20c9
incq %r15
movq (%r14), %rcx
movq 0x8(%r14), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %rax, %r15
jb 0x1a8d
movq %r13, %rdi
xorl %esi, %esi
callq 0x20c9
incq %rbp
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %rbx, %rcx
cmpq %rcx, %rbp
jb 0x1a70
movl $0x8, %edi
callq 0x1130
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
leaq -0x1a1(%rip), %rdx      # 0x194e
movq %r13, %rcx
callq 0x1250
movq 0x28(%rsp), %rax
movq %rbp, (%rax,%r12,8)
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rbp
cmpq %rbp, %r13
je 0x1b88
leaq 0x18(%r13), %rax
cmpq %rbp, %rax
je 0x1b88
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 0x1b77
addq %r13, %rax
movups (%r13,%r14), %xmm0
movq 0x10(%r13,%r14), %rcx
movq (%rax), %rdx
movq %rdx, (%r13,%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%r13,%r14)
movq 0x10(%rax), %rdx
movq %rdx, 0x10(%r13,%r14)
movups %xmm0, (%rax)
movq %rcx, 0x10(%rax)
leaq (%r14,%r13), %rax
addq $0x18, %rax
addq $0x18, %r14
cmpq %rbp, %rax
jne 0x1b1e
incq %r12
movq 0x30(%rsp), %r15
cmpq %r15, %r12
jne 0x1a41
cmpl $0x0, 0xc(%rsp)
movq 0x28(%rsp), %r14
jle 0x1bca
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x10f0
movq (%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x20b7
incq %rbx
cmpq %rbx, %r15
jne 0x1ba7
movq (%rsp), %rdi
callq 0x1190
movq %r14, %rdi
callq 0x1190
movl 0x1556b(%rip), %esi     # 0x1714c
leaq 0xe4c0(%rip), %rdi      # 0x100a8
xorl %eax, %eax
callq 0x1030
movl 0x15557(%rip), %ebx     # 0x1714c
leaq 0x10(%rsp), %rdi
callq 0x1cae
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c18
jmp 0x1c18
jmp 0x1c18
jmp 0x1c18
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1cae
movq %rbx, %rdi
callq 0x1240
nop