// File: /workspace/github_c_makefile_star2_O2/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, %r13d
leal (%r14,%r15), %eax
leal (%r14,%r15), %r12d
incl %r12d
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, 0x2a188(%rip)     # 0x302b8
movl %r12d, %ecx
shll $0x4, %ecx
movl %ebp, %ebx
shll $0x4, %ebx
addl %esi, %eax
imull %ebx, %eax
leal (,%r13,4), %esi
subl %esi, %ebx
addl %ecx, %ebx
addl %eax, %ebx
leaq 0x2100e(%rip), %rdi     # 0x27163
movl %ebx, %esi
xorl %eax, %eax
callq 0x2110
movl %ebx, 0x4(%rsp)
movslq %ebx, %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rbx
movq %rax, %rdi
movl %r13d, %esi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x5bd8
xorl %ecx, %ecx
testl %r15d, %r15d
cmovlel %ecx, %r15d
movq %r15, 0x10(%rsp)
testl %r14d, %r14d
cmovlel %ecx, %r14d
movq %r14, 0x20(%rsp)
movl %eax, %r13d
testl %ebp, %ebp
cmovlel %ecx, %ebp
movl %ebp, 0x8(%rsp)
cmpl 0x8(%rsp), %ecx
je 0x6251
movl %ecx, 0xc(%rsp)
xorl %ebp, %ebp
cmpl %ebp, 0x10(%rsp)
je 0x61f7
movslq %r13d, %r15
leaq (%rbx,%r15,8), %rdi
leal 0x1(%r12), %r14d
movl %ebp, %esi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x5fbe
addl %eax, %r15d
movslq %r15d, %r13
leaq (%rbx,%r13,8), %rdi
addl $0x2, %r12d
movl %r14d, %esi
movl %r12d, %edx
callq 0x5ea3
addl %eax, %r13d
incl %ebp
jmp 0x61b8
addl 0x20(%rsp), %ebp
movq 0x10(%rsp), %rax
movl %eax, %r14d
movslq %r13d, %rax
leaq (%rbx,%rax,8), %rdi
cmpl %r14d, %ebp
je 0x622d
leal 0x1(%r12), %r15d
movl %r14d, %esi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x5fbe
addl %eax, %r13d
incl %r14d
movl %r15d, %r12d
jmp 0x6203
leal 0x1(%r12), %ecx
movl %ebp, %esi
movl %r12d, %edx
callq 0x5db2
addl %r13d, %eax
addl $0x2, %r12d
movl 0xc(%rsp), %ecx
incl %ecx
movl %eax, %r13d
jmp 0x61a8
movq 0x18(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq