// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
movl $0x38, %edi
callq 0x21d0
movq %rax, %rbx
movslq 0x18(%r15), %r12
movl %r12d, 0x18(%rax)
testq %r12, %r12
jle 0x55fc
leaq (,%r12,8), %rdi
callq 0x21d0
movq %rax, 0x20(%rbx)
movq %r12, %rdi
callq 0x21d0
movq %rax, 0x28(%rbx)
movq %r12, %rdi
callq 0x21d0
movq %rax, 0x30(%rbx)
cmpl $0x0, 0x18(%rbx)
jle 0x560b
xorl %r13d, %r13d
movq 0x30(%r15), %rax
movb (%rax,%r13), %al
movq 0x30(%rbx), %rcx
movb %al, (%rcx,%r13)
movq 0x28(%r15), %rax
movb (%rax,%r13), %al
movq 0x28(%rbx), %rcx
movb %al, (%rcx,%r13)
movq 0x20(%r15), %rax
movq (%rax,%r13,8), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0x54d8
movq %r12, %rdi
testl %eax, %eax
je 0x55e1
movl %ebp, %esi
movq %r14, %rdx
callq 0x5539
jmp 0x55e6
callq 0x48c5
movq 0x20(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
movslq 0x18(%rbx), %rax
cmpq %rax, %r13
jl 0x559c
jmp 0x560b
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movq $0x0, 0x30(%rbx)
movl $0x0, (%rbx)
movslq (%r15), %r12
testq %r12, %r12
jle 0x568f
leaq (,%r12,4), %rdi
callq 0x21d0
movq %rax, 0x8(%rbx)
movq %r12, %rdi
callq 0x21d0
movq %rax, 0x10(%rbx)
cmpl $0x0, (%r15)
jle 0x569b
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x8(%r15), %rax
movl (%rax,%r13,4), %eax
cmpl %ebp, %eax
jne 0x5664
movq 0x10(%r15), %rax
movzbl (%rax,%r13), %edi
movq %r14, %rsi
callq 0x4bad
movq %rax, %r12
jmp 0x5682
movq 0x8(%rbx), %rcx
movslq (%rbx), %rdx
movl %eax, (%rcx,%rdx,4)
movq 0x10(%r15), %rax
movb (%rax,%r13), %al
movq 0x10(%rbx), %rcx
movslq (%rbx), %rdx
movb %al, (%rcx,%rdx)
incl (%rbx)
incq %r13
movslq (%r15), %rax
cmpq %rax, %r13
jl 0x5642
jmp 0x569e
movq %rbx, %r14
addq $0x8, %r14
xorl %r12d, %r12d
jmp 0x56bc
xorl %r12d, %r12d
cmpl $0x0, (%rbx)
jne 0x56c3
movq %rbx, %r14
addq $0x8, %r14
movq 0x8(%rbx), %rdi
callq 0x2030
movq 0x10(%rbx), %rdi
callq 0x2030
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
testq %r12, %r12
je 0x56e0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5221
movq %rax, %r14
movq %r12, %rdi
callq 0x484f
jmp 0x56eb
movq %rbx, %rdi
callq 0x4d1b
movq %rax, %r14
movq %rbx, %rdi
callq 0x484f
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq