// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %r8, %rbx
movl %ecx, %ebp
movl %edx, %r15d
movl %esi, %r14d
callq 0x60ed
movq %rax, 0x28(%rsp)
movslq (%rbx), %rax
movl %ebp, 0x1c(%rsp)
imull $0xf, %ebp, %ecx
addl $-0xf, %ecx
movl %ecx, 0x8(%rsp)
movslq %ecx, %rcx
addq %rax, %rcx
movq %rbx, 0x20(%rsp)
movl %ecx, (%rbx)
leaq 0x8(,%rcx,8), %rdi
callq 0x21c0
movq %rax, (%rsp)
addl %r14d, %r15d
movl %r15d, %eax
shll $0x4, %eax
addl $0x10, %eax
movl %eax, 0xc(%rsp)
imull $0x30, %r15d, %r14d
shll $0x5, %r15d
addl $0x21, %r14d
orl $0x10, %r15d
movl %r15d, 0x18(%rsp)
xorl %eax, %eax
pushq $0x1
popq %r13
movslq %eax, %rdx
cmpl $0x10, %r13d
je 0x6633
movq %rax, 0x30(%rsp)
movl %r13d, 0x10(%rsp)
orl 0xc(%rsp), %r13d
movq (%rsp), %rax
leaq (%rax,%rdx,8), %rbp
movl %r14d, 0x14(%rsp)
xorl %r12d, %r12d
leal 0x1(%r12), %eax
cmpl 0x1c(%rsp), %eax
jge 0x6616
movl %r13d, %edi
callq 0x451b
movq %rax, %rbx
movl %r14d, %edi
callq 0x451b
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4b60
movq %rax, (%rbp,%r12,8)
movq %rbx, %rdi
callq 0x42a5
movq %r15, %rdi
callq 0x42a5
incq %r12
addl 0x18(%rsp), %r14d
jmp 0x65cb
movq 0x30(%rsp), %rax
addl %r12d, %eax
movl 0x10(%rsp), %r13d
incl %r13d
movl 0x14(%rsp), %r14d
incl %r14d
jmp 0x659f
movq 0x20(%rsp), %rax
movl (%rax), %eax
subl 0x8(%rsp), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq (%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
movq 0x28(%rsp), %rdi
cmpq %rcx, %rax
je 0x6664
movq (%rdi,%rcx,8), %rsi
movq %rsi, (%rdx,%rcx,8)
incq %rcx
jmp 0x6652
callq 0x2030
movq (%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq