// File: /workspace/github_c_makefile_star2_O0/cbouilla[P]AES-attacks-finder/Symetric.c
// Function: SearchUneSolverN3_SymetricVersion
Solver SearchUneSolverN3_SymetricVersion(int T, Solver *B1, int N1, SysEqLin E, Symetric_structure S)
{

	Solver * __restrict Solver_du_premier_message = malloc(N1*sizeof(Solver));
	int Nombre_de_solver_a_guesser = 0;
	int i;
	for (i = 0; i < N1; i++)
	{
		int j = 0;
		while (j<B1[i]->Nvar && S->message_by_var[B1[i]->var[j]]!=0) j++;
		if (j!=B1[i]->Nvar)	Solver_du_premier_message[Nombre_de_solver_a_guesser++]=B1[i];
	}

	int Alloue=1000; // espace alloué pour stocker les solvers
	Solver * __restrict Candidat=malloc(Alloue*sizeof(Solver));
	int N=0;
	int v_max=0;
	int proba = 0;
	int pos=0;
	Solver * __restrict guess_probable = malloc(N1*sizeof(Solver));
	printf("Randomized Search : (%d/%d) \n",Nombre_de_solver_a_guesser,N1);
	unsigned int cpt=0;
	int cpt2=0;
	Solver tmp;
	const int coeff_proba=200*E->gen/E->a;
	while (1)
	{
		cpt++;
		// On génère une solver
		if (cpt2 < proba) tmp=SearchUneSolver3_SymetricVersion(T,guess_probable,pos,E,S);
		else tmp=SearchUneSolver3_SymetricVersion(T,Solver_du_premier_message,Nombre_de_solver_a_guesser,E,S);
		i=0;
		// On la teste vis à vis des autres
		while (i < N)
		{
			Solver tmp2=UnionSolverBorne(Candidat[i],tmp,E,T);
			if (tmp2!=NULL)
			{
				if (tmp2->Nvar == Candidat[i]->Nvar)
				{
					freeSolver(tmp2);
					break;
				}
				if (tmp2->Nvar == tmp->Nvar)
				{
					N--;
					freeSolver(Candidat[i]);
					Candidat[i]=Candidat[N];
					freeSolver(tmp2);
				}
				else
				{
					N--;
					freeSolver(Candidat[i]);
					Candidat[i]=Candidat[N];
					freeSolver(tmp);
					tmp=PropagateSolver2(tmp2,E,B1,N1);
					freeSolver(tmp2);
					if (tmp->sortie>0) i=0;
					else i=N;
				}
			}
			else
			{
				//freeSolver(tmp2);
				i++;
			}
		}
		if (i==N) // c'est une nouvelle solver
		{
			if (tmp->sortie<=0) // On a probablement gagné
			{
				for (i = 0; i < N; i++) freeSolver(Candidat[i]);
				free(Candidat);
				for (i = 0; i < pos; i++) freeSolver(guess_probable[i]);
				free(guess_probable);
				printf("\n");
				return tmp;
			}
			Candidat[N++]=tmp;
			if (tmp->Nvar>v_max) // Elle a beaucoup de variables -> elle parait interessante
			{
				/* On cherchera une partie des solvers générées dans son complémentaire */
				v_max=tmp->Nvar;
				for (i = 0; i < pos; i++) freeSolver(guess_probable[i]);
				pos=0;
				for (i = 0; i < Nombre_de_solver_a_guesser; i++) if (!ContenuListesTriees(Solver_du_premier_message[i]->var,Solver_du_premier_message[i]->Nvar,tmp->var,tmp->Nvar)) guess_probable[pos++]=copySolver(Solver_du_premier_message[i]);
				proba=v_max*coeff_proba;
			}
			//v_max=max(v_max,tmp->Nvar);
			if (cpt2 >= 199)
			{
				printf("\r - Candidats générés : %u (%d stockés), Nombre var max : %d / %d ",cpt,N,v_max,E->a/E->gen);
				fflush(stdout);
				cpt2=0;
			}
			else cpt2++;
			if (N==Alloue) // On a atteint la limite d'espace alloué
			{
				i=0;
				while (i<N) // On supprime celles qui semblent peu intéressantes
				{
					if (Candidat[i]->Nvar<=(v_max+T)/2)
					{
						freeSolver(Candidat[i]);
						N--;
						Candidat[i]=Candidat[N];
					}
					else i++;
				}
				if (Alloue-N<500) // On realloue
				{
					Alloue+=1000;
					Candidat=realloc(Candidat,Alloue*sizeof(Solver));
					if (Candidat==NULL)
					{
						printf("Erreur allocation");
						getchar();
					}
				}
			}		
		}
		else // elle est moins interessante que celles que l'on a déjà
		{
			freeSolver(tmp);
			cpt2++;
		}
		if (N==1 && Candidat[0]->Nvar==E->a/E->gen) // On a gagné
		{
			tmp=Candidat[0];
			free(Candidat);
			printf("\n");
			return tmp;
		}
	}
	for (i = 0; i < N; i++) freeSolver(Candidat[i]);
	free(Candidat);
	printf("\n");
	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movslq -0x1c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x24514
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
xorl %eax, %eax
cmpl 0x8(%rdx), %ecx
movb %al, -0x89(%rbp)
jge 0x244b7
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx), %rcx
movslq -0x44(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
cmpl $0x0, (%rax,%rcx,4)
setne %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x244c3
jmp 0x244ce
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2446f
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl 0x8(%rcx), %eax
je 0x24504
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x24506
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2445c
movl $0x3e8, -0x48(%rbp)     # imm = 0x3E8
movslq -0x48(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movslq -0x1c(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, -0x68(%rbp)
movl -0x3c(%rbp), %esi
movl -0x1c(%rbp), %edx
leaq 0x14b38(%rip), %rdi     # 0x3909e
movb $0x0, %al
callq 0x2100
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movq -0x28(%rbp), %rax
imull $0xc8, 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
cltd
idivl 0x8(%rcx)
movl %eax, -0x7c(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x245bf
movl -0xc(%rbp), %edi
movq -0x68(%rbp), %rsi
movl -0x60(%rbp), %edx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x24270
movq %rax, -0x78(%rbp)
jmp 0x245da
movl -0xc(%rbp), %edi
movq -0x38(%rbp), %rsi
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x24270
movq %rax, -0x78(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x2472a
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x78(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0xc(%rbp), %ecx
callq 0xac00
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x2471c
movq -0x88(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x50(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl 0x8(%rcx), %eax
jne 0x2464a
movq -0x88(%rbp), %rdi
callq 0x93b0
jmp 0x2472a
movq -0x88(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x78(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x2469d
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x93b0
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x88(%rbp), %rdi
callq 0x93b0
jmp 0x2471a
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x93b0
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rdi
callq 0x93b0
movq -0x88(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0xb580
movq %rax, -0x78(%rbp)
movq -0x88(%rbp), %rdi
callq 0x93b0
movq -0x78(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jle 0x24712
movl $0x0, -0x40(%rbp)
jmp 0x24718
movl -0x54(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x2471a
jmp 0x24725
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x245e1
movl -0x40(%rbp), %eax
cmpl -0x54(%rbp), %eax
jne 0x249e8
movq -0x78(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jg 0x247c7
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x2476f
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x93b0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2474b
movq -0x50(%rbp), %rdi
callq 0x2030
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0x247a3
movq -0x68(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x93b0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2477f
movq -0x68(%rbp), %rdi
callq 0x2030
leaq 0x12724(%rip), %rdi     # 0x36ed7
movb $0x0, %al
callq 0x2100
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x24a5c
movq -0x78(%rbp), %rdx
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x54(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x58(%rbp), %eax
jle 0x248b3
movq -0x78(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0x24826
movq -0x68(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x93b0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x24802
movl $0x0, -0x60(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x248a9
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x8(%rax), %esi
movq -0x78(%rbp), %rax
movq (%rax), %rdx
movq -0x78(%rbp), %rax
movl 0x8(%rax), %ecx
callq 0x3360
cmpl $0x0, %eax
jne 0x2489c
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x9380
movq %rax, %rdx
movq -0x68(%rbp), %rax
movl -0x60(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x60(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x2489e
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x24834
movl -0x58(%rbp), %eax
imull -0x7c(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0xc7, -0x70(%rbp)
jl 0x24909
movl -0x6c(%rbp), %esi
movl -0x54(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x58(%rbp), %ecx
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x28(%rbp), %rdi
cltd
idivl 0x10(%rdi)
movl -0x90(%rbp), %edx
movl %eax, %r8d
leaq 0x147d2(%rip), %rdi     # 0x390bc
movb $0x0, %al
callq 0x2100
movq 0x186d0(%rip), %rax     # 0x3cfc8
movq (%rax), %rdi
callq 0x21d0
movl $0x0, -0x70(%rbp)
jmp 0x24912
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x48(%rbp), %eax
jne 0x249e6
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x2499b
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x8(%rax), %eax
movl %eax, -0x94(%rbp)
movl -0x58(%rbp), %eax
addl -0xc(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x94(%rbp), %eax
cmpl %ecx, %eax
jg 0x24990
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x93b0
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x24999
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x24925
movl -0x48(%rbp), %eax
subl -0x54(%rbp), %eax
cmpl $0x1f4, %eax            # imm = 0x1F4
jge 0x249e4
movl -0x48(%rbp), %eax
addl $0x3e8, %eax            # imm = 0x3E8
movl %eax, -0x48(%rbp)
movq -0x50(%rbp), %rdi
movslq -0x48(%rbp), %rsi
shlq $0x3, %rsi
callq 0x21f0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x249e2
leaq 0x144d2(%rip), %rdi     # 0x38ea8
movb $0x0, %al
callq 0x2100
callq 0x2170
jmp 0x249e4
jmp 0x249e6
jmp 0x249fa
movq -0x78(%rbp), %rdi
callq 0x93b0
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
cmpl $0x1, -0x54(%rbp)
jne 0x24a57
movq -0x50(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
movl %eax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x28(%rbp), %rcx
cltd
idivl 0x10(%rcx)
movl %eax, %ecx
movl -0x98(%rbp), %eax
cmpl %ecx, %eax
jne 0x24a57
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2030
leaq 0x12491(%rip), %rdi     # 0x36ed7
movb $0x0, %al
callq 0x2100
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x24a5c
jmp 0x24591
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq