// File: /workspace/github_c_makefile_star2_O3/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, 0x4(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, 0x50(%rsp)
movl %esi, %ebx
movq %rdi, %r13
movslq %esi, %r14
leaq (,%r14,8), %r15
movq %r15, %rdi
callq 0x21d0
movq %rax, %r12
movl %ebx, 0x18(%rsp)
movl %ebx, %ebp
movq %r14, 0x28(%rsp)
testl %r14d, %r14d
jle 0x62e5
xorl %ebx, %ebx
movq (%r13,%rbx,8), %rdi
callq 0x4b4b
movq %rax, (%r12,%rbx,8)
incq %rbx
cmpq %rbx, %rbp
jne 0x62cf
movq %r15, %rdi
callq 0x21d0
movq %rax, 0x30(%rsp)
movl 0x4(%rsp), %r13d
movslq %r13d, %rbx
leaq (,%rbx,4), %rdi
callq 0x21d0
testl %ebx, %ebx
movq %rax, %rbx
jle 0x6322
movl %r13d, %edx
shlq $0x2, %rdx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x21b0
cmpl $0x0, 0x18(%rsp)
jle 0x6544
movq 0x28(%rsp), %r14
leal -0x1(%r14), %eax
movl %eax, 0x1c(%rsp)
decq %r14
xorl %r15d, %r15d
movq %rbp, %rax
movq %r12, %rcx
movl $0x0, 0x14(%rsp)
movq %r12, 0x38(%rsp)
movq %rbp, 0x60(%rsp)
movq %r14, 0x28(%rsp)
movq %rcx, 0x40(%rsp)
movq %rax, 0x58(%rsp)
movq (%r12,%r15,8), %rbp
movq %rbp, %rdi
leaq 0x4c(%rsp), %rsi
callq 0x611c
movslq 0x4c(%rsp), %r12
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movl %r12d, %esi
callq 0x2bf3
testq %r12, %r12
movq %r12, 0x68(%rsp)
jle 0x63f7
movq %r15, 0x20(%rsp)
movl %r13d, 0x4(%rsp)
movq %r12, %r13
incq %r13
movq 0x8(%rsp), %rax
movl -0x8(%rax,%r13,4), %edi
movq %rbx, %r15
movq %rbx, %rsi
movl 0x4(%rsp), %edx
callq 0x2af1
cmpl $-0x1, %eax
jne 0x63de
movq 0x8(%rsp), %rax
movl -0x8(%rax,%r13,4), %ebx
movq %rbp, %rdi
movl %ebx, %esi
callq 0x5779
cmpl $0x1, %eax
je 0x63fc
decl %r12d
decq %r13
cmpq $0x1, %r13
movq %r15, %rbx
ja 0x63a7
movl 0x4(%rsp), %r13d
jmp 0x6494
jmp 0x6499
movq %rbp, %rdi
movl %ebx, %esi
callq 0x5ab1
cmpq %r14, 0x20(%rsp)
jge 0x646e
movl $0x1, %ebx
movq 0x40(%rsp), %rcx
movq (%rcx,%rbx,8), %rbp
movq 0x8(%rsp), %rcx
movl -0x8(%rcx,%r13,4), %esi
movq %rbp, %rdi
movq %rax, %r14
movq %rax, %rdx
callq 0x58d5
movq %rax, 0x70(%rsp)
movq %rbp, %rdi
callq 0x4ad9
movq %r14, %rax
movq 0x40(%rsp), %rcx
movq 0x70(%rsp), %rdx
movq %rdx, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, 0x58(%rsp)
jne 0x6417
movq 0x38(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rbp
movq 0x28(%rsp), %r14
movq %rbp, %rdi
callq 0x4b4b
movl 0x1c(%rsp), %edx
movslq %edx, %rcx
decl %edx
movl %edx, 0x1c(%rsp)
movq 0x30(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movl 0x4(%rsp), %r13d
movq %r15, %rbx
movq 0x20(%rsp), %r15
movq 0x8(%rsp), %rdx
testl %r12d, %r12d
jne 0x64c6
movq %rbp, %rdi
callq 0x4b4b
movl 0x14(%rsp), %edx
movslq %edx, %rcx
incl %edx
movl %edx, 0x14(%rsp)
movq 0x30(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movq 0x8(%rsp), %rdx
movq 0x38(%rsp), %r12
movq %rbx, %rdi
movl %r13d, %esi
movq 0x68(%rsp), %rcx
leaq 0x48(%rsp), %r8
movq %rdx, %r13
callq 0x2544
movq %rbx, %rdi
movq %rax, %rbx
callq 0x2030
movq %r13, %rdi
callq 0x2030
movl 0x48(%rsp), %r13d
incq %r15
movq 0x40(%rsp), %rcx
addq $0x8, %rcx
movq 0x58(%rsp), %rax
decq %rax
movq 0x60(%rsp), %rbp
cmpq %rbp, %r15
jne 0x635d
movq 0x50(%rsp), %rax
movl 0x14(%rsp), %ecx
movl %ecx, (%rax)
cmpl $0x0, 0x18(%rsp)
jle 0x654f
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
callq 0x4ad9
incq %rbx
cmpq %rbx, %rbp
jne 0x6531
jmp 0x654f
movq 0x50(%rsp), %rax
movl $0x0, (%rax)
movq %r12, %rdi
callq 0x2030
movq 0x30(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq