// File: /workspace/github_c_makefile_star2_O2/cbouilla[P]AES-attacks-finder/Search.c
// Function: ManualSearch
Solver ManualSearch(int T, Solver *B1, int N1, SysEqLin E, string_list_t *variable_names)
{
	int Alloue,N,i,N2,v_max;
	Solver *Candidat,tmp,tmp2;
	char c;
	Alloue=1000;
	Candidat=malloc(Alloue*sizeof(Solver));
	N=0;
	N2=N1/2;
	v_max=0;
	c='y';
	printf("Manual Search : \n");
	while (N<Alloue)
	{
		if (c=='y')
		{
			tmp=GenerateSolver_manual(T,B1,N1,E,variable_names);
			printf("Choose the next solver ? (y/n) :");
			scanf(" %c",&c);
			getchar();
		}
		else tmp=GenerateSolver(T,B1,N1,E);
		i=0;
		while (i < N)
		{
			tmp2=UnionSolver(Candidat[i],tmp,E);
			if (c=='o')
			{
				printf("Join (%d || %d || %d): ",tmp2->temps,tmp2->memoire,tmp2->sortie);
				PrintVarSolver2(tmp2,variable_names);
			}
			if (tmp2->temps<=T)
			{
				if (PlusInteressant2(Candidat[i],tmp2))
				{
					freeSolver(tmp2);
					break;
				}
				if (PlusInteressant2(tmp,tmp2))
				{
					N--;
					freeSolver(Candidat[i]);
					Candidat[i]=Candidat[N];
					freeSolver(tmp2);
				}
				else
				{
					printf("Two solvers were merged");
					printf("Join (%d || %d || %d): ",tmp2->temps,tmp2->memoire,tmp2->sortie);
					PrintVarSolver2(tmp2,variable_names);
					getchar();
					N--;
					freeSolver(Candidat[i]);
					Candidat[i]=Candidat[N];
					freeSolver(tmp);
					tmp=PropagateSolver2(tmp2,E,B1,N1);
					freeSolver(tmp2);
					i=0;
				}
			}
			else
			{
				freeSolver(tmp2);
				i++;
			}
		}
		if (i==N)
		{
			Candidat[N++]=tmp;
			v_max=max(v_max,tmp->Nvar);
			printf("Candidat %d (%d || %d || %d): ",i,tmp->temps,tmp->memoire,tmp->sortie);
			PrintVarSolver2(tmp,variable_names);
			if (N==Alloue)
			{
				i=0;
				while (i<N)
				{
					if (Candidat[i]->Nvar<=(T+v_max)/2)
					{
						freeSolver(Candidat[i]);
						N--;
						Candidat[i]=Candidat[N];
					}
					else i++;
				}
				if (N==Alloue)
				{
					Alloue=2*Alloue;
					Candidat=realloc(Candidat,Alloue*sizeof(Solver));
				}
			}		
		}
		else freeSolver(tmp);
		if (N==1 && Candidat[0]->Nvar==E->a/E->gen)
		{
			tmp=Candidat[0];
			free(Candidat);
			printf("Solution %d || %d : ",tmp->temps,tmp->memoire);
			PrintVarSolver(tmp);
			return tmp;
		}
	}
	for (i = 0; i < N; i++) freeSolver(Candidat[i]);
	free(Candidat);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21c0
movq %rax, %rbx
leaq 0x3(%rsp), %rax
movb $0x79, (%rax)
leaq 0x156b6(%rip), %rdi     # 0x2ae9b
callq 0x2090
movl $0x3e8, %r12d           # imm = 0x3E8
xorl %r13d, %r13d
xorl %r15d, %r15d
cmpl %r12d, %r13d
jge 0x15ab5
movq %r15, 0x28(%rsp)
cmpb $0x79, 0x3(%rsp)
movq %r12, 0x30(%rsp)
jne 0x15858
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
callq 0x14ef8
movq %rax, %r12
leaq 0x154af(%rip), %rdi     # 0x2ace6
xorl %eax, %eax
callq 0x2110
leaq 0x11dc1(%rip), %rdi     # 0x27606
leaq 0x3(%rsp), %rsi
xorl %eax, %eax
callq 0x2220
callq 0x2170
jmp 0x15873
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rcx
callq 0x14e26
movq %rax, %r12
movslq %r13d, %r13
xorl %r15d, %r15d
movslq %r15d, %r15
movslq %r13d, %rbp
cmpl %r13d, %r15d
jge 0x159bf
movq (%rbx,%r15,8), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
callq 0x72e2
movq %rax, %r14
cmpb $0x6f, 0x3(%rsp)
jne 0x158ca
movl 0xc(%r14), %esi
movl 0x10(%r14), %edx
movl 0x14(%r14), %ecx
leaq 0x15451(%rip), %rdi     # 0x2ad07
xorl %eax, %eax
callq 0x2110
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x6cc9
movl 0xc(%r14), %eax
cmpl 0x18(%rsp), %eax
jle 0x158e1
movq %r14, %rdi
callq 0x6852
incq %r15
jmp 0x1587c
movq (%rbx,%r15,8), %rdi
movl 0x8(%r14), %ecx
cmpl %ecx, 0x8(%rdi)
jl 0x15900
movl 0x14(%rdi), %edx
cmpl 0x14(%r14), %edx
jg 0x15900
cmpl %eax, 0xc(%rdi)
jle 0x159b7
cmpl %ecx, 0x8(%r12)
jl 0x15939
movl 0x14(%r12), %ecx
cmpl 0x14(%r14), %ecx
jg 0x15939
cmpl %eax, 0xc(%r12)
jg 0x15939
decq %r13
callq 0x6852
movslq %r13d, %rax
movq (%rbx,%rax,8), %rax
movq %rax, (%rbx,%r15,8)
movq %r14, %rdi
callq 0x6852
jmp 0x15879
leaq 0x153df(%rip), %rdi     # 0x2ad1f
xorl %eax, %eax
callq 0x2110
movl 0xc(%r14), %esi
movl 0x10(%r14), %edx
movl 0x14(%r14), %ecx
leaq 0x153ad(%rip), %rdi     # 0x2ad07
xorl %eax, %eax
callq 0x2110
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x6cc9
callq 0x2170
leal -0x1(%rbp), %r13d
movq (%rbx,%r15,8), %rdi
callq 0x6852
movq -0x8(%rbx,%rbp,8), %rax
movq %rax, (%rbx,%r15,8)
movq %r12, %rdi
callq 0x6852
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl 0x4(%rsp), %ecx
callq 0x788d
movq %rax, %r12
movq %r14, %rdi
callq 0x6852
jmp 0x15873
movq %r14, %rdi
callq 0x6852
cmpl %r15d, %r13d
jne 0x15a59
leal 0x1(%rbp), %r13d
movq %r12, (%rbx,%rbp,8)
movl 0x8(%r12), %eax
movl 0xc(%r12), %edx
movq 0x28(%rsp), %r15
cmpl %eax, %r15d
cmovlel %eax, %r15d
movl 0x10(%r12), %ecx
movl 0x14(%r12), %r8d
leaq 0x15340(%rip), %rdi     # 0x2ad37
movl %ebp, %esi
xorl %eax, %eax
callq 0x2110
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0x6cc9
movq 0x30(%rsp), %r12
cmpl %r12d, %r13d
jne 0x15a6b
movq 0x18(%rsp), %rax
addl %r15d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %ebp
xorl %r14d, %r14d
movl %r12d, %r13d
movslq %r14d, %r14
cmpl %r13d, %r14d
jge 0x15a92
movq (%rbx,%r14,8), %rdi
cmpl %ebp, 0x8(%rdi)
jle 0x15a43
incq %r14
jmp 0x15a30
callq 0x6852
movslq %r13d, %rax
decl %r13d
movq -0x8(%rbx,%rax,8), %rax
movq %rax, (%rbx,%r14,8)
jmp 0x15a2d
movq %r12, %rdi
callq 0x6852
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %r15
cmpl $0x1, %r13d
jne 0x157f6
movq (%rbx), %r14
movl 0x8(%r14), %ecx
movq 0x8(%rsp), %rsi
movl 0x8(%rsi), %eax
cltd
idivl 0x10(%rsi)
cmpl %eax, %ecx
jne 0x157f6
jmp 0x15adf
cmpl %r12d, %r13d
jne 0x15a6b
leal (%r12,%r12), %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
movq %rbx, %rdi
callq 0x21f0
movq %rax, %rbx
movl %r12d, %r13d
movl %ebp, %r12d
jmp 0x15a6b
xorl %r14d, %r14d
testl %r13d, %r13d
cmovlel %r14d, %r13d
cmpq %r14, %r13
je 0x15ad2
movq (%rbx,%r14,8), %rdi
callq 0x6852
incq %r14
jmp 0x15abf
movq %rbx, %rdi
callq 0x2030
xorl %r14d, %r14d
jmp 0x15b05
movq %rbx, %rdi
callq 0x2030
movl 0xc(%r14), %esi
movl 0x10(%r14), %edx
leaq 0x15260(%rip), %rdi     # 0x2ad56
xorl %eax, %eax
callq 0x2110
movq %r14, %rdi
callq 0x6c8b
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq