// File: /workspace/github_c_makefile_star2_O3/cbouilla[P]AES-attacks-finder/EquationAES.c
// Function: MakeKS
int MakeKS(Equation *Eq, int Nk, int Tours, int Final)
{
	Equation tmp,tmp1,tmp2,tmp3;
	int i,j,pos;
	pos=0;
	for (i = Nk; i < (Tours+Final+1)*4; i++)
	{
		for (j = 0; j < 4; j++)
		{
			if (i%Nk==0)
			{
				tmp=varEq(4*(i-1)+(j+1)%4);
				tmp1=appliqueS(tmp,0);
				freeEq(tmp);
				if (j==0)
				{
					tmp2=varEq(VARIABLES-(i/Nk));
					tmp=addEq(tmp1,tmp2);
					freeEq(tmp1);
					freeEq(tmp2);
				}
				else tmp=tmp1;
				tmp1=varEq(4*(i-Nk)+j);
				tmp2=varEq(4*i+j);
				tmp3=addEq(tmp1,tmp2);
				Eq[pos++]=addEq(tmp,tmp3);
				freeEq(tmp);
				freeEq(tmp1);
				freeEq(tmp2);
				freeEq(tmp3);
			}
			else
			{
				if (Nk>6 && (i%Nk)==4)
				{
					tmp=varEq(4*(i-1)+j);
					tmp1=appliqueS(tmp,0);
					freeEq(tmp);
					tmp=tmp1;
					tmp1=varEq(4*(i-Nk)+j);
					tmp2=varEq(4*i+j);
					tmp3=addEq(tmp1,tmp2);
					Eq[pos++]=addEq(tmp,tmp3);
					freeEq(tmp);
					freeEq(tmp1);
					freeEq(tmp2);
					freeEq(tmp3);
				}
				else
				{
					tmp=varEq(4*(i-1)+j);
					tmp1=varEq(4*(i-Nk)+j);
					tmp2=varEq(4*i+j);
					tmp3=addEq(tmp1,tmp2);
					Eq[pos++]=addEq(tmp,tmp3);
					freeEq(tmp);
					freeEq(tmp1);
					freeEq(tmp2);
					freeEq(tmp3);
				}
			}
		}
	}
	return pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, 0x40(%rsp)
addl %ecx, %edx
leal 0x4(,%rdx,4), %ecx
xorl %eax, %eax
movl %ecx, 0x8(%rsp)
cmpl %esi, %ecx
jle 0x68aa
leal (,%rsi,4), %eax
movq %rax, 0x28(%rsp)
leal -0x4(,%rsi,4), %eax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r8d, %r8d
movl %esi, %edi
movq %rsi, 0x38(%rsp)
cmpl $0x7, %esi
setge %cl
movl %edi, %eax
cltd
idivl %esi
movl %eax, 0xc(%rsp)
movq %r8, %rax
movl %edx, 0x14(%rsp)
cmpl $0x4, %edx
sete %dl
andb %cl, %dl
movb %dl, 0x7(%rsp)
movq %rdi, 0x50(%rsp)
leal -0x4(,%rdi,4), %ecx
movl %ecx, 0x10(%rsp)
movq %r8, 0x30(%rsp)
movslq %eax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x48(%rsp)
leaq (%rax,%rcx,8), %r13
xorl %r15d, %r15d
cmpl $0x0, 0x14(%rsp)
je 0x67a2
movq 0x18(%rsp), %rax
leal (%rax,%r15), %edi
callq 0x4d63
movq %rax, %r14
cmpb $0x0, 0x7(%rsp)
je 0x6805
movq %r14, %rdi
xorl %esi, %esi
callq 0x57d7
movq %rax, %rbx
jmp 0x67fa
leal 0x1(%r15), %edi
andl $0x3, %edi
orl 0x10(%rsp), %edi
callq 0x4d63
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x57d7
movq %rax, %r14
movq %rbx, %rdi
callq 0x4ad9
testl %r15d, %r15d
jne 0x6805
movl 0x2bae3(%rip), %edi     # 0x322b8
subl 0xc(%rsp), %edi
callq 0x4d63
movq %rax, %r12
movq %r14, %rdi
movq %rax, %rsi
callq 0x557f
movq %rax, %rbx
movq %r14, %rdi
callq 0x4ad9
movq %r12, %r14
movq %r14, %rdi
callq 0x4ad9
movq %rbx, %r14
movq 0x20(%rsp), %rax
leal (%rax,%r15), %edi
callq 0x4d63
movq %rax, %rbx
movq 0x28(%rsp), %rax
leal (%rax,%r15), %edi
callq 0x4d63
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
callq 0x557f
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x557f
movq %rax, (%r13,%r15,8)
movq %r14, %rdi
callq 0x4ad9
movq %rbx, %rdi
callq 0x4ad9
movq %r12, %rdi
callq 0x4ad9
movq %rbp, %rdi
callq 0x4ad9
incq %r15
cmpl $0x4, %r15d
jne 0x6774
movq 0x50(%rsp), %rdi
incl %edi
movq 0x48(%rsp), %r8
addq %r15, %r8
addq $0x4, 0x20(%rsp)
addq $0x4, 0x28(%rsp)
addq $0x4, 0x18(%rsp)
cmpl 0x8(%rsp), %edi
movq 0x38(%rsp), %rsi
jne 0x6729
movq 0x30(%rsp), %rax
addl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq