// File: /workspace/github_c_makefile_star2_O2/cbouilla[P]AES-attacks-finder/Solver.c
// Function: AjusteSolver
Solver AjusteSolver(Solver B, SysEqLin E) // Refait la solver B par rapport à E (supprime les variables connues, ...)
{
	if (B==NULL) return NULL;
	
	if (B->type==2)
	{
		Solver B2=AjusteSolver(B->fils2,E);
		if (B2!=NULL && B2->Nvar>0)
		{
			SysEqLin F=EsachantX(B2->var,B2->Nvar,E);
			Solver B1=AjusteSolver(B->fils1,F);
			freeSysEq(F);
			if (B1!=NULL && B1->Nvar>0)
			{
				Solver tmp=NewSolver();
				tmp->var=UnionListesTriees(B1->var,B1->Nvar,B2->var,B2->Nvar,&(tmp->Nvar));
				tmp->sortie=B1->sortie+max(B2->sortie,0);
				tmp->temps=max(B2->temps,max(B2->sortie,0)+B1->temps);
				tmp->memoire=max(B1->memoire,B2->memoire);
				tmp->type=2;
				//tmp->parents=1;
				tmp->fils1=B1;
				tmp->fils2=B2;
				return tmp;
			}
			else
			{
				freeSolver(B1);
				return B2;
			}
		}
		else
		{
			freeSolver(B2);
			return AjusteSolver(B->fils1,E);
		}
	}
	
	if (B->type==1)
	{
		Solver B1=AjusteSolver(B->fils1,E);
		Solver B2=AjusteSolver(B->fils2,E);
		Solver tmp=UnionSolver(B1,B2,E);
		freeSolver(B1);
		freeSolver(B2);
		return tmp;
	}
	
	Solver tmp=NewSolver();
	tmp->Nvar=0;
	tmp->var=malloc(B->Nvar*sizeof(int));
	int i;
	for (i = 0; i < B->Nvar; i++) if (E->lignevar[B->var[i]]*E->gen<E->a) tmp->var[tmp->Nvar++]=B->var[i];
	if (tmp->Nvar==0) 
	{
		/* On libère la solver ( ATTENTION !!) */
		free(tmp->var);
		tmp->parents=0;
		return NULL;
	}
	#if 0
	tmp->initialisation=E;
	tmp->mat=InfoSortie_VariablesVersion(tmp->var,tmp->Nvar,E);
	tmp->sortie=tmp->mat->nombre_de_lignes - (E->gen-1)*tmp->Nvar;
	#else
	B->sortie=TailleE(B->var,B->Nvar,E);
	#endif
	if (tmp->Nvar<=B->temps)
	{
		tmp->temps=tmp->Nvar;
		tmp->memoire=0;
	}
	else
	{
		tmp->temps=B->temps;
		tmp->memoire=B->memoire;
	}
	tmp->type=0;
	//tmp->parents=1;
	tmp->fils1=NULL;
	tmp->fils2=NULL;
	return tmp;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
testq %r14, %r14
je 0x8907
movzbl 0x18(%r14), %eax
cmpl $0x2, %eax
jne 0x8771
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x8723
movq %rax, %rbx
testq %rax, %rax
je 0x8763
movl 0x8(%rbx), %esi
testl %esi, %esi
jg 0x8859
movq %rbx, %rdi
callq 0x6852
movq 0x20(%r14), %r14
jmp 0x8731
cmpl $0x1, %eax
jne 0x87bd
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x8723
movq %rax, %rbx
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x8723
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x72e2
movq %rax, %r15
movq %rbx, %rdi
callq 0x6852
movq %r14, %rdi
callq 0x6852
movq %r15, %rax
jmp 0x8916
callq 0x67a4
movq %rax, %rbx
andl $0x0, 0x8(%rax)
movslq 0x8(%r14), %r12
movq %r12, %rdi
shlq $0x2, %rdi
callq 0x21c0
movq %rax, (%rbx)
xorl %ecx, %ecx
xorl %edx, %edx
movslq %r12d, %rsi
cmpq %rsi, %rdx
jge 0x8816
movq 0x18(%r15), %rdi
movq (%r14), %rsi
movslq (%rsi,%rdx,4), %rsi
movl 0x10(%r15), %r8d
imull (%rdi,%rsi,4), %r8d
cmpl 0x8(%r15), %r8d
jge 0x8811
movslq %ecx, %rdi
incl %ecx
movl %ecx, 0x8(%rbx)
movl %esi, (%rax,%rdi,4)
movl 0x8(%r14), %r12d
incq %rdx
jmp 0x87e0
testl %ecx, %ecx
je 0x88fb
movq (%r14), %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x96cf
movl %eax, 0x14(%r14)
movl 0x8(%rbx), %eax
movl 0xc(%r14), %edx
xorl %ecx, %ecx
cmpl %edx, %eax
jle 0x8843
movl 0x10(%r14), %ecx
movl %edx, %eax
movl %eax, 0xc(%rbx)
movl %ecx, 0x10(%rbx)
movb $0x0, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
jmp 0x8913
movq (%rbx), %rdi
movq %r15, %rdx
callq 0xb021
movq %rax, %r15
movq 0x20(%r14), %rdi
movq %rax, %rsi
callq 0x8723
movq %rax, %r14
movq %r15, %rdi
callq 0xb562
testq %r14, %r14
je 0x890b
cmpl $0x0, 0x8(%r14)
jle 0x890b
callq 0x67a4
movq %rax, %r15
movq (%r14), %rdi
movl 0x8(%r14), %esi
movq (%rbx), %rdx
movl 0x8(%rbx), %ecx
leaq 0x8(%rax), %r8
callq 0x2440
movq %rax, (%r15)
movl 0x14(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
addl 0x14(%r14), %eax
movl %eax, 0x14(%r15)
movl 0x14(%rbx), %eax
testl %eax, %eax
cmovgl %eax, %ecx
addl 0xc(%r14), %ecx
movl 0xc(%rbx), %eax
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0xc(%r15)
movl 0x10(%r14), %eax
movl 0x10(%rbx), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x10(%r15)
movb $0x2, 0x18(%r15)
movq %r14, 0x20(%r15)
movq %rbx, 0x28(%r15)
movq %r15, %rbx
jmp 0x8913
movq %rax, %rdi
callq 0x2030
andl $0x0, 0x1c(%rbx)
xorl %ebx, %ebx
jmp 0x8913
movq %r14, %rdi
callq 0x6852
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq