// File: /workspace/github_c_makefile_star2_O1/cbouilla[P]AES-attacks-finder/EquationAES.c
// Function: MakeEquations2
Equation * MakeEquations2(int Nk, int Tours, int Final, int Messages, int *N)
{
  Equation *Eq,*Eq2,tmp1,tmp2;/*,tmp3;*/
	int i,j,dec,pos;
	/*int t;*/
	Eq=MakeEquations(Nk,Tours,Final,Messages,N);
	*N=*N+(Messages-1)*15;
	Eq2=malloc((*N+1)*sizeof(Equation));
	dec=(Tours+Final+1)*16;
	pos=0;
	for (i = 1; i < 16; i++)
	{
		for (j = 1; j < Messages; j++)
		{
			tmp1=varEq(dec+i);
			tmp2=varEq((2*(Tours+Final)+1)*16*j+dec+i);
			Eq2[pos++]=addEq(tmp1,tmp2);
			freeEq(tmp1);
			freeEq(tmp2);
		}
	}
	for (i = 0; i < *N-(Messages-1)*15; i++) Eq2[pos++]=Eq[i];
	free(Eq);
	/*for (i = dec; i < 176; i++)
	{
		printf("%d / %d\n",i-dec,176-dec);
		tmp1=varEq(i);
		tmp2=varEq(i+176-dec);
		Eq2[*N]=addEq(tmp1,tmp2);
		t=SimplifySysEq(Eq2,*N+1);
		if (t<=*N)
		{
			freeEq(tmp1);
			tmp1=varEq(i);
			for (j = 0; j < *N; j++)
			{
				tmp3=remplaceEq(Eq2[j],i+176-dec,tmp1);
				freeEq(Eq2[j]);
				Eq2[j]=tmp3;
			}
			*N=SimplifySysEq(Eq2,t);
		}
		else freeEq(Eq2[*N]);
		freeEq(tmp1);
		freeEq(tmp2);
		tmp3=varEq(i);
		tmp1=appliqueS(tmp3,0);
		freeEq(tmp3);
		tmp3=varEq(i+176-dec);
		tmp2=appliqueS(tmp3,0);
		freeEq(tmp3);
		Eq2[*N]=addEq(tmp1,tmp2);
		t=SimplifySysEq(Eq2,*N+1);
		if (t<=*N)
		{
			freeEq(tmp1);
			tmp1=varEq(i);
			for (j = 0; j < *N; j++)
			{
				tmp3=remplaceEq(Eq2[j],i+176-dec,tmp1);
				freeEq(Eq2[j]);
				Eq2[j]=tmp3;
			}
			*N=SimplifySysEq(Eq2,t);
		}
		else freeEq(Eq2[*N]);
		freeEq(tmp1);
		freeEq(tmp2);
		tmp3=varEq(i);
		tmp1=appliqueS(tmp3,1);
		freeEq(tmp3);
		tmp3=varEq(i+176-dec);
		tmp2=appliqueS(tmp3,1);
		freeEq(tmp3);
		Eq2[*N]=addEq(tmp1,tmp2);
		t=SimplifySysEq(Eq2,*N+1);
		if (t<=*N)
		{
			freeEq(tmp1);
			tmp1=varEq(i);
			for (j = 0; j < *N; j++)
			{
				tmp3=remplaceEq(Eq2[j],i+176-dec,tmp1);
				freeEq(Eq2[j]);
				Eq2[j]=tmp3;
			}
			*N=SimplifySysEq(Eq2,t);
		}
		else freeEq(Eq2[*N]);
		freeEq(tmp1);
		freeEq(tmp2);
	}*/
	return Eq2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, %rbx
movl %ecx, %r14d
movl %edx, %r13d
movl %esi, %ebp
callq 0x6898
movq %rax, 0x28(%rsp)
movslq (%rbx), %rax
leal (%r14,%r14,4), %ecx
leal (%rcx,%rcx,2), %edx
movl %edx, 0x8(%rsp)
leal (%rcx,%rcx,2), %ecx
addl $-0xf, %ecx
movl %ecx, 0xc(%rsp)
movslq %ecx, %rcx
addq %rax, %rcx
movq %rbx, 0x20(%rsp)
movl %ecx, (%rbx)
leaq 0x8(,%rcx,8), %rdi
callq 0x21d0
movq %rax, (%rsp)
addl %ebp, %r13d
movl %r13d, %eax
shll $0x4, %eax
addl $0x10, %eax
movl %eax, 0x10(%rsp)
leal -0x1(%r14), %r15d
movl %r13d, %ebp
shll $0x5, %ebp
leal (%r13,%r13,2), %r13d
shll $0x4, %r13d
addl $0x21, %r13d
orl $0x10, %ebp
movl $0x1, %eax
xorl %ecx, %ecx
movq %r14, 0x30(%rsp)
cmpl $0x2, %r14d
jl 0x6e2d
movl %eax, 0x14(%rsp)
orl 0x10(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq %rcx, 0x38(%rsp)
movslq %ecx, %rax
movq (%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x40(%rsp)
movl %r13d, 0x18(%rsp)
xorl %r12d, %r12d
movl 0x1c(%rsp), %edi
callq 0x4afc
movq %rax, %rbx
movl %r13d, %edi
callq 0x4afc
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5221
movq 0x40(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
movq %rbx, %rdi
callq 0x484f
movq %r14, %rdi
callq 0x484f
incq %r12
addl %ebp, %r13d
cmpl %r12d, %r15d
jne 0x6dd1
movq 0x38(%rsp), %rcx
addl %r12d, %ecx
movq 0x30(%rsp), %r14
movl 0x18(%rsp), %r13d
movl 0x14(%rsp), %eax
incl %eax
incl %r13d
cmpl $0x10, %eax
jne 0x6d9e
movq 0x20(%rsp), %rax
movl (%rax), %eax
cmpl 0xc(%rsp), %eax
movq 0x28(%rsp), %rbx
jle 0x6e6f
movslq %ecx, %rcx
movq (%rsp), %rdx
leaq (%rdx,%rcx,8), %rdi
subl 0x8(%rsp), %eax
addl $0xe, %eax
leaq 0x8(,%rax,8), %rdx
movq %rbx, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2030
movq (%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq