// File: /workspace/github_c_makefile_star2_O2/cbouilla[P]AES-attacks-finder/Equation.c
// Function: RemonteSysEq
Equation * RemonteSysEq(Equation *E, int N, int *N1, int *Known, int Nconnu)
{
	Equation *Eq,*Eq2,tmp,tmp1;
	int *V,*F,*F1,n,n1,n2,i,j,k,pos1,pos2;
	Eq=malloc(N*sizeof(Equation));
	for (i = 0; i < N; i++) Eq[i]=copyEq(E[i]);
	Eq2=malloc(N*sizeof(Equation));
	pos1=0;
	pos2=N-1;
	F=malloc(Nconnu*sizeof(int));
	for (i = 0; i < Nconnu; i++) F[i]=Known[i];	
	n=Nconnu;
	for (i = 0; i < N; i++)
	{
		V=VarsDedans(Eq[i],&n1);
		Tri(V,n1);
		/*
		printf("V : ");
		PrintListe(V,n1);
		printf("F : ");
		PrintListe(F,n);
		*/
		for (j = n1-1; j >= 0; j--)
		{
			if (SearchElement(V[j],F,n)==-1 && apparaitEq(Eq[i],V[j])==1)
			{
				tmp=inverseEq(Eq[i],V[j]);
				/*
				  printf("%d = ",V[j]);
				  PrintEq(tmp);
				  printf("\n");
				  getchar();
				*/
				for (k = i+1; k < N; k++)
				{
					tmp1=remplaceEq(Eq[k],V[j],tmp);
					freeEq(Eq[k]);
					Eq[k]=tmp1;
				}
				Eq2[pos2--]=copyEq(Eq[i]);
				break;
			}
		}
		if (j==-1) Eq2[pos1++]=copyEq(Eq[i]);
		F1=UnionListesTriees(F,n,V,n1,&n2);
		free(F);
		free(V);
		F=F1;
		n=n2;	
	}
	*N1=pos1;
	for (i = 0; i < N; i++) freeEq(Eq[i]);
	free(Eq);
	return Eq2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, (%rsp)
movq %rcx, %r14
movq %rdx, 0x48(%rsp)
movl %esi, %ebp
movq %rdi, %r13
movslq %esi, %r15
leaq (,%r15,8), %r12
movq %r12, %rdi
callq 0x21c0
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
testl %r15d, %r15d
movl $0x0, %r15d
movq %rbp, 0x40(%rsp)
cmovgl %ebp, %r15d
cmpq %rbx, %r15
je 0x5897
movq (%r13,%rbx,8), %rdi
callq 0x4319
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x587a
movq %r12, %rdi
callq 0x21c0
movq %rax, 0x18(%rsp)
movl (%rsp), %r13d
movslq %r13d, %rbx
leaq (,%rbx,4), %rdi
callq 0x21c0
movq %rax, %rdx
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
cmpq %rax, %rbx
je 0x58d3
movl (%r14,%rax,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
jmp 0x58c2
movq 0x40(%rsp), %rax
decl %eax
movl %eax, 0x14(%rsp)
xorl %ecx, %ecx
pushq $0x1
popq %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x4(%rsp)
movq %rdx, %rbx
movq %r15, 0x28(%rsp)
cmpq %r15, %rcx
je 0x5a5c
movq 0x8(%rsp), %rax
movq %rcx, 0x38(%rsp)
movq (%rax,%rcx,8), %r12
movq %r12, %rdi
leaq 0x24(%rsp), %rsi
callq 0x56ee
movq %rax, %r14
movl 0x24(%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x27bf
movq %rbp, 0x58(%rsp)
testl %ebp, %ebp
jle 0x59f2
movl -0x4(%r14,%rbp,4), %edi
movq %rbx, %rsi
movl %r13d, %edx
callq 0x26cf
cmpl $-0x1, %eax
jne 0x5964
movl -0x4(%r14,%rbp,4), %r15d
movq %r12, %rdi
movl %r15d, %esi
callq 0x4d1e
cmpl $0x1, %eax
je 0x5969
decq %rbp
jmp 0x5932
movq %rbx, 0x50(%rsp)
movl %r13d, (%rsp)
movq %r12, %rdi
movl %r15d, %esi
callq 0x5074
movq %rax, 0x60(%rsp)
movq 0x30(%rsp), %r13
cmpl 0x40(%rsp), %r13d
jge 0x59bd
movq 0x8(%rsp), %r12
movq (%r12,%r13,8), %r15
movl -0x4(%r14,%rbp,4), %esi
movq %r15, %rdi
movq 0x60(%rsp), %rdx
callq 0x4e89
movq %rax, %rbx
movq %r15, %rdi
callq 0x42a5
movq %rbx, (%r12,%r13,8)
incq %r13
jmp 0x5987
movq 0x8(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %r12
movq %r12, %rdi
callq 0x4319
movl 0x14(%rsp), %edx
movslq %edx, %rcx
decl %edx
movl %edx, 0x14(%rsp)
movq 0x18(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movl (%rsp), %r13d
movq 0x50(%rsp), %rbx
testq %rbp, %rbp
jne 0x5a15
movq %r12, %rdi
callq 0x4319
movl 0x4(%rsp), %edx
movslq %edx, %rcx
incl %edx
movl %edx, 0x4(%rsp)
movq 0x18(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movq 0x28(%rsp), %r15
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
movq 0x58(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0x2440
movq %rbx, %rdi
movq %rax, %rbx
callq 0x2030
movq %r14, %rdi
callq 0x2030
movl 0x20(%rsp), %r13d
movq 0x38(%rsp), %rcx
incq %rcx
incq 0x30(%rsp)
jmp 0x58f8
movq 0x48(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x5a81
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x42a5
incq %rbx
jmp 0x5a69
movq 0x8(%rsp), %rdi
callq 0x2030
movq 0x18(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq