// File: /workspace/github_c_makefile_star2_O1/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 0x931a
movzbl 0x18(%r14), %eax
cmpl $0x2, %eax
jne 0x917b
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x912d
movq %rax, %rbx
testq %rax, %rax
je 0x916d
movl 0x8(%rbx), %esi
testl %esi, %esi
jg 0x9265
movq %rbx, %rdi
callq 0x7060
movq 0x20(%r14), %r14
jmp 0x913b
cmpl $0x1, %eax
jne 0x91c7
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x912d
movq %rax, %rbx
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x912d
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x7be3
movq %rax, %r15
movq %rbx, %rdi
callq 0x7060
movq %r14, %rdi
callq 0x7060
movq %r15, %rax
jmp 0x933e
callq 0x6fb4
movq %rax, %rbx
movl $0x0, 0x8(%rax)
movslq 0x8(%r14), %r12
leaq (,%r12,4), %rdi
callq 0x21d0
movq %rax, (%rbx)
testq %r12, %r12
jle 0x922e
movq 0x18(%r15), %rcx
movq (%r14), %rdx
movl 0x8(%r15), %esi
movl 0x10(%r15), %edi
xorl %r8d, %r8d
movslq (%rdx,%r8,4), %r9
movl (%rcx,%r9,4), %r10d
imull %edi, %r10d
cmpl %esi, %r10d
jge 0x9222
movslq 0x8(%rbx), %r10
leal 0x1(%r10), %r11d
movl %r11d, 0x8(%rbx)
movl %r9d, (%rax,%r10,4)
incq %r8
movslq 0x8(%r14), %r12
cmpq %r12, %r8
jl 0x9201
cmpl $0x0, 0x8(%rbx)
je 0x930b
movq (%r14), %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0xa280
movl %eax, 0x14(%r14)
movl 0x8(%rbx), %eax
movl 0xc(%r14), %ecx
cmpl %ecx, %eax
jle 0x9328
movl %ecx, 0xc(%rbx)
movl 0x10(%r14), %eax
jmp 0x932d
movq (%rbx), %rdi
movq %r15, %rdx
callq 0xbed5
movq %rax, %r15
movq 0x20(%r14), %rdi
movq %rax, %rsi
callq 0x912d
movq %rax, %r14
movq %r15, %rdi
callq 0xc453
testq %r14, %r14
je 0x931e
cmpl $0x0, 0x8(%r14)
jle 0x931e
callq 0x6fb4
movq %rax, %r15
movq (%r14), %rdi
movl 0x8(%r14), %esi
movq (%rbx), %rdx
movl 0x8(%rbx), %ecx
leaq 0x8(%rax), %r8
callq 0x2544
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 0x933b
movq %rax, %rdi
callq 0x2030
movl $0x0, 0x1c(%rbx)
xorl %ebx, %ebx
jmp 0x933b
movq %r14, %rdi
callq 0x7060
jmp 0x933b
movl %eax, 0xc(%rbx)
xorl %eax, %eax
movl %eax, 0x10(%rbx)
movb $0x0, 0x18(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq