// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movl %r8d, %r14d
movq %rcx, 0x18(%rsp)
movq %rdx, 0x60(%rsp)
movl %esi, %ebp
movq %rdi, %r12
movslq %esi, %rbx
leaq (,%rbx,8), %r15
movq %r15, %rdi
callq 0x21d0
movq %rax, %r13
movq %rbp, 0x40(%rsp)
movl %ebp, %ebp
testl %ebx, %ebx
jle 0x5f74
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
callq 0x48c5
movq %rax, (%r13,%rbx,8)
incq %rbx
cmpq %rbx, %rbp
jne 0x5f5e
movq %r15, %rdi
callq 0x21d0
movq %rax, 0x20(%rsp)
movl %r14d, %r15d
movslq %r14d, %rbx
leaq (,%rbx,4), %rdi
callq 0x21d0
testl %ebx, %ebx
movq %rax, %rbx
jle 0x5faf
movl %r15d, %edx
shlq $0x2, %rdx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x21b0
movq 0x40(%rsp), %rax
testl %eax, %eax
jle 0x61a3
decl %eax
movl %eax, 0xc(%rsp)
xorl %r14d, %r14d
movq %rbp, %rax
movq %r13, %rcx
movl $0x0, 0x8(%rsp)
movq %r13, 0x48(%rsp)
movq %rbp, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq %rax, 0x58(%rsp)
movl %r15d, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movq (%r13,%r14,8), %r15
movq %r15, %rdi
leaq 0x3c(%rsp), %rsi
callq 0x5daf
movq %rax, %r14
movslq 0x3c(%rsp), %rbp
movq %rax, %rdi
movl %ebp, %esi
callq 0x2a2b
testq %rbp, %rbp
movq %r14, 0x50(%rsp)
movq %rbp, 0x68(%rsp)
jle 0x606f
movq %rbp, %r13
incq %r13
movl -0x8(%r14,%r13,4), %edi
movq %rbx, %r12
movq %rbx, %rsi
movl 0x18(%rsp), %edx
callq 0x291b
cmpl $-0x1, %eax
jne 0x6057
movl -0x8(%r14,%r13,4), %ebx
movq %r15, %rdi
movl %ebx, %esi
callq 0x53ed
cmpl $0x1, %eax
je 0x6077
decl %ebp
decq %r13
cmpq $0x1, %r13
movq %r12, %rbx
jg 0x602a
movq 0x48(%rsp), %r13
jmp 0x610f
movq %rbx, %r12
jmp 0x610f
movq %r15, %rdi
movl %ebx, %esi
callq 0x5705
movq %rax, %rcx
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x28(%rsp), %rax
movq 0x30(%rsp), %rdx
jae 0x60e5
movl $0x1, %r15d
movq (%rdx,%r15,8), %rbx
movl -0x8(%r14,%r13,4), %esi
movq %rbx, %rdi
movq %rcx, %r14
movq %rcx, %rdx
callq 0x5539
movq %rax, 0x70(%rsp)
movq %rbx, %rdi
callq 0x484f
movq 0x30(%rsp), %rdx
movq 0x58(%rsp), %rax
movq %r14, %rcx
movq 0x70(%rsp), %rsi
movq %rsi, (%rdx,%r15,8)
movq 0x50(%rsp), %r14
incq %r15
cmpq %r15, %rax
jne 0x609e
movq 0x48(%rsp), %r13
movq 0x10(%rsp), %rax
movq (%r13,%rax,8), %rdi
callq 0x48c5
movl 0xc(%rsp), %edx
movslq %edx, %rcx
decl %edx
movl %edx, 0xc(%rsp)
movq 0x20(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
testl %ebp, %ebp
movl 0x18(%rsp), %ebx
je 0x6123
movq 0x28(%rsp), %rbp
movq 0x10(%rsp), %r14
jmp 0x614d
movq 0x10(%rsp), %r14
movq (%r13,%r14,8), %rdi
callq 0x48c5
movl 0x8(%rsp), %edx
movslq %edx, %rcx
incl %edx
movl %edx, 0x8(%rsp)
movq 0x20(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movq 0x28(%rsp), %rbp
movq %r12, %r15
movq %r12, %rdi
movl %ebx, %esi
movq 0x50(%rsp), %r12
movq %r12, %rdx
movq 0x68(%rsp), %rcx
leaq 0x38(%rsp), %r8
callq 0x2544
movq %rax, %rbx
movq %r15, %rdi
callq 0x2030
movq %r12, %rdi
callq 0x2030
movl 0x38(%rsp), %r15d
incq %r14
movq 0x30(%rsp), %rcx
addq $0x8, %rcx
movq 0x58(%rsp), %rax
decq %rax
cmpq %rbp, %r14
jne 0x5fdd
jmp 0x61ab
movl $0x0, 0x8(%rsp)
movq 0x60(%rsp), %rax
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
cmpl $0x0, 0x40(%rsp)
jle 0x61d1
xorl %ebx, %ebx
movq (%r13,%rbx,8), %rdi
callq 0x484f
incq %rbx
cmpq %rbx, %rbp
jne 0x61bf
movq %r13, %rdi
callq 0x2030
movq 0x20(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq