// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rdi, 0x30(%rsp)
addl %ecx, %edx
leal 0x4(,%rdx,4), %eax
movl %eax, 0x4(%rsp)
leal (,%rsi,4), %eax
movq %rax, 0x28(%rsp)
leal -0x4(,%rsi,4), %eax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq %rsi, 0x38(%rsp)
movl %esi, %r8d
xorl %edi, %edi
cmpl 0x4(%rsp), %r8d
jge 0x5da1
movq 0x38(%rsp), %rsi
cmpl $0x7, %esi
setge %cl
movl %r8d, %eax
cltd
idivl %esi
movl %eax, 0xc(%rsp)
movl %edx, 0x14(%rsp)
cmpl $0x4, %edx
sete %al
andb %cl, %al
movb %al, 0x3(%rsp)
movq %r8, 0x40(%rsp)
leal -0x4(,%r8,4), %eax
movl %eax, 0x10(%rsp)
movl %edi, 0x8(%rsp)
movslq %edi, %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,8), %r13
xorl %r12d, %r12d
cmpl $0x4, %r12d
je 0x5d7b
cmpl $0x0, 0x14(%rsp)
je 0x5caf
movq 0x18(%rsp), %rax
leal (%rax,%r12), %edi
callq 0x451b
movq %rax, %r14
cmpb $0x0, 0x3(%rsp)
je 0x5d13
movq %r14, %rdi
xorl %esi, %esi
callq 0x4d8b
movq %rax, %rbx
jmp 0x5d08
leal 0x1(%r12), %edi
andl $0x3, %edi
orl 0x10(%rsp), %edi
callq 0x451b
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x4d8b
movq %rax, %r14
movq %rbx, %rdi
callq 0x42a5
testl %r12d, %r12d
jne 0x5d13
movl 0x2a5d5(%rip), %edi     # 0x302b8
subl 0xc(%rsp), %edi
callq 0x451b
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x4b60
movq %rax, %rbx
movq %r14, %rdi
callq 0x42a5
movq %rbp, %r14
movq %r14, %rdi
callq 0x42a5
movq %rbx, %r14
movq 0x20(%rsp), %rax
leal (%rax,%r12), %edi
callq 0x451b
movq %rax, %rbx
movq 0x28(%rsp), %rax
leal (%rax,%r12), %edi
callq 0x451b
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4b60
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x4b60
movq %rax, (%r13,%r12,8)
movq %r14, %rdi
callq 0x42a5
movq %rbx, %rdi
callq 0x42a5
movq %rbp, %rdi
callq 0x42a5
movq %r15, %rdi
callq 0x42a5
incq %r12
jmp 0x5c77
movl 0x8(%rsp), %edi
addl %r12d, %edi
movq 0x40(%rsp), %r8
incl %r8d
addq $0x4, 0x20(%rsp)
addq $0x4, 0x28(%rsp)
addq $0x4, 0x18(%rsp)
jmp 0x5c23
movl %edi, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq