// File: /workspace/github_c_makefile_star2_O1/cbouilla[P]AES-attacks-finder/Solver.c
// Function: OptimizeSolver
Solver OptimizeSolver(Solver B, SysEqLin E) 
{
	/*
	 *  Fonction censée mettre en forme la solver avant implémentation.
	 * 	Plusieurs objectifs :
	 * 		- ne doit pas être trop longue.
	 * 		- avoir un maximum d'unions avec des solvers de type 0 (ie 1 variable)
	 * 		- essayer de supprimer les variables en commun
	 */
	  
	if (B==NULL || B->type==0) return copySolver(B); // cas simple : rien à faire
	
	if (B->type==2) // cas union sequentielle, on met en forme les deux parties.
	{
		SysEqLin F=EsachantX(B->fils2->var,B->fils2->Nvar,E);
		Solver B1=OptimizeSolver(B->fils1,F);
		freeSysEq(F);
		Solver B2=OptimizeSolver(B->fils2,E);
		if (B1==NULL) return B2;
		Solver tmp=NewSolver();
		tmp->var=UnionListesTriees(B1->var,B1->Nvar,B2->var,B2->Nvar,&(tmp->Nvar));
		tmp->sortie=B->sortie;
		tmp->temps=max(B2->temps,max(B2->sortie,0)+B1->temps);
		tmp->memoire=max(B1->memoire,B2->memoire);
		tmp->type=2;
		tmp->fils1=B1;
		tmp->fils2=B2;		
		return tmp;
	}
	
	if (B->fils2->sortie<=0) // la solver 2 a moins d'une solution -> passage au sequentiel
	{
		SysEqLin F=EsachantX(B->fils2->var,B->fils2->Nvar,E);
		Solver B2=AjusteSolver(B->fils1,F); // On met à jour la solver car maintenant les variables de la solver 2 sont connues
		Solver B1=OptimizeSolver(B2,F);
		freeSolver(B2);
		freeSysEq(F);
		B2=OptimizeSolver(B->fils2,E);
		if (B1==NULL) return B2;
		Solver tmp=NewSolver();
		tmp->var=UnionListesTriees(B1->var,B1->Nvar,B2->var,B2->Nvar,&(tmp->Nvar));
		tmp->sortie=B->sortie;
		tmp->temps=max(B2->temps,B1->temps);
		tmp->memoire=max(B1->memoire,B2->memoire);
		tmp->type=2;
		tmp->fils1=B1;
		tmp->fils2=B2;
		return tmp;
	}
	
	if (B->fils1->sortie<=0) // pareil que ci-dessus
	{
		SysEqLin F=EsachantX(B->fils1->var,B->fils1->Nvar,E);
		Solver B2=AjusteSolver(B->fils2,F);
		Solver B1=OptimizeSolver(B2,F);
		freeSolver(B2);
		freeSysEq(F);
		B2=OptimizeSolver(B->fils1,E);
		if (B1==NULL) return B2;
		Solver tmp=NewSolver();
		tmp->var=UnionListesTriees(B1->var,B1->Nvar,B2->var,B2->Nvar,&(tmp->Nvar));
		tmp->sortie=B->sortie;
		tmp->temps=max(B2->temps,B1->temps);
		tmp->memoire=max(B1->memoire,B2->memoire);
		tmp->type=2;
		//tmp->parents=1;
		tmp->fils1=B1;
		tmp->fils2=B2;
		if (tmp->Nvar!=B->Nvar)
		{
			printf("Gros bug 3");
			getchar();
		}
		return tmp;
	}
	
	if (B->sortie==B->fils1->sortie + B->fils2->sortie) // les deux solvers sont indépendantes -> passage au séquentiel
	{
		/* Les deux temps possibles */
		int t1=max(max(B->fils1->sortie,0) + B->fils2->temps, B->fils1->temps);
		int t2=max(max(B->fils2->sortie,0) + B->fils1->temps, B->fils2->temps);
		if (min(t1,t2)<=B->temps)
		{
			Solver tmp=NewSolver();
			tmp->var=UnionListesTriees(B->fils1->var,B->fils1->Nvar,B->fils2->var,B->fils2->Nvar,&(tmp->Nvar));
			tmp->sortie=B->sortie;
			tmp->type=2;
			//tmp->parents=1;
			Solver B1,B2;
			/* On choisit la meilleur option */
			if (t1<t2 || (t1==t2 && B->fils1->Nvar>=B->fils2->Nvar))
			{
				tmp->temps=t1;
				SysEqLin F=EsachantX(B->fils1->var,B->fils1->Nvar,E);
				B2=AjusteSolver(B->fils2,F);
				B1=OptimizeSolver(B2,F);
				freeSolver(B2);
				freeSysEq(F);
				B2=OptimizeSolver(B->fils1,E);
			}
			else
			{
				tmp->temps=t2;
				SysEqLin F=EsachantX(B->fils2->var,B->fils2->Nvar,E);
				B2=AjusteSolver(B->fils1,F);
				B1=OptimizeSolver(B2,F);
				freeSolver(B2);
				freeSysEq(F);
				B2=OptimizeSolver(B->fils2,E);
			}
			tmp->memoire=max(B1->memoire,B2->memoire);
			tmp->fils1=B1;
			tmp->fils2=B2;
			if (tmp->Nvar!=B->Nvar)
			{
				printf("Gros bug 4");
				getchar();
			}
			return tmp;
		}
	}

	/* Cas idéal */
	if (B->fils2->Nvar==1) 
	{
		Solver B1=OptimizeSolver(B->fils1,E);
		Solver B2=UnionSolver(B1,B->fils2,E);
		freeSolver(B1);
		return B2;
	}
	if (B->fils1->Nvar==1)
	{
		Solver B1=OptimizeSolver(B->fils2,E);
		Solver B2=UnionSolver(B1,B->fils1,E);
		freeSolver(B1);
		return B2;
	}

	/* Partie d'amélioration */

	// On est donc dans le cas d'une union de type 1, chacune des solvers à au moins 2 variables
	// On garde le fils1 pour l'énumération et on va chercher à diviser fils2

	int N1;	
	int *X1=DifferenceListesTriees(B->fils2->var,B->fils2->Nvar,B->fils1->var,B->fils1->Nvar,&N1);
	Solver *L1=malloc((N1+1)*sizeof(Solver));
	int i;
	for (i = 0; i < N1; i++) L1[i]=BaseSolver(X1[i],E);
	
	if (B->fils1->Nvar>=B->fils2->Nvar && N1<B->fils2->Nvar)
	{
		L1[N1]=copySolver(B->fils1);
		int N2;
		Solver *L2=ExhaustiveSearch(L1,N1+1,B->temps,B->memoire,&N2,E);
		Solver tmp=NULL;
		for (i = 0; i < N2; i++)
		{
			if (B->Nvar==L2[i]->Nvar) tmp=L2[i];
			else freeSolver(L2[i]);
		}
		free(L2);
		if (tmp!=NULL)
		{
			for (i = 0; i <= N1; i++) freeSolver(L1[i]);
			free(L1);
			free(X1);
			Solver B3=OptimizeSolver(tmp,E);
			freeSolver(tmp);
			return B3;
		}
	}
	
	Solver B1 = PropagateSolver2(B->fils1,E,L1,N1);
	free(X1);
	for (i = 0; i < N1; i++) freeSolver(L1[i]);
	free(L1);
	Solver B2 = copySolver(B->fils2);


	while (B2->type==1 && ContenuListesTriees(B2->fils2->var,B2->fils2->Nvar,B1->var,B1->Nvar))
	{
		Solver B3 = copySolver(B2->fils1);
		freeSolver(B2);
		B2 = B3;
	}
	while (B2->type==1 && ContenuListesTriees(B2->fils1->var,B2->fils1->Nvar,B1->var,B1->Nvar))
	{
		Solver B3 = copySolver(B2->fils2);
		freeSolver(B2);
		B2 = B3;
	}
	
	/* Partie qui foire, la fonction peut boucler indéfiniment */ 
	if (B2->type==1)
	{
		Solver B3 = UnionSolver(B1,B2->fils1,E);
		if (B3->temps<=B->temps)
		{
			Solver B4 = UnionSolver(B3,B2->fils2,E);
			freeSolver(B3);
			freeSolver(B2);
			freeSolver(B1);
			B1 = OptimizeSolver(B4,E);
			freeSolver(B4);
			return B1;
		}
		freeSolver(B3);
		B3 = UnionSolver(B1,B2->fils2,E);
		if (B3->temps<=B->temps)
		{
			Solver B4 = UnionSolver(B3,B2->fils1,E);
			freeSolver(B3);
			freeSolver(B2);
			freeSolver(B1);
			B1 = OptimizeSolver(B4,E);
			freeSolver(B4);
			return B1;
		}
		freeSolver(B3);			
	}
	if (B2->type==2)
	{
		X1=DifferenceListesTriees(B2->var,B2->Nvar,B1->var,B1->Nvar,&N1);
		L1=malloc((N1+1)*sizeof(Solver));
		for (i = 0; i < N1; i++) L1[i]=BaseSolver(X1[i],E);
		L1[N1]=copySolver(B1);
		int N2;
		Solver *L2=ExhaustiveSearch(L1,N1+1,B->temps,B2->sortie-1,&N2,E);
		Solver tmp=NULL;
		for (i = 0; i < N2; i++)
		{
			if (B->Nvar==L2[i]->Nvar) tmp=L2[i];
			else freeSolver(L2[i]);
		}
		free(L2);
		for (i = 0; i <= N1; i++) freeSolver(L1[i]);
		free(L1);
		free(X1);
		if (tmp!=NULL)
		{
			freeSolver(B1);
			freeSolver(B2);
			Solver B3=OptimizeSolver(tmp,E);
			freeSolver(tmp);
			return B3;
		}
	}

	/* Rien n'a marché */
	
	Solver B3 = OptimizeSolver(B1,E);
	freeSolver(B1);
	B1 = OptimizeSolver(B2,E);
	freeSolver(B2);
	B2 = UnionSolver(B3,B1,E);
	freeSolver(B3);
	freeSolver(B1);
	return B2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
testq %rdi, %rdi
je 0x8807
movq %rsi, %rbx
movzbl 0x18(%r14), %eax
cmpl $0x2, %eax
je 0x880f
testl %eax, %eax
jne 0x8897
testq %r14, %r14
je 0x8807
incl 0x1c(%r14)
movq %r14, %r15
jmp 0x8a07
movq 0x28(%r14), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq %rbx, %rdx
callq 0xbed5
movq %rax, %r15
movq 0x20(%r14), %rdi
movq %rax, %rsi
callq 0x87d3
movq %rax, %r12
movq %r15, %rdi
callq 0xc453
movq 0x28(%r14), %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r15
testq %r12, %r12
je 0x8a07
callq 0x6fb4
movq %rax, %rbx
movq (%r12), %rdi
movl 0x8(%r12), %esi
movq (%r15), %rdx
movl 0x8(%r15), %ecx
leaq 0x8(%rax), %r8
callq 0x2544
movq %rax, (%rbx)
movl 0x14(%r14), %eax
movl %eax, 0x14(%rbx)
movl 0x14(%r15), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
addl 0xc(%r12), %ecx
movl 0xc(%r15), %eax
jmp 0x89df
movq 0x28(%r14), %rax
movl 0x14(%rax), %r13d
testl %r13d, %r13d
jle 0x8959
leaq 0x28(%r14), %rbp
leaq 0x20(%r14), %r8
movq 0x20(%r14), %rcx
movl 0x14(%rcx), %r12d
testl %r12d, %r12d
jle 0x8a19
leal (%r12,%r13), %edx
cmpl %edx, 0x14(%r14)
jne 0x8bc2
movl 0xc(%rax), %eax
addl %eax, %r12d
movl 0xc(%rcx), %ecx
cmpl %ecx, %r12d
cmovlel %ecx, %r12d
addl %ecx, %r13d
cmpl %eax, %r13d
cmovlel %eax, %r13d
cmpl %r13d, %r12d
movl %r13d, %eax
cmovll %r12d, %eax
movl 0xc(%r14), %ecx
cmpl %ecx, %eax
jg 0x8bba
movl %ecx, 0x20(%rsp)
movl %eax, 0x18(%rsp)
movq %r8, 0x8(%rsp)
callq 0x6fb4
movq %rax, %r15
movq 0x20(%r14), %rax
movq 0x28(%r14), %rcx
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%rcx), %rdx
movl 0x8(%rcx), %ecx
leaq 0x8(%r15), %r8
callq 0x2544
movq %rax, (%r15)
movl 0x14(%r14), %eax
movl %eax, 0x14(%r15)
movb $0x2, 0x18(%r15)
cmpl %r13d, %r12d
movq %rbp, 0x10(%rsp)
jge 0x8af1
movq 0x8(%rsp), %rsi
jmp 0x8b1a
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq %rbx, %rdx
callq 0xbed5
movq %rax, %r15
movq 0x20(%r14), %rdi
movq %rax, %rsi
callq 0x912d
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x87d3
movq %rax, %r12
movq %r13, %rdi
callq 0x7060
movq %r15, %rdi
callq 0xc453
movq 0x28(%r14), %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r15
testq %r12, %r12
je 0x8a07
callq 0x6fb4
movq %rax, %rbx
movq (%r12), %rdi
movl 0x8(%r12), %esi
movq (%r15), %rdx
movl 0x8(%r15), %ecx
leaq 0x8(%rax), %r8
callq 0x2544
movq %rax, (%rbx)
movl 0x14(%r14), %eax
movl %eax, 0x14(%rbx)
movl 0xc(%r15), %eax
movl 0xc(%r12), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0xc(%rbx)
movl 0x10(%r12), %eax
movl 0x10(%r15), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x10(%rbx)
movb $0x2, 0x18(%rbx)
movq %r12, 0x20(%rbx)
movq %r15, 0x28(%rbx)
movq %rbx, %r15
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rcx), %rdi
movl 0x8(%rcx), %esi
movq %rbx, %rdx
movq %rbp, %r12
movq %r8, %rbp
callq 0xbed5
movq %rax, %r15
movq (%r12), %rdi
movq %rax, %rsi
callq 0x912d
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
callq 0x87d3
movq %rax, %r12
movq %r13, %rdi
callq 0x7060
movq %r15, %rdi
callq 0xc453
movq (%rbp), %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %rbx
testq %r12, %r12
je 0x8a04
callq 0x6fb4
movq %rax, %r15
movq (%r12), %rdi
movl 0x8(%r12), %esi
movq (%rbx), %rdx
movl 0x8(%rbx), %ecx
leaq 0x8(%rax), %r8
callq 0x2544
movq %rax, (%r15)
movl 0x14(%r14), %eax
movl %eax, 0x14(%r15)
movl 0xc(%rbx), %eax
movl 0xc(%r12), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0xc(%r15)
movl 0x10(%r12), %eax
movl 0x10(%rbx), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, 0x10(%r15)
movb $0x2, 0x18(%r15)
movq %r12, 0x20(%r15)
movq %rbx, 0x28(%r15)
movl 0x8(%r15), %eax
cmpl 0x8(%r14), %eax
je 0x8a07
leaq 0x2081f(%rip), %rdi     # 0x292ff
xorl %eax, %eax
callq 0x2110
callq 0x2180
jmp 0x8a07
movq 0x8(%rsp), %rdx
jne 0x8b0f
movq (%rdx), %rax
movl 0x8(%rax), %eax
movq 0x10(%rsp), %rbp
movq (%rbp), %rcx
movq %rdx, %rsi
cmpl 0x8(%rcx), %eax
jge 0x8b1a
movl %r13d, %r12d
movq 0x10(%rsp), %rsi
movq %rdx, %rbp
movq %rsi, 0x30(%rsp)
movl %r12d, 0xc(%r15)
movq (%rsi), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq %rbx, %rdx
callq 0xbed5
movq %rax, %r12
movq (%rbp), %rdi
movq %rax, %rsi
callq 0x912d
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0x87d3
movq %rax, %rbp
movq %r13, %rdi
callq 0x7060
movq %r12, %rdi
callq 0xc453
movq 0x30(%rsp), %rax
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x87d3
movl 0x10(%rbp), %ecx
movl 0x10(%rax), %edx
cmpl %edx, %ecx
cmovgl %ecx, %edx
movl %edx, 0x10(%r15)
movq %rbp, 0x20(%r15)
movq %rax, 0x28(%r15)
movl 0x8(%r15), %eax
cmpl 0x8(%r14), %eax
je 0x8ba8
leaq 0x2076e(%rip), %rdi     # 0x2930a
xorl %eax, %eax
callq 0x2110
callq 0x2180
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %r8
movl 0x18(%rsp), %eax
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jle 0x8a07
movq (%rbp), %rdi
movl 0x8(%rdi), %esi
movq (%r8), %rax
cmpl $0x1, %esi
jne 0x8be8
movq %rax, %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r14
movq (%rbp), %rsi
movq %rax, %rdi
jmp 0x8c0b
movq %r8, 0x8(%rsp)
movl 0x8(%rax), %ecx
cmpl $0x1, %ecx
jne 0x8c26
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x7be3
movq %rax, %rbx
movq %r14, %rdi
callq 0x7060
movq %rbx, %rax
jmp 0x8a0a
movq (%rdi), %rdi
movq (%rax), %rdx
leaq 0x4(%rsp), %r12
movq %r12, %r8
callq 0x2847
movq %rax, 0x20(%rsp)
movslq (%r12), %r12
leaq 0x8(,%r12,8), %rdi
callq 0x21d0
movq %rax, %r13
testq %r12, %r12
movq %rbp, 0x10(%rsp)
jle 0x8c9a
movq %r15, 0x18(%rsp)
xorl %ebp, %ebp
movq %r13, %r15
movq %rbx, %r13
movq 0x20(%rsp), %rbx
movl (%rbx,%rbp,4), %edi
movq %r13, %rsi
callq 0x754c
movq %rax, (%r15,%rbp,8)
incq %rbp
movslq 0x4(%rsp), %r12
cmpq %r12, %rbp
jl 0x8c6e
movq 0x10(%rsp), %rbp
movq %r13, %rbx
movq %r15, %r13
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rsi
movq (%rsi), %rax
movq (%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpl %ecx, 0x8(%rax)
setl %dl
cmpl %ecx, %r12d
setge %cl
orb %dl, %cl
jne 0x8d26
testq %rax, %rax
je 0x8cc1
incl 0x1c(%rax)
movslq %r12d, %rcx
movq %rax, (%r13,%rcx,8)
incl %r12d
movl 0xc(%r14), %edx
movl 0x10(%r14), %ecx
leaq 0x2c(%rsp), %rbp
movq %r13, %rdi
movl %r12d, %esi
movq %rbp, %r8
movq %rbx, %r9
callq 0x15bbf
movq %rax, %r12
cmpl $0x0, (%rbp)
jle 0x8d30
xorl %ebp, %ebp
movq $0x0, 0x18(%rsp)
movl 0x8(%r14), %eax
movq (%r12,%rbp,8), %rdi
cmpl 0x8(%rdi), %eax
jne 0x8d12
movq %rdi, 0x18(%rsp)
jmp 0x8d17
callq 0x7060
incq %rbp
movslq 0x2c(%rsp), %rax
cmpq %rax, %rbp
jl 0x8cfe
jmp 0x8d39
movq 0x20(%rsp), %r12
jmp 0x8db5
movq $0x0, 0x18(%rsp)
movq %r12, %rdi
callq 0x2030
movq 0x18(%rsp), %r12
testq %r12, %r12
movq 0x10(%rsp), %rbp
je 0x8da2
cmpl $0x0, 0x4(%rsp)
js 0x8d75
movq $-0x1, %r15
movq 0x8(%r13,%r15,8), %rdi
callq 0x7060
movslq 0x4(%rsp), %rax
incq %r15
cmpq %rax, %r15
jl 0x8d5e
movq %r13, %rdi
callq 0x2030
movq 0x20(%rsp), %rdi
callq 0x2030
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r15
movq %r12, %rdi
callq 0x7060
testq %r12, %r12
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %r12
jne 0x8a07
movq (%rsi), %rdi
movl 0x4(%rsp), %ecx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x817d
movq %rax, 0x8(%rsp)
movq %r12, %rdi
callq 0x2030
cmpl $0x0, 0x4(%rsp)
jle 0x8df5
xorl %r12d, %r12d
movq (%r13,%r12,8), %rdi
callq 0x7060
incq %r12
movslq 0x4(%rsp), %rax
cmpq %rax, %r12
jl 0x8dde
movq %r13, %rdi
callq 0x2030
movq (%rbp), %r12
testq %r12, %r12
je 0x8e0b
incl 0x1c(%r12)
cmpb $0x1, 0x18(%r12)
jne 0x8e52
movq 0x28(%r12), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movl 0x8(%rax), %ecx
callq 0x2ce2
testl %eax, %eax
je 0x8e52
movq 0x20(%r12), %rbp
testq %rbp, %rbp
je 0x8e3f
incl 0x1c(%rbp)
movq %r12, %rdi
callq 0x7060
cmpb $0x1, 0x18(%rbp)
movq %rbp, %r12
je 0x8e13
jmp 0x8e55
movq %r12, %rbp
cmpb $0x1, 0x18(%rbp)
jne 0x8e9d
movq 0x8(%rsp), %r12
movq 0x20(%rbp), %rax
movq (%rax), %rdi
movl 0x8(%rax), %esi
movq (%r12), %rdx
movl 0x8(%r12), %ecx
callq 0x2ce2
testl %eax, %eax
je 0x8ea7
movq 0x28(%rbp), %r13
testq %r13, %r13
je 0x8e89
incl 0x1c(%r13)
movq %rbp, %rdi
callq 0x7060
cmpb $0x1, 0x18(%r13)
movq %r13, %rbp
je 0x8e60
jmp 0x8eaa
movq %rbp, %r13
movq 0x8(%rsp), %r12
jmp 0x8eaa
movq %rbp, %r13
cmpb $0x1, 0x18(%r13)
jne 0x8f5d
movq 0x20(%r13), %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x7be3
movq %rax, %rbp
movl 0xc(%rax), %eax
cmpl 0xc(%r14), %eax
jle 0x8f01
movq %rbp, %rdi
callq 0x7060
movq 0x28(%r13), %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x7be3
movq %rax, %rbp
movl 0xc(%rax), %eax
movb $0x1, %r12b
cmpl 0xc(%r14), %eax
jg 0x8f47
leaq 0x20(%r13), %rax
movq 0x8(%rsp), %r12
jmp 0x8f05
leaq 0x28(%r13), %rax
movq (%rax), %rsi
movq %rbp, %rdi
movq %rbx, %rdx
callq 0x7be3
movq %rax, %r15
movq %rbp, %rdi
callq 0x7060
movq %r13, %rdi
callq 0x7060
movq %r12, %rdi
callq 0x7060
movq %r15, %rdi
movq %rbx, %rsi
callq 0x87d3
xorl %r12d, %r12d
movq %r15, %rbp
movq %rax, 0x8(%rsp)
movq %rax, %r15
movq %rbp, %rdi
callq 0x7060
testb %r12b, %r12b
movq 0x8(%rsp), %r12
je 0x8a07
cmpb $0x2, 0x18(%r13)
jne 0x90db
movq (%r13), %rdi
movl 0x8(%r13), %esi
movq (%r12), %rdx
movq %r12, 0x8(%rsp)
movl 0x8(%r12), %ecx
leaq 0x4(%rsp), %r12
movq %r12, %r8
callq 0x2847
movq %rax, 0x20(%rsp)
movslq (%r12), %r12
leaq 0x8(,%r12,8), %rdi
callq 0x21d0
testq %r12, %r12
movq %rax, 0x18(%rsp)
jle 0x8fe6
movq %r13, 0x10(%rsp)
xorl %ebp, %ebp
movq 0x20(%rsp), %r13
movl (%r13,%rbp,4), %edi
movq %rbx, %rsi
callq 0x754c
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
movslq 0x4(%rsp), %r12
cmpq %r12, %rbp
jl 0x8fb7
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rdi
jmp 0x8fe9
movq %rax, %rdi
movq 0x8(%rsp), %rax
incl 0x1c(%rax)
movslq %r12d, %rsi
movq %rax, (%rdi,%rsi,8)
incl %esi
movl 0xc(%r14), %edx
movl 0x14(%r13), %ecx
decl %ecx
leaq 0x28(%rsp), %rbp
movq %rbp, %r8
movq %rbx, %r9
callq 0x15bbf
movq %rax, %r12
cmpl $0x0, (%rbp)
jle 0x9050
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
movl 0x8(%r14), %eax
movq (%r12,%rbp,8), %rdi
cmpl 0x8(%rdi), %eax
jne 0x903c
movq %rdi, 0x10(%rsp)
jmp 0x9041
callq 0x7060
incq %rbp
movslq 0x28(%rsp), %rax
cmpq %rax, %rbp
jl 0x9028
jmp 0x9059
movq $0x0, 0x10(%rsp)
movq %r12, %rdi
callq 0x2030
cmpl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %r12
js 0x908b
movq $-0x1, %r14
movq 0x8(%r12,%r14,8), %rdi
callq 0x7060
movslq 0x4(%rsp), %rax
incq %r14
cmpq %rax, %r14
jl 0x9074
movq %r12, %rdi
callq 0x2030
movq 0x20(%rsp), %rdi
callq 0x2030
movq 0x10(%rsp), %r14
testq %r14, %r14
movq 0x8(%rsp), %r12
je 0x90d2
movq %r12, %rdi
callq 0x7060
movq %r13, %rdi
callq 0x7060
movq %r14, %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r15
movq %r14, %rdi
callq 0x7060
testq %r14, %r14
jne 0x8a07
movq %r12, %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r14
movq %r12, %rdi
callq 0x7060
movq %r13, %rdi
movq %rbx, %rsi
callq 0x87d3
movq %rax, %r12
movq %r13, %rdi
callq 0x7060
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x7be3
movq %rax, %r15
movq %r14, %rdi
callq 0x7060
movq %r12, %rdi
callq 0x7060
jmp 0x8a07