// File: /workspace/github_c_makefile_star2_O2/cbouilla[P]AES-attacks-finder/Solver.c
// Function: ExtraireEquationUnion
Equation * ExtraireEquationUnion(Solver B, SysEqLin E, int *taille) // Renvoi les equations de E(X1 u X2) - (E(X1) + E(X2)).
{
	// Attention : les équation sont de la forme Eq[i] = Eq[i + *taille], Eq[i] est en les variables X2

	/* A améliorer, elle est beaucoup trop lente et c'est la fonction la plus utilisée dans l'écriture du code C. */

	
	
	const int a=E->gen*VARIABLES;

	__restrict SysEqLin F = ExtraireEX2(B->var,B->Nvar,E);

	unsigned char ** __restrict m1=malloc(a*sizeof(unsigned char *));
	unsigned char ** __restrict m2=malloc(a*sizeof(unsigned char *));
	unsigned char ** __restrict m3=malloc(a*sizeof(unsigned char *));
	int i;
	for (i = 0; i < a; i++)
	{
		m1[i]=malloc(F->b*sizeof(unsigned char));
		m2[i]=malloc(F->b*sizeof(unsigned char));
		m3[i]=malloc(F->b*sizeof(unsigned char));
	}

	int b1=ExtraireEX(m1,B->fils1->var,B->fils1->Nvar,F);
	int b2=ExtraireEX(m2,B->fils2->var,B->fils2->Nvar,F);	
	
	int b3=Somme(m3,m1,b1,m2,a,b2);
	//b1=ExtraireEX(m1,B->var,B->Nvar,E);
	
	b2=Supplementaire(m2,m3,b3,F->mat,a,F->b);
	for (i = 0; i < a; i++)
	{
		free(m1[i]);
		free(m3[i]);
	}
	free(m1);
	free(m3);
	__restrict SysEqLin G=malloc(sizeof(SYSEQLIN));
	G->mat=m2;
	G->gen=F->gen;
	G->a=F->a;
	G->b=b2;
	//->lignevar=malloc((VARIABLES)*sizeof(int));
	//for (i = 0; i < VARIABLES; i++) F->lignevar[i]=E->lignevar[i];
	G->lignevar=F->lignevar;
	Equation * __restrict Eq=ConversionSys2(B->fils2->var,B->fils2->Nvar,G);
	//free(F->lignevar);
	for (i = 0; i < a; i++) free(m2[i]);
	free(m2);
	freeSysEq(F);
	free(G);
	*taille=b2;
	return Eq;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, %rdx
movq %rdi, %rcx
leaq 0x27976(%rip), %rax     # 0x302b8
movl (%rax), %r12d
imull 0x10(%rsi), %r12d
movq (%rdi), %rdi
movq %rcx, 0x18(%rsp)
movl 0x8(%rcx), %esi
callq 0xace0
movq %rax, 0x8(%rsp)
movslq %r12d, %rbx
leaq (,%rbx,8), %rbp
movq %rbp, %rdi
callq 0x21c0
movq %rax, %r13
movq %rbp, %rdi
callq 0x21c0
movq %rax, %r15
movq %rbp, %rdi
callq 0x21c0
movq %rax, %rbp
xorl %r14d, %r14d
testl %ebx, %ebx
movl $0x0, %ebx
movl %r12d, 0x14(%rsp)
cmovgl %r12d, %ebx
cmpq %r14, %rbx
je 0x89d7
movq 0x8(%rsp), %rax
movslq 0xc(%rax), %r12
movq %r12, %rdi
callq 0x21c0
movq %rax, (%r13,%r14,8)
movq %r12, %rdi
callq 0x21c0
movq %rax, (%r15,%r14,8)
movq %r12, %rdi
callq 0x21c0
movq %rax, (%rbp,%r14,8)
incq %r14
jmp 0x899e
movq 0x18(%rsp), %r12
movq 0x20(%r12), %rax
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r13, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rcx
callq 0xa644
movl %eax, 0x10(%rsp)
movq 0x28(%r12), %rax
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0xa644
movq %rbp, %rdi
movq %r13, %rsi
movl 0x10(%rsp), %edx
movq %r15, %rcx
movl 0x14(%rsp), %r12d
movl %r12d, %r8d
movl %eax, %r9d
callq 0x3372
movq (%r14), %rcx
movl 0xc(%r14), %r9d
movq %r15, %rdi
movq %rbp, %rsi
movl %eax, %edx
movl %r12d, %r8d
callq 0x38f0
movl %eax, %r12d
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x8a69
movq (%r13,%r14,8), %rdi
callq 0x2030
movq (%rbp,%r14,8), %rdi
callq 0x2030
incq %r14
jmp 0x8a4b
movq %r13, %rdi
callq 0x2030
movq %rbp, %rdi
callq 0x2030
pushq $0x40
popq %rdi
callq 0x21c0
movq %rax, %r13
movq %r15, (%rax)
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %eax
movl %eax, 0x10(%r13)
movl 0x8(%rcx), %eax
movl %eax, 0x8(%r13)
movl %r12d, %ebp
movl %r12d, 0xc(%r13)
movq 0x18(%rcx), %rax
movq %rax, 0x18(%r13)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq %r13, %rdx
callq 0xb380
movq %rax, %r12
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x8ad9
movq (%r15,%r14,8), %rdi
callq 0x2030
incq %r14
jmp 0x8ac6
movq %r15, %rdi
callq 0x2030
movq 0x8(%rsp), %rdi
callq 0xb562
movq %r13, %rdi
callq 0x2030
movq 0x20(%rsp), %rax
movl %ebp, (%rax)
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq