// File: /workspace/github_c_makefile_star2_O0/cbouilla[P]AES-attacks-finder/Equation.c
// Function: reduitEq
Equation reduitEq(Equation a)
{	
	Equation p=NulEq();
	if (a->nV>0)
	{
		unsigned char *ajout=malloc(a->nV*sizeof(unsigned char));
		p->var=malloc(a->nV*sizeof(int));
		p->coefV=malloc(a->nV*sizeof(unsigned char));
		int i;
		for (i = 0; i < a->nV; i++) ajout[i]=1;
		for (i = 0; i < a->nV; i++)
		{
			if (ajout[i])
			{
				unsigned char coeff=a->coefV[i];
				int j;
				for (j = i+1; j < a->nV; j++)
				{
					if (a->var[j]==a->var[i])
					{
						ajout[j]=0;
						coeff^=a->coefV[j];
					}
				}
				if (coeff!=0)
				{
					p->var[p->nV]=a->var[i];
					p->coefV[p->nV]=coeff;
					p->nV++;
				}
			}
		}
		free(ajout);
		if (p->nV==0)
		{
			free(p->var);
			free(p->coefV);
		}
	}
	
	if (a->nS>0)
	{
		unsigned char *ajout=malloc(a->nS*sizeof(unsigned char));
		p->S=malloc(a->nS*sizeof(Equation));
		p->coefS=malloc(a->nS*sizeof(unsigned char));
		p->sbox=malloc(a->nS*sizeof(unsigned char));
		Equation *red=malloc(a->nS*sizeof(Equation));
		int i;
		for (i = 0; i < a->nS; i++)
		{
			red[i]=reduitEq(a->S[i]);
			ajout[i]=1;
		}
		for (i = 0; i < a->nS; i++)
		{
			if (ajout[i])
			{
				unsigned char coeff=a->coefS[i];
				int j;
				for (j = i+1; j < a->nS; j++)
				{
					if (a->sbox[j]==a->sbox[i] && EgaleEq(red[i],red[j]))
					{
						ajout[j]=0;
						coeff^=a->coefS[j];
					}
				}
				if (coeff!=0)
				{
					p->coefS[p->nS]=coeff;
					p->sbox[p->nS]=a->sbox[i];
					p->S[p->nS]=copyEq(red[i]);
					p->nS++;
				}
			}
		}
		free(ajout);
		for (i = 0; i < a->nS; i++) freeEq(red[i]);
		free(red);
		if (p->nS==0)
		{
			free(p->S);
			free(p->sbox);
			free(p->coefS);
		}
	}
	
	if (p->nS==0) return p;
	else
	{
		Equation pp=malloc(sizeof(EQUATION));
		pp->nV=p->nV;
		if (p->nV>0)
		{
			pp->var=malloc(p->nV*sizeof(int));
			pp->coefV=malloc(p->nV*sizeof(unsigned char));
			int i;
			for (i = 0; i < p->nV; i++)
			{
				pp->var[i]=p->var[i];
				pp->coefV[i]=p->coefV[i];
			}
		}
		else
		{
			pp->var=NULL;
			pp->coefV=NULL;
		}
		pp->nS=0;
		pp->S=malloc(p->nS*sizeof(Equation));
		pp->sbox=malloc(p->nS*sizeof(unsigned char));
		pp->coefS=malloc(p->nS*sizeof(unsigned char));
		Equation tmp=NulEq();
		int i;
		for (i = 0; i < p->nS; i++)
		{
			int res=(p->S[i]->nS==1 && p->S[i]->nV==0);
			if (res) res=(p->S[i]->coefS[0]==0x01 && p->S[i]->sbox[0]!=p->sbox[i]);
			if (res)
			{
				Equation tmp1=mulEq(p->coefS[i],p->S[i]->S[0]);
				Equation tmp2=addEq(tmp1,tmp);
				freeEq(tmp);
				freeEq(tmp1);
				tmp=tmp2;
			}
			else
			{
				pp->S[pp->nS]=copyEq(p->S[i]);
				pp->coefS[pp->nS]=p->coefS[i];
				pp->sbox[pp->nS]=p->sbox[i];
				pp->nS++;
			}
		}
		if (pp->nS==0)
		{
			free(pp->S);
			free(pp->sbox);
			free(pp->coefS);
		}
		freeEq(p);
		if (EstNulEq(tmp))
		{
			freeEq(tmp);
			return pp;
		}
		else
		{
			p=addEq(tmp,pp);
			freeEq(tmp);
			freeEq(pp);
			return p;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
callq 0x5850
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x62c2
movq -0x10(%rbp), %rax
movslq (%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movslq (%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6198
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6176
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6294
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x6284
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x25(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6238
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x24(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x622b
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movzbl -0x25(%rbp), %eax
xorl %ecx, %eax
movb %al, -0x25(%rbp)
jmp 0x622d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x61db
movzbl -0x25(%rbp), %eax
cmpl $0x0, %eax
je 0x6282
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movb -0x25(%rbp), %dl
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x6284
jmp 0x6286
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x619f
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x62c0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2030
jmp 0x62c2
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x6563
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x639c
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x6100
movq %rax, %rdx
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x6355
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x64ef
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x64df
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x44(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x45(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x6467
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x4c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x44(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x6457
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x5bc0
cmpl $0x0, %eax
je 0x6457
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x4c(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movzbl -0x45(%rbp), %eax
xorl %ecx, %eax
movb %al, -0x45(%rbp)
jmp 0x6459
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x63e0
movzbl -0x45(%rbp), %eax
cmpl $0x0, %eax
je 0x64dd
movb -0x45(%rbp), %dl
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x44(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x59c0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0x64df
jmp 0x64e1
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x63a3
movq -0x38(%rbp), %rdi
callq 0x2030
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x6527
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x5900
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x64ff
movq -0x40(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x6561
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2030
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2030
jmp 0x6563
movq -0x18(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x657a
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x68f3
movl $0x38, %edi
callq 0x21c0
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x6632
movq -0x18(%rbp), %rax
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movslq (%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x6630
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x5c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x5c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x65de
jmp 0x664a
movq -0x58(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movslq 0x18(%rax), %rdi
shlq $0x0, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x28(%rax)
callq 0x5850
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x686d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
xorl %eax, %eax
cmpl $0x1, 0x18(%rcx)
movb %al, -0x81(%rbp)
jne 0x6703
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax)
sete %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x677b
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, -0x82(%rbp)
jne 0x676d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x30(%rax), %rax
movzbl (%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x6c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x67e0
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x6c(%rbp), %rcx
movb (%rax,%rcx), %al
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x6c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx), %rsi
movzbl %al, %edi
callq 0x5ea0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x6900
movq %rax, -0x80(%rbp)
movq -0x68(%rbp), %rdi
callq 0x5900
movq -0x78(%rbp), %rdi
callq 0x5900
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x685d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x59c0
movq %rax, %rdx
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x58(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x6c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x6c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x58(%rbp), %rcx
movslq 0x18(%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x58(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0x685f
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x66b9
movq -0x58(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x689e
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2030
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2030
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2030
movq -0x18(%rbp), %rdi
callq 0x5900
movq -0x68(%rbp), %rdi
callq 0x58d0
cmpl $0x0, %eax
je 0x68c8
movq -0x68(%rbp), %rdi
callq 0x5900
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x68f3
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x6900
movq %rax, -0x18(%rbp)
movq -0x68(%rbp), %rdi
callq 0x5900
movq -0x58(%rbp), %rdi
callq 0x5900
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq