// File: /workspace/github_c_makefile_star2_O2/cbouilla[P]AES-attacks-finder/SysEqLin.c
// Function: Transform2
SysEqLin Transform2(Equation *Eq, int taille, int gen) // Transforme une système d'équations en SysEqLin
{
	Equation *A;
	SysEqLin E;
	int i,*dedans,j,NA;
	A=Linearise(Eq,taille,&NA); // Probablement inutile maintenant
#if DISPLAY_EQUATIONS==1
	for (i = 0; i < NA; i++)
	{
		printf("Eq[%d] : ",i);
		PrintEq(A[i]);
		printf("\n");
	}
#endif
	E=malloc(sizeof(SYSEQLIN));
	E->a=gen*VARIABLES;
	E->b=NA;
	E->gen=gen;
	E->mat=malloc(E->a*sizeof(unsigned char *));
	dedans=malloc(VARIABLES*sizeof(int));
	for (i = 0; i < VARIABLES; i++) dedans[i]=0;
	for (i = 0; i < E->a; i++)
	{
		E->mat[i]=malloc(NA*sizeof(unsigned char));
		for (j = 0; j < NA; j++) E->mat[i][j]=0;
	}
	for (i = 0; i < NA; i++)
	{
		for (j = 0; j < A[i]->nV; j++)
		{
			E->mat[gen*A[i]->var[j]][i]^=A[i]->coefV[j];
			dedans[A[i]->var[j]]=1;
		}
		for (j = 0; j < A[i]->nS; j++)
		{
			E->mat[gen*A[i]->S[j]->var[0]+A[i]->sbox[j]+1][i]^=A[i]->coefS[j];
			dedans[A[i]->S[j]->var[0]]=1;
		}
		freeEq(A[i]);
	}
	free(A);
	E->varligne=malloc(VARIABLES*sizeof(int));
	E->lignevar=malloc(VARIABLES*sizeof(int));
	for (i = 0; i < VARIABLES; i++) E->varligne[i]=i;
	for (i = 0; i < VARIABLES; i++) E->lignevar[i]=i;
	for (i = 0; i < VARIABLES; i++)
	{
		if (dedans[i]==0)
		{
			E->a=E->a-gen;
			PermuterVar(i,E->varligne[E->a/gen],E);
		}
	}
	E->initialise=0;
	return E;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
leaq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x5423
movq %rax, %r12
pushq $0x40
popq %rdi
callq 0x21c0
movq %rax, %r15
leaq 0x25e86(%rip), %rax     # 0x302b8
movslq (%rax), %rbx
movl %ebx, %eax
imull %ebp, %eax
movl %eax, 0x8(%r15)
movl (%r14), %r14d
movl %r14d, 0xc(%r15)
movl %ebp, 0x4(%rsp)
movl %ebp, 0x10(%r15)
movl %eax, %ebp
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %r13
movq %r15, 0x20(%rsp)
movq %rax, (%r15)
movq %rbx, %rdi
shlq $0x2, %rdi
movq %rdi, 0x18(%rsp)
callq 0x21c0
movq %rax, %r15
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %edx
cmovgl %ebx, %edx
cmpq %rax, %rdx
je 0xa495
andl $0x0, (%r15,%rax,4)
incq %rax
jmp 0xa486
xorl %ebx, %ebx
testl %ebp, %ebp
movl %ebp, %eax
movl $0x0, %ebp
movl %eax, 0xc(%rsp)
cmovgl %eax, %ebp
movq %rdx, 0x10(%rsp)
cmpq %rbp, %rbx
je 0xa4e0
movslq %r14d, %rdi
callq 0x21c0
movq %rax, (%r13,%rbx,8)
xorl %eax, %eax
movslq %r14d, %rcx
cmpq %rcx, %rax
jge 0xa4db
movq (%r13,%rbx,8), %rcx
movb $0x0, (%rcx,%rax)
incq %rax
movl 0x8(%rsp), %r14d
jmp 0xa4c0
incq %rbx
jmp 0xa4ac
xorl %ebp, %ebp
movslq 0x4(%rsp), %rbx
movslq %r14d, %rax
cmpq %rax, %rbp
jge 0xa59f
movq (%r12,%rbp,8), %rdi
xorl %eax, %eax
movslq (%rdi), %rcx
cmpq %rcx, %rax
jge 0xa535
movq 0x8(%rdi), %rcx
movq 0x10(%rdi), %rdx
movb (%rdx,%rax), %dl
movslq (%rcx,%rax,4), %rcx
imulq %rbx, %rcx
movq (%r13,%rcx,8), %rcx
xorb %dl, (%rcx,%rbp)
movq (%r12,%rbp,8), %rdi
movq 0x8(%rdi), %rcx
movslq (%rcx,%rax,4), %rcx
movl $0x1, (%r15,%rcx,4)
incq %rax
jmp 0xa4f9
xorl %eax, %eax
movslq 0x18(%rdi), %rcx
cmpq %rcx, %rax
jge 0xa58d
movq 0x20(%rdi), %rcx
movq 0x28(%rdi), %rdx
movb (%rdx,%rax), %dl
movq (%rcx,%rax,8), %rcx
movq 0x8(%rcx), %rcx
movslq (%rcx), %rcx
imulq %rbx, %rcx
movq 0x30(%rdi), %rsi
movzbl (%rsi,%rax), %esi
addq %rcx, %rsi
movq 0x8(%r13,%rsi,8), %rcx
xorb %dl, (%rcx,%rbp)
movq (%r12,%rbp,8), %rdi
movq 0x20(%rdi), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x8(%rcx), %rcx
movslq (%rcx), %rcx
movl $0x1, (%r15,%rcx,4)
incq %rax
jmp 0xa537
callq 0x42a5
incq %rbp
movl 0x8(%rsp), %r14d
jmp 0xa4e7
movq %r12, %rdi
callq 0x2030
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x21c0
movq %rax, %r12
movq 0x20(%rsp), %r14
movq %rax, 0x20(%r14)
movq %rbx, %rdi
callq 0x21c0
movq %rax, 0x18(%r14)
xorl %ecx, %ecx
movl 0x4(%rsp), %ebx
movl 0xc(%rsp), %ebp
movq 0x10(%rsp), %rdx
cmpq %rcx, %rdx
je 0xa5e9
movl %ecx, (%r12,%rcx,4)
incq %rcx
jmp 0xa5db
xorl %ecx, %ecx
cmpq %rcx, %rdx
je 0xa5f8
movl %ecx, (%rax,%rcx,4)
incq %rcx
jmp 0xa5eb
xorl %r13d, %r13d
cmpq %r13, %rdx
je 0xa62d
cmpl $0x0, (%r15,%r13,4)
jne 0xa628
subl %ebx, %ebp
movl %ebp, 0x8(%r14)
movl %ebp, %eax
cltd
idivl %ebx
cltq
movl (%r12,%rax,4), %esi
movl %r13d, %edi
movq %r14, %rdx
callq 0xa35c
movq 0x10(%rsp), %rdx
incq %r13
jmp 0xa5fb
movb $0x0, 0x28(%r14)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq