// File: /workspace/github_c_makefile_star2_O1/cbouilla[P]AES-attacks-finder/EquationAES.c
// Function: MakeEquations
Equation * MakeEquations(int Nk, int Tours, int Final, int Messages, int *N)
{
	int NombreEtat,NombreCstRonde,NombreEqKS,NombreEqMC,NombreEqSS,NombreEqAK;
	Equation *Eq;
	int i,j,pos,taille,state,key;
	
	NombreEtat=Tours+Final+1+Messages*(2*Tours+Final+2);
	NombreCstRonde=Tours+Final;
	VARIABLES=16*NombreEtat+NombreCstRonde;
	NombreEqKS=((Tours+Final+1)*4-Nk)*4;
	NombreEqMC=16*Tours*Messages;
	NombreEqSS=16*(Tours+Final)*Messages;
	NombreEqAK=16*Messages;
	taille=NombreEqKS+NombreEqMC+NombreEqSS+NombreEqAK;
	printf("taille = %d, Variables = %d\n",taille,VARIABLES);
	Eq=malloc(taille*sizeof(Equation));
	pos=MakeKS(Eq,Nk,Tours,Final);
	state=(Tours+Final+1);
	for (i = 0; i < Messages; i++)
	{
		key=0;
		for (j = 0; j < Tours; j++)
		{
			pos+=MakeSS(Eq+pos,key,state,state+1);
			state++;
			pos+=MakeMC(Eq+pos,state,state+1);
			state++;
			key++;
		}
		for (j = 0; j < Final; j++)
		{
			pos+=MakeSS(Eq+pos,key,state,state+1);
			state++;
			key++;
		}
		pos+=MakeAK(Eq+pos,key,state,state+1);
		state+=2;
	}
	/*for (i = 0; i < pos; i++)
	{
		printf("Eq[%d] : ",i);
		PrintEq(Eq[i]);
		printf("\n");
	}
	getchar();
	*/
	*N=taille;
	return Eq;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %r15d
movl %edi, %r12d
leal (%r14,%r15), %eax
leal (%r14,%r15), %r13d
incl %r13d
leal (%r14,%r15,2), %ecx
addl $0x2, %ecx
imull %ebp, %ecx
leal (%rcx,%rax), %edx
incl %edx
shll $0x4, %edx
addl %eax, %edx
movl %edx, 0x2b9dd(%rip)     # 0x322b8
movl %r13d, %ecx
shll $0x4, %ecx
movl %ebp, %ebx
shll $0x4, %ebx
addl %esi, %eax
imull %ebx, %eax
leal (,%r12,4), %esi
subl %esi, %ebx
addl %ecx, %ebx
addl %eax, %ebx
leaq 0x22863(%rip), %rdi     # 0x29163
movl $0x0, 0x4(%rsp)
movl %ebx, %esi
xorl %eax, %eax
callq 0x2110
movl %ebx, 0x8(%rsp)
movslq %ebx, %rdi
shlq $0x3, %rdi
callq 0x21d0
movq %rax, %rbx
movq %rax, %rdi
movl %r12d, %esi
movl %r15d, %edx
movq %r14, 0x20(%rsp)
movl %r14d, %ecx
callq 0x6358
movl %ebp, 0xc(%rsp)
testl %ebp, %ebp
jle 0x69fe
movl %eax, %r12d
movq %r15, 0x10(%rsp)
xorl %ebp, %ebp
testl %r15d, %r15d
jle 0x6998
movslq %r12d, %r15
leaq (%rbx,%r15,8), %rdi
leal 0x1(%r13), %r14d
movl %ebp, %esi
movl %r13d, %edx
movl %r14d, %ecx
callq 0x6763
addl %eax, %r15d
movslq %r15d, %r12
movq 0x10(%rsp), %r15
leaq (%rbx,%r12,8), %rdi
addl $0x2, %r13d
movl %r14d, %esi
movl %r13d, %edx
callq 0x6652
addl %eax, %r12d
incl %ebp
cmpl %ebp, %r15d
jne 0x6955
movl %r15d, %ebp
movq 0x20(%rsp), %rax
movl %eax, %r15d
testl %eax, %eax
jle 0x69c9
movslq %r12d, %r12
leaq (%rbx,%r12,8), %rdi
leal 0x1(%r13), %r14d
movl %ebp, %esi
movl %r13d, %edx
movl %r14d, %ecx
callq 0x6763
addl %eax, %r12d
incl %ebp
movl %r14d, %r13d
decl %r15d
jne 0x69a4
movslq %r12d, %r12
leaq (%rbx,%r12,8), %rdi
leal 0x1(%r13), %ecx
movl %ebp, %esi
movl %r13d, %edx
callq 0x6554
addl %eax, %r12d
addl $0x2, %r13d
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x4(%rsp)
cmpl 0xc(%rsp), %eax
movq 0x10(%rsp), %r15
jne 0x694e
movq 0x18(%rsp), %rax
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq