// File: /workspace/github_c_makefile_star2_O2/cbouilla[P]AES-attacks-finder/Equation.c
// Function: remplaceEq
Equation remplaceEq(Equation a, int var, Equation b)
{
	int i;
	Equation p,tmp,tmp1;
	p=malloc(sizeof(EQUATION));
	p->nS=a->nS;
	if (p->nS>0)
	{
		p->S=malloc(p->nS*sizeof(Equation));
		p->coefS=malloc(p->nS*sizeof(unsigned char));
		p->sbox=malloc(p->nS*sizeof(unsigned char));
		for (i = 0; i < p->nS; i++)
		{
			p->sbox[i]=a->sbox[i];
			p->coefS[i]=a->coefS[i];
			if (dependEq(a->S[i],var)) p->S[i]=remplaceEq(a->S[i],var,b);
			else p->S[i]=copyEq(a->S[i]);
		}
	}
	else
	{
		p->S=NULL;
		p->coefS=NULL;
		p->sbox=NULL;
	}
	p->nV=0;
	tmp=NULL;
	if (a->nV>0)
	{
		p->var=malloc(a->nV*sizeof(unsigned int));
		p->coefV=malloc(a->nV*sizeof(unsigned char));
		for (i = 0; i < a->nV; i++)
		{
			if (a->var[i]==var) tmp=mulEq(a->coefV[i],b);
			else
			{
				p->var[p->nV]=a->var[i];
				p->coefV[p->nV]=a->coefV[i];
				p->nV++;
			}
		}
		if (p->nV==0)
		{
			free(p->var);
			free(p->coefV);
			p->var=NULL;
			p->coefV=NULL;
		}
	}
	else
	{
		p->var=NULL;
		p->coefV=NULL;
	}
	if (tmp==NULL)
	{
		tmp=reduitEq(p);
		freeEq(p);
		return tmp;
	}
	else
	{
		tmp1=addEq(tmp,p);
		freeEq(tmp);
		freeEq(p);
		return tmp1;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, %r15
pushq $0x38
popq %rdi
callq 0x21c0
movq %rax, %rbx
movslq 0x18(%r15), %r12
movl %r12d, 0x18(%rax)
testq %r12, %r12
movq %rax, 0x8(%rsp)
jle 0x4f5e
leaq (,%r12,8), %rdi
callq 0x21c0
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%rbx)
movq %r12, %rdi
callq 0x21c0
movq %rax, 0x20(%rsp)
movq %rax, 0x28(%rbx)
movq %r12, %rdi
callq 0x21c0
movq %rax, %r13
movq %rax, 0x30(%rbx)
xorl %r14d, %r14d
cmpq %r12, %r14
jae 0x4f6a
movq %r12, %rbx
movq 0x30(%r15), %rax
movb (%rax,%r14), %al
movb %al, (%r13,%r14)
movq 0x28(%r15), %rax
movb (%rax,%r14), %al
movq 0x20(%rsp), %rcx
movb %al, (%rcx,%r14)
movq 0x20(%r15), %rax
movq (%rax,%r14,8), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0x4e21
movq %r12, %rdi
testl %eax, %eax
je 0x4f48
movl %ebp, %esi
movq 0x18(%rsp), %rdx
callq 0x4e89
jmp 0x4f4d
callq 0x4319
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
movq %rbx, %r12
jmp 0x4efb
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
andq $0x0, 0x30(%rbx)
movq 0x8(%rsp), %rbx
andl $0x0, (%rbx)
movslq (%r15), %r14
testq %r14, %r14
jle 0x5048
leaq (,%r14,4), %rdi
callq 0x21c0
movq %rbx, %rcx
addq $0x8, %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rbx)
movq %r14, %rdi
callq 0x21c0
movq %rax, 0x10(%rbx)
xorl %r13d, %r13d
xorl %r12d, %r12d
movslq %r14d, %rax
cmpq %rax, %r13
jge 0x5004
movq 0x8(%r15), %rax
movl (%rax,%r13,4), %eax
cmpl %ebp, %eax
jne 0x4fd9
movq 0x10(%r15), %rax
movzbl (%rax,%r13), %edi
movq 0x18(%rsp), %rsi
callq 0x45c6
movq %rax, %r12
jmp 0x4ffc
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rcx
movslq (%rsi), %rdx
movl %eax, (%rcx,%rdx,4)
movq 0x10(%r15), %rax
movb (%rax,%r13), %al
movq 0x10(%rsi), %rcx
movslq (%rsi), %rdx
movb %al, (%rcx,%rdx)
incl (%rsi)
incq %r13
movl (%r15), %r14d
jmp 0x4fad
movq 0x8(%rsp), %rbx
cmpl $0x0, (%rbx)
jne 0x502b
movq 0x8(%rbx), %rdi
callq 0x2030
movq 0x10(%rbx), %rdi
callq 0x2030
xorps %xmm0, %xmm0
movq 0x10(%rsp), %rax
movups %xmm0, (%rax)
testq %r12, %r12
je 0x504f
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4b60
movq %rax, %r14
movq %r12, %rdi
callq 0x42a5
jmp 0x505a
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x4716
movq %rax, %r14
movq %rbx, %rdi
callq 0x42a5
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq