// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq %rdx, 0x58(%rsp)
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movl %esi, 0x4c(%rsp)
movq %r14, %rdx
callq 0x131c8
movq %rax, %r13
movslq (%r14), %r15
movq %r15, %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %r14
leaq 0x2c(%rsp), %rsi
movq %rbx, 0x50(%rsp)
movq %rbx, %rdi
callq 0x771f
movq %rax, 0x40(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movl %r15d, 0x28(%rsp)
movl %r15d, 0xc(%rsp)
movslq 0x8(%rsp), %rbp
testq %rbp, %rbp
jle 0x14dbc
movl 0x4(%rsp), %ebx
cmpl %r12d, %ebx
cmovgl %ebx, %r12d
movl %r12d, 0x24(%rsp)
cmpl %r15d, %ebp
cmovgl %ebp, %r15d
movq %r15, 0x38(%rsp)
leaq 0x1614e(%rip), %rdi     # 0x2ab67
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2110
decq %rbp
movl %ebp, 0x8(%rsp)
movl %ebp, %eax
movq %r13, 0x18(%rsp)
movq (%r13,%rax,8), %r12
movl %ebp, %eax
movq %rax, 0x30(%rsp)
movl %ebx, %r15d
movq %rbp, 0x60(%rsp)
movl %r15d, %ebx
movl %ebx, %r15d
movslq 0x4(%rsp), %rbp
testl %r15d, %r15d
jle 0x14c79
leal -0x1(%r15), %ebx
movq (%r14,%rbx,8), %rsi
movq %r12, %rdi
movq 0x50(%rsp), %rdx
movl 0x4c(%rsp), %ecx
callq 0x73be
testq %rax, %rax
je 0x14ab7
movq %rax, %r13
movl 0x8(%rax), %eax
movq (%r14,%rbx,8), %rdi
movl 0x8(%rdi), %ecx
cmpl %ecx, %eax
jne 0x14abc
movq %r13, %rdi
callq 0x6852
movq (%r14,%rbx,8), %rax
movl 0x8(%rax), %ecx
cmpl 0x8(%r12), %ecx
jl 0x14ab7
movl 0x14(%rax), %ecx
cmpl 0x14(%r12), %ecx
jg 0x14ab7
movl 0xc(%rax), %eax
cmpl 0xc(%r12), %eax
jle 0x14cb7
decl %r15d
jmp 0x14a4c
cmpl 0x8(%r12), %eax
jne 0x14b01
cmpl %ecx, %eax
jl 0x14af4
movl 0x14(%r12), %eax
cmpl 0x14(%rdi), %eax
jg 0x14af4
movl 0xc(%r12), %eax
cmpl 0xc(%rdi), %eax
jg 0x14af4
callq 0x6852
decl 0x4(%rsp)
movq -0x8(%r14,%rbp,8), %rax
addl $-0x2, %r15d
movq %rax, (%r14,%rbx,8)
movl %r15d, %ebx
movq %r13, %rdi
callq 0x6852
jmp 0x14a49
movl 0x2c(%rsp), %ecx
movq %r13, %rdi
movq 0x50(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x788d
movq %rax, %rbp
movq %r13, %rdi
callq 0x6852
movq %rbp, %r8
movl 0x14(%rbp), %eax
cmpl 0x14(%r12), %eax
movq %rbp, 0x10(%rsp)
jg 0x14b43
movl 0xc(%r8), %eax
cmpl 0xc(%r12), %eax
jle 0x14cf8
decl %r15d
movl %ebx, %ebp
decq %rbx
movslq %r15d, %r13
testl %ebp, %ebp
jle 0x14bbe
movq (%r14,%rbx,8), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%r8), %rdx
movl 0x8(%r8), %ecx
callq 0x2a3d
movq 0x10(%rsp), %r8
testl %eax, %eax
je 0x14b87
movl 0x14(%r8), %eax
movq (%r14,%rbx,8), %rdi
cmpl 0x14(%rdi), %eax
jg 0x14b87
movl 0xc(%r8), %eax
cmpl 0xc(%rdi), %eax
jle 0x14b8e
decq %rbx
decl %ebp
jmp 0x14b4b
callq 0x6852
movq 0x10(%rsp), %r8
leal -0x1(%r13), %r15d
movq -0x8(%r14,%r13,8), %rax
movq %rax, (%r14,%rbx,8)
movl 0x4(%rsp), %ecx
movslq %ecx, %rax
decl %ecx
movl %ecx, 0x4(%rsp)
movq -0x8(%r14,%rax,8), %rax
movq %rax, -0x8(%r14,%r13,8)
jmp 0x14b46
movslq 0x4(%rsp), %rbx
cmpq %r13, %rbx
jle 0x14c27
movq -0x8(%r14,%rbx,8), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%r8), %rdx
movl 0x8(%r8), %ecx
callq 0x2a3d
movq 0x10(%rsp), %r8
testl %eax, %eax
je 0x14bff
movl 0x14(%r8), %eax
movq -0x8(%r14,%rbx,8), %rdi
cmpl 0x14(%rdi), %eax
jg 0x14bff
movl 0xc(%r8), %eax
cmpl 0xc(%rdi), %eax
jle 0x14c04
decq %rbx
jmp 0x14bc3
callq 0x6852
movq 0x10(%rsp), %r8
movl 0x4(%rsp), %ecx
movslq %ecx, %rax
decl %ecx
movl %ecx, 0x4(%rsp)
movq -0x8(%r14,%rax,8), %rax
movq %rax, -0x8(%r14,%rbx,8)
jmp 0x14bff
movq 0x30(%rsp), %rcx
cmpl 0xc(%rsp), %ecx
jne 0x14c56
movl %ecx, %eax
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movslq %eax, %rsi
shlq $0x3, %rsi
movq 0x18(%rsp), %rdi
callq 0x21f0
movq 0x10(%rsp), %r8
movl 0x8(%rsp), %ecx
jmp 0x14c5b
movq 0x18(%rsp), %rax
movslq %ecx, %rdx
incl %ecx
movl %ecx, 0x8(%rsp)
movq %rax, 0x18(%rsp)
movq %r8, (%rax,%rdx,8)
movl %ecx, %eax
movq %rax, 0x30(%rsp)
jmp 0x14a46
movl 0x28(%rsp), %eax
cmpl %eax, 0x4(%rsp)
jne 0x14c9b
addl %eax, %eax
movl %eax, 0x28(%rsp)
movslq %eax, %rsi
shlq $0x3, %rsi
movq %r14, %rdi
callq 0x21f0
movq %rax, %r14
movq 0x18(%rsp), %r13
movq 0x38(%rsp), %r15
incl 0x4(%rsp)
movq %r12, (%r14,%rbp,8)
movl 0x24(%rsp), %r12d
jmp 0x149e8
movq %r12, %rdi
callq 0x6852
movslq 0x30(%rsp), %rbx
movq 0x60(%rsp), %rbp
movq %rbp, %r15
movq 0x18(%rsp), %r13
movl 0x24(%rsp), %r12d
cmpq %rbx, %r15
jge 0x14cea
movq (%r13,%r15,8), %rdi
callq 0x6852
incq %r15
jmp 0x14cd6
movl %ebp, 0x8(%rsp)
movq 0x38(%rsp), %r15
jmp 0x149e8
movq %r12, %rdi
callq 0x6852
movl 0x4(%rsp), %ebx
movq 0x18(%rsp), %r13
movq 0x38(%rsp), %r15
movl 0x24(%rsp), %r12d
movl %ebx, %ebp
decq %rbx
movq 0x10(%rsp), %r8
testl %ebp, %ebp
jle 0x14d7a
movq (%r14,%rbx,8), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%r8), %rdx
movl 0x8(%r8), %ecx
callq 0x2a3d
movq 0x10(%rsp), %r8
testl %eax, %eax
je 0x14d56
movl 0x14(%r8), %eax
movq (%r14,%rbx,8), %rdi
cmpl 0x14(%rdi), %eax
jg 0x14d56
movl 0xc(%r8), %eax
cmpl 0xc(%rdi), %eax
jle 0x14d5d
decq %rbx
decl %ebp
jmp 0x14d1d
callq 0x6852
movl 0x4(%rsp), %ecx
movslq %ecx, %rax
decl %ecx
movl %ecx, 0x4(%rsp)
movq -0x8(%r14,%rax,8), %rax
movq %rax, (%r14,%rbx,8)
jmp 0x14d13
movq 0x30(%rsp), %rcx
cmpl 0xc(%rsp), %ecx
jne 0x14da8
movl %ecx, %eax
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movslq %eax, %rsi
shlq $0x3, %rsi
movq %r13, %rdi
callq 0x21f0
movq 0x10(%rsp), %r8
movq %rax, %r13
movl 0x8(%rsp), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x8(%rsp)
movslq %ecx, %rax
movq %r8, (%r13,%rax,8)
jmp 0x149e8
pushq $0xa
popq %rdi
callq 0x2040
leaq 0x15dba(%rip), %rdi     # 0x2ab85
xorl %ebx, %ebx
movl %r15d, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2110
movq %r13, %rdi
callq 0x2030
movslq 0x2c(%rsp), %rax
cmpq %rax, %rbx
jge 0x14dff
movq 0x40(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x6852
incq %rbx
jmp 0x14de2
movq 0x40(%rsp), %rdi
callq 0x2030
movq 0x58(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq