// File: /workspace/github_c_makefile_star2_O0/cbouilla[P]AES-attacks-finder/Solver.c
// Function: Refine
Solver Refine(Solver B, SysEqLin E)
{
	if (B==NULL || B->type==0) return copySolver(B); // cas simple : rien à faire
	
	SysEqLin F = ExtraireEX2(B->var,B->Nvar,E);
	int * __restrict X = malloc(B->Nvar*sizeof(int));
	int n=0;
	int i;
	for (i = 0; i < B->Nvar; i++) if (ApparaitLineairement(B->var[i],F)) X[n++]=B->var[i];
	if (n)
	{
		Solver result = copySolver(B);
		for (i = 0; i < n; i++)
		{
			Solver tmp = DeleteVariable(X[i],result,F);
			freeSolver(result);
			result = tmp;
		}
		
		{
			Solver tmp = Refine(result,F);
			freeSolver(result);
			result = tmp;
		}
		
		for (i = 0; i < n; i++)
		{
			Solver bs = BaseSolver(X[i],F);
			Solver tmp = UnionSolver(result,bs,F);
			freeSolver(result);
			freeSolver(bs);
			result = tmp;
		}
		free(X);
		freeSysEq(F);
		return result;
	}
	else
	{
		free(X);
		if (B->type==1)
		{
			if (B->fils1->Nvar + B->fils2->Nvar != B->Nvar)
			{
				X=IntersectionListesTriees(B->fils1->var,B->fils1->Nvar,B->fils2->var,B->fils2->Nvar,&n);
				Solver f1 = copySolver(B->fils1);
				Solver f2 = copySolver(B->fils2);
				SysEqLin F1 = ExtraireEX2(f1->var,f1->Nvar,F);
				SysEqLin F2 = ExtraireEX2(f2->var,f2->Nvar,F);
				for (i = 0; i < n; i++)
				{
					int l1 = ApparaitLineairement(X[i],F1);
					int l2 = ApparaitLineairement(X[i],F2);
					if (l1 || l2)
					{
						if (l1>l2)
						{
							Solver tmp = DeleteVariable(X[i],f1,F1);
							freeSolver(f1);
							f1 = tmp;
						}
						else
						{
							Solver tmp = DeleteVariable(X[i],f2,F2);
							freeSolver(f2);
							f2 = tmp;
						}
						break;
					}
				}
				free(X);
				freeSysEq(F1);
				freeSysEq(F2);
				if (i<n)
				{
					Solver tmp = UnionSolver(f1,f2,F);
					freeSolver(f1);
					freeSolver(f2);
					Solver result = Refine(tmp,F);
					freeSolver(tmp);
					freeSysEq(F);
					return result;
				}
				else
				{
					freeSolver(f1);
					freeSolver(f2);
				}		
			}
			Solver f1 = Refine(B->fils1,F);
			Solver f2 = Refine(B->fils2,F);
			Solver result = UnionSolver(f1,f2,F);
			freeSolver(f1);
			freeSolver(f2);
			freeSysEq(F);
			return result;
		}
		else
		{
			Solver f2 = Refine(B->fils2,F);
			SysEqLin G = EsachantX(f2->var,f2->Nvar,F);
			Solver f1 = Refine(B->fils1,G);
			freeSysEq(G);
			freeSysEq(F);
			Solver result = NewSolver();
			result->var=UnionListesTriees(f1->var,f1->Nvar,f2->var,f2->Nvar,&result->Nvar);
			result->temps=max(f2->temps,max(0,f2->sortie)+f1->temps);
			result->memoire=max(f1->memoire,f2->memoire);
			result->sortie=max(0,f1->sortie)+f2->sortie;
			result->type=2;
			result->fils1 = f1;
			result->fils2 = f2;
			return result;
		}
	}
	
		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xb9a7
movq -0x10(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0xb9b9
movq -0x10(%rbp), %rdi
callq 0x9380
movq %rax, -0x8(%rbp)
jmp 0xc03b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x18(%rbp), %rdx
callq 0x115e0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x21c0
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xba4f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x20(%rbp), %rsi
callq 0x12190
cmpl $0x0, %eax
je 0xba42
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xba44
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb9f7
cmpl $0x0, -0x2c(%rbp)
je 0xbb4f
movq -0x10(%rbp), %rdi
callq 0x9380
movq %rax, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xbaad
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xb6b0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x93b0
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xba6d
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xb980
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0x93b0
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xbb30
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x20(%rbp), %rsi
callq 0x9a40
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xaa60
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
callq 0x93b0
movq -0x50(%rbp), %rdi
callq 0x93b0
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xbad6
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x20(%rbp), %rdi
callq 0x12220
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc03b
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x10(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x1, %eax
jne 0xbe08
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
addl 0x8(%rcx), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0xbd89
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x8(%rax), %esi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %ecx
leaq -0x2c(%rbp), %r8
callq 0x28f0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x9380
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x9380
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rdi
movq -0x60(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x115e0
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x115e0
movq %rax, -0x78(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xbcec
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x70(%rbp), %rsi
callq 0x12190
movl %eax, -0x7c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x78(%rbp), %rsi
callq 0x12190
movl %eax, -0x80(%rbp)
cmpl $0x0, -0x7c(%rbp)
jne 0xbc6a
cmpl $0x0, -0x80(%rbp)
je 0xbcdc
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jle 0xbca7
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0xb6b0
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rdi
callq 0x93b0
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0xbcda
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x68(%rbp), %rsi
movq -0x78(%rbp), %rdx
callq 0xb6b0
movq %rax, -0x90(%rbp)
movq -0x68(%rbp), %rdi
callq 0x93b0
movq -0x90(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0xbcec
jmp 0xbcde
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xbc24
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x70(%rbp), %rdi
callq 0x12220
movq -0x78(%rbp), %rdi
callq 0x12220
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xbd75
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xaa60
movq %rax, -0x98(%rbp)
movq -0x60(%rbp), %rdi
callq 0x93b0
movq -0x68(%rbp), %rdi
callq 0x93b0
movq -0x98(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xb980
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x93b0
movq -0x20(%rbp), %rdi
callq 0x12220
movq -0xa0(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc03b
movq -0x60(%rbp), %rdi
callq 0x93b0
movq -0x68(%rbp), %rdi
callq 0x93b0
jmp 0xbd89
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xb980
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xb980
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xaa60
movq %rax, -0xb8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x93b0
movq -0xb0(%rbp), %rdi
callq 0x93b0
movq -0x20(%rbp), %rdi
callq 0x12220
movq -0xb8(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc03b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xb980
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq (%rax), %rdi
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x11aa0
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0xc8(%rbp), %rsi
callq 0xb980
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x12220
movq -0x20(%rbp), %rdi
callq 0x12220
callq 0x9280
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rax
movq (%rax), %rdi
movq -0xd0(%rbp), %rax
movl 0x8(%rax), %esi
movq -0xc0(%rbp), %rax
movq (%rax), %rdx
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0xd8(%rbp), %r8
addq $0x8, %r8
callq 0x24e0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, (%rax)
movq -0xc0(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xdc(%rbp)
movq -0xc0(%rbp), %rcx
xorl %eax, %eax
cmpl 0x14(%rcx), %eax
jle 0xbeed
xorl %eax, %eax
movl %eax, -0xe0(%rbp)
jmp 0xbefd
movq -0xc0(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0xe0(%rbp)
movl -0xdc(%rbp), %eax
movl -0xe0(%rbp), %ecx
movq -0xd0(%rbp), %rdx
addl 0xc(%rdx), %ecx
cmpl %ecx, %eax
jle 0xbf29
movq -0xc0(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xe4(%rbp)
jmp 0xbf67
movq -0xc0(%rbp), %rcx
xorl %eax, %eax
cmpl 0x14(%rcx), %eax
jle 0xbf41
xorl %eax, %eax
movl %eax, -0xe8(%rbp)
jmp 0xbf51
movq -0xc0(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0xe8(%rbp)
movl -0xe8(%rbp), %eax
movq -0xd0(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %ecx
movq -0xd8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0xd0(%rbp), %rax
movl 0x10(%rax), %eax
movq -0xc0(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jle 0xbf9f
movq -0xd0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xec(%rbp)
jmp 0xbfaf
movq -0xc0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %ecx
movq -0xd8(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0xd0(%rbp), %rcx
xorl %eax, %eax
cmpl 0x14(%rcx), %eax
jle 0xbfd7
xorl %eax, %eax
movl %eax, -0xf0(%rbp)
jmp 0xbfe7
movq -0xd0(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0xf0(%rbp)
movl -0xf0(%rbp), %ecx
movq -0xc0(%rbp), %rax
addl 0x14(%rax), %ecx
movq -0xd8(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0xd8(%rbp), %rax
movb $0x2, 0x18(%rax)
movq -0xd0(%rbp), %rcx
movq -0xd8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0xc0(%rbp), %rcx
movq -0xd8(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0xd8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax,%rax)