// File: /workspace/github_c_makefile_star2_O1/cbouilla[P]AES-attacks-finder/Search.c
// Function: ExhaustiveSearchBalancedSolver
Solver * ExhaustiveSearchBalancedSolver(SysEqLin E, const int T, int * taille)
{
	int nb_wait;
	Solver * __restrict wait=SearchAlgoLowMem_All(E,T,&nb_wait);		
	
	int alloc_wait = nb_wait;
	
	Solver * __restrict checked=malloc(nb_wait*sizeof(Solver));
	int alloc_checked = nb_wait;
	int nb_checked = 0;
	
	int nb_low_time;
	Solver * __restrict low_time=MakeSolver1(E,&nb_low_time);
	
	int max_checked=0;
	int max_wait=nb_wait;
	start_1 :
	while (nb_wait>0)
	{
		if (nb_checked>max_checked) max_checked=nb_checked;
		if (nb_wait>max_wait) max_wait=nb_wait;
		printf("\r wait : %d - checked : %d - ",nb_wait,nb_checked);
		Solver B = wait[--nb_wait];
		const int nb_wait_backup = nb_wait;
		int nb_staying = nb_checked;
		start_2 :
		while (nb_staying>0)
		{
			Solver result = UnionSolverBorne(B,checked[--nb_staying],E,T);
			if (result!=NULL)
			{
				if (result->Nvar==checked[nb_staying]->Nvar)
				{
					freeSolver(result);
					if (PlusInteressant2(checked[nb_staying],B))
					{
						freeSolver(B);
						int i;
						for (i = nb_wait_backup; i < nb_wait; i++) freeSolver(wait[i]);
						nb_wait=nb_wait_backup;
						goto start_1;
					}
					else goto start_2;
				}
				if (result->Nvar==B->Nvar)
				{
					if (PlusInteressant2(B,checked[nb_staying]))
					{
						freeSolver(checked[nb_staying]);
						checked[nb_staying--]=checked[--nb_checked];
					}
					freeSolver(result);
					goto start_2;
				}
				Solver tmp = PropagateSolver2(result,E,low_time,nb_low_time);
				freeSolver(result);
				if (PlusInteressant_NoVarsNoMem(tmp,B))
				{
					freeSolver(B);
					int i=nb_checked;
					while (i>0)
					{
						i--;
						if (ContenuListesTriees(checked[i]->var,checked[i]->Nvar,tmp->var,tmp->Nvar) && PlusInteressant_NoVarsNoMem(tmp,checked[i]))
						{
							freeSolver(checked[i]);
							checked[i]=checked[--nb_checked];
						}
					}
					if (nb_wait==alloc_wait)
					{
						alloc_wait=2*alloc_wait;
						wait=realloc(wait,alloc_wait*sizeof(Solver));
					}
					wait[nb_wait++]=tmp;
					goto start_1;
				}
				else
				{
					int i=nb_staying;
					while (i>0)
					{
						i--;
						if (ContenuListesTriees(checked[i]->var,checked[i]->Nvar,tmp->var,tmp->Nvar) && PlusInteressant_NoVarsNoMem(tmp,checked[i]))
						{
							freeSolver(checked[i]);
							checked[i]=checked[--nb_staying];
							checked[nb_staying]=checked[--nb_checked];
						}
					}
					i=nb_checked;
					while (i>nb_staying)
					{
						i--;
						if (ContenuListesTriees(checked[i]->var,checked[i]->Nvar,tmp->var,tmp->Nvar) && PlusInteressant_NoVarsNoMem(tmp,checked[i]))
						{
							freeSolver(checked[i]);
							checked[i]=checked[--nb_checked];
						}
					}
					if (nb_wait==alloc_wait)
					{
						alloc_wait=2*alloc_wait;
						wait=realloc(wait,alloc_wait*sizeof(Solver));
					}
					wait[nb_wait++]=tmp;					
				}		
			}
		}
		if (nb_checked==alloc_checked)
		{
			alloc_checked=2*alloc_checked;
			checked=realloc(checked,alloc_checked*sizeof(Solver));
		}
		checked[nb_checked++]=B;		
	}
	printf("\n");
	printf("\r wait : %d - checked : %d",max_wait,max_checked);
	free(wait);
	int i;
	for (i = 0; i < nb_low_time; i++) freeSolver(low_time[i]);
	free(low_time);
	*taille=nb_checked;
	return checked;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, 0x68(%rsp)
movl %esi, %ebp
movq %rdi, %r12
leaq 0xc(%rsp), %rbx
movq %rbx, %rdx
callq 0x14a82
movq %rax, 0x18(%rsp)
movslq (%rbx), %r15
movl %ebp, %ebx
movq %r15, %rdi
shlq $0x3, %rdi
callq 0x21d0
movq %rax, %r14
leaq 0x38(%rsp), %rsi
movq %r12, 0x58(%rsp)
movq %r12, %rdi
callq 0x8010
movq %rax, 0x50(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
movl %r15d, 0x3c(%rsp)
movl %r15d, 0x2c(%rsp)
movl %ebx, 0x34(%rsp)
leaq -0x8(%r14), %rax
movq %r14, 0x10(%rsp)
movq %rax, 0x60(%rsp)
movslq 0xc(%rsp), %r14
testq %r14, %r14
jle 0x167d0
cmpl %r12d, %ebp
cmovgl %ebp, %r12d
movl %r12d, 0x30(%rsp)
cmpl %r15d, %r14d
cmovgl %r14d, %r15d
movq %r15, 0x40(%rsp)
leaq 0x167e5(%rip), %rdi     # 0x2cb67
movl %r14d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2110
leaq -0x1(%r14), %rcx
movl %ecx, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq -0x8(%rax,%r14,8), %r12
movq %rcx, 0x78(%rsp)
movslq %ecx, %rax
shlq $0x3, %rax
movq %rax, 0x70(%rsp)
movl $0x1, %eax
movq %r14, 0x80(%rsp)
subl %r14d, %eax
movl %eax, 0x4c(%rsp)
movl %ebp, 0x8(%rsp)
movl %ebp, %r13d
movq %r12, 0x20(%rsp)
movq 0x10(%rsp), %r14
testl %r13d, %r13d
jle 0x1678f
leal -0x1(%r13), %ebp
movq (%r14,%rbp,8), %rsi
movq %r12, %rdi
movq 0x58(%rsp), %rdx
movl %ebx, %ecx
callq 0x7cbb
xorl %r15d, %r15d
testq %rax, %rax
je 0x164fa
movq %rax, %r12
movl 0x8(%rax), %ecx
movq (%r14,%rbp,8), %rdi
movl 0x8(%rdi), %eax
cmpl %eax, %ecx
jne 0x16454
movq %r12, %rdi
callq 0x7060
movq (%r14,%rbp,8), %rax
movl 0x8(%rax), %ecx
movl $0x5, %r15d
movq 0x20(%rsp), %r12
cmpl 0x8(%r12), %ecx
jl 0x1644c
movl 0x14(%rax), %ecx
cmpl 0x14(%r12), %ecx
jg 0x1644c
movl 0xc(%rax), %eax
cmpl 0xc(%r12), %eax
jle 0x16641
movl %ebp, %r13d
jmp 0x16697
movq %r14, %rsi
movq 0x20(%rsp), %r14
movl 0x8(%r14), %edx
cmpl %edx, %ecx
jne 0x1646d
cmpl %eax, %edx
jge 0x164b2
movq %rsi, %r14
jmp 0x164ec
movl 0x38(%rsp), %ecx
movq %r12, %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x817d
movq %rax, %rbx
movq %r12, %rdi
callq 0x7060
movl 0x14(%rbx), %eax
cmpl 0x14(%r14), %eax
jg 0x164a4
movl 0xc(%rbx), %eax
cmpl 0xc(%r14), %eax
jle 0x166af
cmpl $0x1, %r13d
jne 0x16507
movl %ebp, %r13d
jmp 0x16582
movq 0x20(%rsp), %rcx
movl 0x14(%rcx), %eax
cmpl 0x14(%rdi), %eax
movq %rsi, %r14
jg 0x164ec
movl 0xc(%rcx), %eax
cmpl 0xc(%rdi), %eax
jg 0x164ec
callq 0x7060
movl 0x8(%rsp), %ecx
movslq %ecx, %rax
decl %ecx
movl %ecx, 0x8(%rsp)
movq -0x8(%r14,%rax,8), %rax
addl $-0x2, %r13d
movq %rax, (%r14,%rbp,8)
movl %r13d, %ebp
movq %r12, %rdi
callq 0x7060
movl $0x5, %r15d
movl %ebp, %r13d
movq 0x20(%rsp), %r12
jmp 0x16697
movl %ebp, %eax
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
movl %r13d, %r14d
movl %ebp, %r13d
movq (%r12), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%rbx), %rdx
movl 0x8(%rbx), %ecx
callq 0x2ce2
testl %eax, %eax
je 0x16575
movl 0x14(%rbx), %eax
movq (%r12), %rdi
cmpl 0x14(%rdi), %eax
jg 0x16575
movl 0xc(%rbx), %eax
cmpl 0xc(%rdi), %eax
jg 0x16575
callq 0x7060
movslq %r13d, %rax
decl %r13d
movq 0x10(%rsp), %rdx
movq -0x8(%rdx,%rax,8), %rcx
movq %rcx, (%r12)
movl 0x8(%rsp), %esi
movslq %esi, %rcx
decl %esi
movl %esi, 0x8(%rsp)
movq -0x8(%rdx,%rcx,8), %rcx
movq %rcx, -0x8(%rdx,%rax,8)
decl %r14d
addq $-0x8, %r12
cmpl $0x1, %r14d
jg 0x16518
movl 0x8(%rsp), %eax
cmpl %r13d, %eax
jle 0x165ee
movslq %eax, %r14
movslq %r13d, %r12
movq 0x60(%rsp), %rbp
movq (%rbp,%r14,8), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%rbx), %rdx
movl 0x8(%rbx), %ecx
callq 0x2ce2
testl %eax, %eax
je 0x165e6
movl 0x14(%rbx), %eax
movq (%rbp,%r14,8), %rdi
cmpl 0x14(%rdi), %eax
jg 0x165e6
movl 0xc(%rbx), %eax
cmpl 0xc(%rdi), %eax
jg 0x165e6
callq 0x7060
movl 0x8(%rsp), %ecx
movslq %ecx, %rax
decl %ecx
movl %ecx, 0x8(%rsp)
movq 0x10(%rsp), %rcx
movq -0x8(%rcx,%rax,8), %rax
movq %rax, -0x8(%rcx,%r14,8)
decq %r14
cmpq %r12, %r14
jg 0x16591
movl 0x2c(%rsp), %eax
cmpl %eax, 0xc(%rsp)
jne 0x1661b
addl %eax, %eax
movl %eax, 0x2c(%rsp)
movslq %eax, %rsi
shlq $0x3, %rsi
movq 0x18(%rsp), %rdi
callq 0x2200
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %r12
jmp 0x1662a
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %rax
movslq 0xc(%rsp), %rdx
leal 0x1(%rdx), %ecx
movl %ecx, 0xc(%rsp)
movq %rax, 0x18(%rsp)
movq %rbx, (%rax,%rdx,8)
jmp 0x16693
movq %r12, %rdi
callq 0x7060
movl 0xc(%rsp), %ebx
cmpl %ebx, 0x80(%rsp)
jg 0x1667c
movq 0x18(%rsp), %rax
movq 0x70(%rsp), %rcx
leaq (%rax,%rcx), %r14
addl 0x4c(%rsp), %ebx
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x7060
incq %r15
cmpl %r15d, %ebx
jne 0x1666b
movq 0x78(%rsp), %rax
movl %eax, 0xc(%rsp)
movl $0x2, %r15d
movl %ebp, %r13d
movq 0x10(%rsp), %r14
movl 0x34(%rsp), %ebx
testl %r15d, %r15d
je 0x163d6
cmpl $0x5, %r15d
je 0x163d6
jmp 0x1677c
movq %r14, %rdi
callq 0x7060
movl 0x8(%rsp), %r12d
testl %r12d, %r12d
jle 0x1671e
movl %r12d, %r14d
incq %r14
movq 0x10(%rsp), %r15
movq -0x10(%r15,%r14,8), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%rbx), %rdx
movl 0x8(%rbx), %ecx
callq 0x2ce2
testl %eax, %eax
je 0x16715
movl 0x14(%rbx), %eax
movq -0x10(%r15,%r14,8), %rdi
cmpl 0x14(%rdi), %eax
jg 0x16715
movl 0xc(%rbx), %eax
cmpl 0xc(%rdi), %eax
jg 0x16715
callq 0x7060
movslq %r12d, %rax
decl %r12d
movq 0x10(%rsp), %rcx
movq -0x8(%rcx,%rax,8), %rax
movq %rax, -0x10(%rcx,%r14,8)
decq %r14
cmpq $0x1, %r14
jg 0x166c7
movl 0x2c(%rsp), %eax
cmpl %eax, 0xc(%rsp)
movl %r12d, 0x8(%rsp)
jne 0x1674b
addl %eax, %eax
movl %eax, 0x2c(%rsp)
movslq %eax, %rsi
shlq $0x3, %rsi
movq 0x18(%rsp), %rdi
callq 0x2200
movq 0x10(%rsp), %r14
jmp 0x16755
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rax
movslq 0xc(%rsp), %rdx
leal 0x1(%rdx), %ecx
movl %ecx, 0xc(%rsp)
movq %rax, 0x18(%rsp)
movq %rbx, (%rax,%rdx,8)
movl $0x2, %r15d
movl %ebp, %r13d
movl 0x34(%rsp), %ebx
jmp 0x164fd
movl 0x8(%rsp), %ebp
movq 0x40(%rsp), %r15
movl 0x30(%rsp), %r12d
jmp 0x16355
movl 0x8(%rsp), %ebp
movl 0x3c(%rsp), %eax
cmpl %eax, %ebp
jne 0x167b3
addl %eax, %eax
movl %eax, 0x3c(%rsp)
movslq %eax, %rsi
shlq $0x3, %rsi
movq %r14, %rdi
callq 0x2200
movq %rax, %r14
movq 0x40(%rsp), %r15
movl 0x30(%rsp), %r12d
movslq %ebp, %rax
incl %ebp
movq 0x20(%rsp), %rcx
movq %rcx, (%r14,%rax,8)
jmp 0x16347
movl $0xa, %edi
callq 0x2040
leaq 0x163a4(%rip), %rdi     # 0x2cb85
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2110
movq 0x18(%rsp), %rdi
callq 0x2030
cmpl $0x0, 0x38(%rsp)
movq 0x50(%rsp), %r15
jle 0x1681c
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
callq 0x7060
incq %rbx
movslq 0x38(%rsp), %rax
cmpq %rax, %rbx
jl 0x16806
movq %r15, %rdi
callq 0x2030
movq 0x68(%rsp), %rax
movl %ebp, (%rax)
movq 0x10(%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq