// File: /workspace/github_c_makefile_star2_O3/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
testq %rdi, %rdi
je 0x955e
movq %rsi, %r15
movq %rdi, %r14
movzbl 0x18(%r14), %eax
cmpl $0x2, %eax
jne 0x9457
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x9401
testq %rax, %rax
je 0x9449
movq %rax, %rbx
movl 0x8(%rax), %esi
testl %esi, %esi
jg 0x956f
movq %rbx, %rdi
callq 0x7447
movq 0x20(%r14), %r14
testq %r14, %r14
jne 0x9418
jmp 0x955e
cmpl $0x1, %eax
jne 0x94a3
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq 0x9401
movq %rax, %rbx
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x9401
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x7f14
movq %rax, %r15
movq %rbx, %rdi
callq 0x7447
movq %r14, %rdi
callq 0x7447
movq %r15, %rax
jmp 0x9563
callq 0x7394
movq %rax, %rbx
movl $0x0, 0x8(%rax)
movslq 0x8(%r14), %r12
leaq (,%r12,4), %rdi
callq 0x21d0
movq %rax, (%rbx)
testq %r12, %r12
jle 0x954f
movq 0x18(%r15), %rcx
movq (%r14), %rdx
movl 0x8(%r15), %esi
movl 0x10(%r15), %edi
xorl %r8d, %r8d
xorl %r9d, %r9d
movslq (%rdx,%r9,4), %r10
movl (%rcx,%r10,4), %r11d
imull %edi, %r11d
cmpl %esi, %r11d
jge 0x9507
movslq %r8d, %r11
incl %r8d
movl %r8d, 0x8(%rbx)
movl %r10d, (%rax,%r11,4)
movl 0x8(%r14), %r12d
incq %r9
movslq %r12d, %r10
cmpq %r10, %r9
jl 0x94e4
testl %r8d, %r8d
je 0x954f
movq (%r14), %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0xa544
movl %eax, 0x14(%r14)
movl 0x8(%rbx), %eax
movl 0xc(%r14), %edx
xorl %ecx, %ecx
cmpl %edx, %eax
jle 0x953c
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 0x9560
movq %rax, %rdi
callq 0x2030
movl $0x0, 0x1c(%rbx)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq (%rbx), %rdi
movq %r15, %rdx
callq 0xc29a
movq %rax, %r15
movq 0x20(%r14), %rdi
movq %rax, %rsi
callq 0x9401
movq %rax, %r14
movq %r15, %rdi
callq 0xc82d
testq %r14, %r14
je 0x9560
cmpl $0x0, 0x8(%r14)
jle 0x9610
callq 0x7394
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 0x9560
movq %r14, %rdi
callq 0x7447
jmp 0x9560