// File: /workspace/github_c_makefile_star2_O1/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, 0x38(%rsp)
addl %ecx, %edx
leal 0x4(,%rdx,4), %ecx
xorl %eax, %eax
movl %ecx, 0x10(%rsp)
cmpl %esi, %ecx
jle 0x6545
leal -0x4(,%rsi,4), %eax
movq %rax, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r8d, %r8d
movl %esi, %edi
movq %rsi, 0x30(%rsp)
cmpl $0x7, %esi
setge %cl
movl %edi, %eax
cltd
idivl %esi
movl %eax, 0x14(%rsp)
movq %r8, %rax
movl %edx, 0x1c(%rsp)
cmpl $0x4, %edx
sete %dl
andb %cl, %dl
movb %dl, 0x7(%rsp)
leal (,%rdi,4), %ecx
movq %rcx, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
leal -0x4(,%rdi,4), %ecx
movl %ecx, 0x18(%rsp)
movq %r8, 0x28(%rsp)
movslq %eax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x40(%rsp)
leaq (%rax,%rcx,8), %r13
xorl %r12d, %r12d
cmpl $0x0, 0x1c(%rsp)
je 0x6432
cmpb $0x0, 0x7(%rsp)
je 0x6495
movq 0x8(%rsp), %rax
leal (%rax,%r12), %edi
callq 0x4afc
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x544b
movq %rax, %r14
movq %rbx, %rdi
callq 0x484f
jmp 0x64a6
leal 0x1(%r12), %edi
andl $0x3, %edi
orl 0x18(%rsp), %edi
callq 0x4afc
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x544b
movq %rax, %r14
movq %rbx, %rdi
callq 0x484f
testl %r12d, %r12d
jne 0x64a6
movl 0x2be52(%rip), %edi     # 0x322b8
subl 0x14(%rsp), %edi
callq 0x4afc
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
callq 0x5221
movq %rax, %r15
movq %r14, %rdi
callq 0x484f
movq %rbx, %rdi
callq 0x484f
movq %r15, %r14
jmp 0x64a6
movq 0x8(%rsp), %rax
leal (%rax,%r12), %edi
callq 0x4afc
movq %rax, %r14
movq 0x20(%rsp), %rax
leal (%rax,%r12), %edi
callq 0x4afc
movq %rax, %rbx
movq 0x50(%rsp), %rax
leal (%r12,%rax), %edi
callq 0x4afc
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5221
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x5221
movq %rax, (%r13,%r12,8)
movq %r14, %rdi
callq 0x484f
movq %rbx, %rdi
callq 0x484f
movq %r15, %rdi
callq 0x484f
movq %rbp, %rdi
callq 0x484f
incq %r12
cmpl $0x4, %r12d
jne 0x63f8
movq 0x48(%rsp), %rdi
incl %edi
movq 0x40(%rsp), %r8
addq %r12, %r8
addq $0x4, 0x20(%rsp)
addq $0x4, 0x8(%rsp)
cmpl 0x10(%rsp), %edi
movq 0x30(%rsp), %rsi
jne 0x63a1
movq 0x28(%rsp), %rax
addl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq