// File: /workspace/github_cpp_makefile_star2_O2/dcarrey[P]hgt-detection/./utils_tree.cpp
// Function: lectureNewick(char const*, long*, double*, char**, int*)
int lectureNewick(const char * newick, long int * ARETE, double * LONGUEUR, char ** lesNoms, int *kt)
{
	int n;                                     
	int cpt_x;
	// Ce sous programme permet de lire un arbre au format newick et de le transcrire dans
	// des vecteurs arete-longueur commencant � 1
	// ATTENTION: les noms commencent � 0
	// 7 octobre 2004
	// Elmaestro

	// TODO: Add your command handler code here
	int i,j,j1,k, a, a1, a2,a3, VertexNumber,numero;
	char symbol, *string, *string1, *string2, *string4;
	int taxaPos; // le nombre de taxas recup�r�
	int aretePos; // le nombre d'aretes recup�r�
	char symbolOld =' ';
	int zz, xx,jj,ii;
	double longueur;
	char * tempString;
	int cpt=0;
	//char *string4 = (char*) malloc(100000 * sizeof(char));
	string4 = (char*)malloc((100000) * sizeof(char));
	//char *string4 = (char*) malloc(100000);
	//char *string4 = new char[10000];

	int temoin=0;
	int cpt_parenthese=0;
	//long int *ARETE;
	//double *LONGUEUR; 	

	//Correctness of the Newick format verification
	i=0;
	n = 0;

	do
	{
		symbol = newick[cpt++];
		if (symbol==':') i++;
		if(symbol == ':' && symbolOld !=')' && temoin != 1) n++;
		if(symbol >= '0' && symbol <= '9' && symbolOld==')') temoin=1;
		if(symbol==':' && temoin==1) temoin=0;
		symbolOld = symbol;
	}  while(symbol != '\0');

	cpt=0;

	if(i<=2*n-3)(*kt)=i;
	else (*kt)=2*n-3;

	if (i == 0) { printf("Incorrect Newick file format. Edge lengths must be indicated after a ':' characters."); exit(FAIL);}

	if ((i>2*n-3) || (i<n)){
		//printf("Unable to read your input data, please check it and try again...");
		//exit(-1);
	}

	j=0;
	do{ 
	   symbol=newick[cpt++]; 
	   if (symbol=='(') j++; 
	}while(symbol != '\0');
	
	cpt=0;	
	j1=0;
	
	do{
		symbol=newick[cpt++];
		if (symbol==')') j1++; 
	}while(symbol != '\0');  
	
	cpt=0;

	// verification des arit�s de l'arbre
	if (j1!=j) { printf("Incorrect Newick file format. Number of right parentheses must be equal to number of left parentheses."); exit(FAIL);}
	//else if (j!=n-2) { printf("Incorrect Newick file format. Only trees with vertices of degree 1 and 3 are allowed by T-REX."); fclose (data); exit(FAIL);}

	k=0;

	do{ 
		symbol=newick[cpt++];
		if (symbol==',') k++; 
	}while(symbol != '\0');   
	
	cpt=0;
	//if (k!=(n-1)) { printf("Incorrect Newick file format. Number of objects must be equal to number of commas plus 1."); fclose (data); exit(FAIL);}

	a=0;

	do{ 
		symbol=newick[cpt++];
		if (symbol==';') a++; 
	}while(symbol != '\0');    
	cpt=0;

	if (a==0) { printf("Incorrect Newick file format. Newick string must be followed by a ';' character."); exit(FAIL);}
	else if (a>1) { printf("Incorrect Newick file format. Newick string must contain (in the end) only one ';' character."); exit(FAIL);}

	a=0;
	do{
		symbol=newick[cpt++];a++;
	}while(symbol == ' '); 
	
	cpt=0;

	if (symbol!='(') { printf("Incorrect Newick file format. Newick string must begin with a '(' character."); exit(FAIL);}  

	a=0;
	
	do{ symbol=newick[cpt++];
		if (symbol=='%') a++; 
	}while(symbol != '\0');

	cpt=0;

	if (a>0) { printf("Incorrect Newick file format. Newick string cannot contain \'%%\' character."); exit(FAIL);}

	do
	{
		symbol=newick[cpt++];
		if ((symbol=='(')||(symbol==','))		
		{ 
			symbol=newick[cpt++]; a=0;
			if ((symbol!='(')&&(symbol!=',')&&(symbol!=';')&&(symbol!=':'))		   
			{ 
				cpt--; 
				do{
					symbol=newick[cpt++];a++;
				}while ((symbol!=':')&&(symbol!='\0'));  
			}
			else cpt--;
			if (a>50) { printf("Incorrect Newick file format. Names of objects must not exceed 50 characters.");  exit(FAIL);}   
		}	
	}while(symbol != '\0');
	cpt=0;

	string = (char*)malloc((100000) * sizeof(char));
	string2 = (char*)malloc((100000) * sizeof(char));
	//string3 = (char*)malloc((1000*n) * sizeof(char));
	string1 = (char*)malloc((100000) * sizeof(char));

	if ((string == NULL)||(string1 == NULL)||(string2 == NULL)/*||(string3 == NULL)*/)
	{ printf("Input data are too large or not a correct Newick file chosen"); exit(FAIL);}

	a=0;

	do{		
		symbol=newick[cpt++];
		if ((symbol!=' ')&&(symbol!='\n')&&(symbol!='\t')) { string[a++]=symbol; } 
	}while(symbol !='\0'); 

	int boot_value;
	int temoin3 = 0;
	k=0; VertexNumber=n;
	//a1 = 0;
	//a2 = 0;
	taxaPos =1;    // nous allons commencer � mettre les taxas � la position 1
	aretePos = 1;
	boot_value=0;
	
	while (string[0] == '(')   // traiter toute la chaine
	{
		a1 = 0;
		a2 = 0;
		while( string[a2] != ')')  // traiter la paire () la plus profonde
		{
			if(string[a2] == '(') a1 = a2;  // retrouver ;a parenth�se ouvrante
			a2++;
		}
		

		// a   => contient la longueur de la chaine
		// a1  => contient le debut d'un noeud � traiter
		// a2  => contient la fin d'un noeud � traiter
		// a3  => d�limite le noeud et sa longueur

		zz = a1+1;
		VertexNumber++;  // augmenter le nombre de noeuds
		boot_value=0;
		for ( ii = a1+1; ii <= a2; ii++)
		{// decortiquer cette chaine

			if (string[ii] == ':')
			{
				xx = 0;
				a3 = ii+1;

				if( string[zz] == '%')
				{ // cela veut dire que c'est un  noeud que l'on traite

					for ( jj = zz+1; jj < ii; jj++)
					{
						if(string[jj] == '|')
							break;
						string1[xx++] = string[jj]; 
					}
					temoin3=1;
					string1[xx++] = '\0';
					numero = atoi(string1);
					
					if(string[jj] == '|' ){
						boot_value=1;
						cpt_x=0;
						jj++;
						while(string[jj] != ':')
							string4[cpt_x++] = string[jj++];
						string4[cpt_x] = '\0';
					}
					
				}
				else
				{
					// on recup�re le nom du taxa

					for(jj = zz; jj < ii; jj++)
					{
						lesNoms[taxaPos-1][xx++] = string[jj];
					}
					numero = taxaPos;
					lesNoms[taxaPos-1][xx] = '\0';  // mettre la fin de chaine
					taxaPos++;  // augmenter le nombre de taxas pris
				}

			}
			else if(string[ii] == ','  || string[ii] == ')')
			{
				xx = 0;
				zz = ii +1;   // faire pointer sur le prochain noeud
				for ( jj = a3; jj < ii; jj++)
				{
					string1[xx++] = string[jj]; 
				}
				string1[xx++] = '\0';
				longueur = atof(string1);
				ARETE[aretePos++] = VertexNumber;
				ARETE[aretePos++] = numero;
				LONGUEUR[(aretePos-1)/ 2] = longueur;

				if(boot_value == 1){
					//printf("\n%d--%d : %lf (%s)",VertexNumber,numero,longueur,string4);
					boot_value=0;
				}
			}

		}

		// fin for pour traiter noeud
		//transcrire la nouvelle chaine
		xx = 0;
		for ( jj = 0; jj < (int)a1; jj++)
		{string2[xx++] = string[jj];}

		// ecrire le vertex
		//	char buffer[50];
		itoa_(VertexNumber,string1,10);
		string2[xx++] = '%';   // indiquer que c'est un noeud
		for( jj = 0; jj < (int) strlen(string1); jj++)
		{string2[xx++] = string1[jj];}

		int temoin=0;
		
		// transcrire la fin
		for( jj = a2+1; jj <= a; jj++)  // il faut voir si c'est  <= a ou c < a
		{
			if(string[jj] != ':' && temoin==0){
				string2[xx++] = '|';	
			}
			temoin = 1;
			//if(temoin==1)
				string2[xx++] = string[jj];
			
		}

		// remplacer string par string2 en remplacant les pointeurs
		
		tempString = string;
		string = string2;
		string2 = tempString;
		tempString = 0;
		a = xx;  // mettre la longueur � jour 

	} // fin du while pour traiter toute la string

	int root_existance = -1;
	for( jj=n;jj>0;jj--){
		strcpy(lesNoms[jj],lesNoms[jj-1]);
		if (strcmp(lesNoms[jj],"Root") == 0)
			root_existance = jj;
	}
	printf("\nRoot_existance = %d",root_existance);
	for( jj=1;jj<=n;jj++){
		printf("\n(%d) - %s",jj,lesNoms[jj]); 
	}
	
	
	ARETE[aretePos++] = 0;
	ARETE[aretePos++] = 0;


	for(i=1;i<=2*n-3;i++){
		LONGUEUR[i-1] = LONGUEUR[i];
		if(LONGUEUR[i-1] < 5*epsilon){
			LONGUEUR[i-1] = 5*epsilon;
		}
	}
	for(i=1;i<=2*(2*n-3);i++){
		ARETE[i-1] = ARETE[i];
	}
	
	//== recherche des branches connexes a celle de la racine;
	if( root_existance > 0){
		int noeud_interne = -1;
		for(i=1;i<=2*n-3;i++){
			if(ARETE[2*i-1] == root_existance)
				noeud_interne = ARETE[2*i-2];
			if(ARETE[2*i-2] == root_existance)
				noeud_interne = ARETE[2*i-1];
		}
		printf("\n[%d,%d]",noeud_interne,root_existance);
		for(i=1;i<=2*n-3;i++){
			if((ARETE[2*i-1] != root_existance) && (noeud_interne == ARETE[2*i-2])){
				LONGUEUR[i-1] = 50;
				printf("\n[%d,%ld]",noeud_interne,ARETE[2*i-1]);
			}
			if((ARETE[2*i-2] != root_existance) && (noeud_interne == ARETE[2*i-1])){
				LONGUEUR[i-1] = 50;
				printf("\n[%d,%ld]",noeud_interne,ARETE[2*i-2]);
			}
		}
		
		
	}
	
	
	//=== on teste si il y a un noeud de degre 2 et un noeud de degre 1

	printf("\n");
	for(i=1;i<=2*n-3;i++){
		printf("\n%ld-%ld --> %lf",ARETE[2*i-1],ARETE[2*i-2],LONGUEUR[i-1]);
	}
    printf("\n");
  
	int * tableau = (int*)malloc((2*n)*sizeof(int));
	int deg2=-1,deg1=-1;
	for(i=1;i<2*n;i++)
		tableau[i-1] = 0;
	for(i=1;i<=2*n-3;i++){
		tableau[ARETE[2*i-1]]++;
		tableau[ARETE[2*i-2]]++;
	}
//	printf("\n");
	i=n+1;
	while(tableau[i] > 0){
		//printf("\n%d-->%d",i,tableau[i]);
		if(tableau[i] == 2) deg2 = i;
		if(tableau[i] == 1) deg1 = i;
		i++;
	}
	//printf("\ndeg2=%d , deg1=%d",deg2,deg1);
	int pos_racine=-1;
	
	for(i=1;i<=2*n-3;i++){
		if(ARETE[2*i-1] == deg1){ ARETE[2*i-1] = deg2; pos_racine=i; break;} 
		if(ARETE[2*i-2] == deg1){ ARETE[2*i-2] = deg2; pos_racine=i; break;} 
	}
    if(pos_racine != -1){
        LONGUEUR[pos_racine-1] = 100;
    }
	/*printf("\n");
	for(i=1;i<=2*n-3;i++){
		printf("\n%d-%d --> %lf",ARETE[2*i-1],ARETE[2*i-2],LONGUEUR[i-1]);
	}
  printf("\n");
*/

	free(string);
	free(string1);
	free(string2);
	//free(string3);

	(*kt) = 2*n-3 - (*kt);
    
    
	return pos_racine;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, -0x80(%rbp)
movq %rdx, -0x48(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, %rbx
xorl %r11d, %r11d
movb $0x20, %cl
pushq $0x1
popq %r12
movq %rdi, %rax
xorl %edi, %edi
xorl %r15d, %r15d
movl %edi, %esi
movl %r15d, %r14d
movl %r11d, %edx
movl %ecx, %r10d
movb (%rax), %cl
leal -0x30(%rcx), %r9d
cmpb $0xa, %r9b
cmovbl %r12d, %esi
cmpb $0x29, %r10b
setne %r9b
cmovnel %edi, %esi
movl $0x0, %r11d
cmpl $0x1, %esi
je 0x4aff
movl %esi, %r11d
xorl %r10d, %r10d
cmpb $0x3a, %cl
sete %r10b
cmovel %r11d, %esi
leal (%rdx,%r10), %r11d
cmpl $0x1, %edi
setne %dil
andb %dil, %r9b
andb %r9b, %r10b
movzbl %r10b, %r15d
addl %r14d, %r15d
incq %rax
movl %esi, %edi
testb %cl, %cl
jne 0x4acf
leal -0x3(,%r15,2), %ecx
cmpl %ecx, %edx
movq %rcx, %rax
movq %rcx, -0x78(%rbp)
cmovll %edx, %eax
movl %eax, (%r8)
testl %edx, %edx
je 0x52c3
leal (%r15,%r15), %r10d
xorl %eax, %eax
movq %rbx, %rcx
movb (%rcx), %dl
xorl %esi, %esi
cmpb $0x28, %dl
sete %sil
addl %esi, %eax
incq %rcx
testb %dl, %dl
jne 0x4b56
xorl %esi, %esi
movq %rbx, %rcx
movl %esi, %edx
movb (%rcx), %dil
xorl %esi, %esi
cmpb $0x29, %dil
sete %sil
addl %edx, %esi
incq %rcx
testb %dil, %dil
jne 0x4b6f
cmpl %eax, %edx
jne 0x52cc
pushq $-0x1
popq %rax
xorl %esi, %esi
movq %rbx, %rdx
movl %esi, %ecx
movb (%rdx), %dil
xorl %esi, %esi
cmpb $0x3b, %dil
sete %sil
addl %ecx, %esi
incq %rdx
testb %dil, %dil
jne 0x4b98
cmpl $0x1, %ecx
jne 0x52b6
movq %rbx, %rcx
movzbl (%rcx), %edx
incq %rcx
cmpl $0x20, %edx
je 0x4bbd
cmpl $0x28, %edx
jne 0x52a0
xorl %edx, %edx
movq %rbx, %rcx
movl %edx, %esi
movb (%rcx), %dil
xorl %edx, %edx
cmpb $0x25, %dil
sete %dl
addl %esi, %edx
incq %rcx
testb %dil, %dil
jne 0x4bd6
testl %esi, %esi
jne 0x52de
xorl %ecx, %ecx
movabsq $0xc00110000000000, %rdx # imm = 0xC00110000000000
movslq %ecx, %rsi
incl %ecx
movb (%rbx,%rsi), %sil
movl %esi, %edi
andb $-0x5, %dil
cmpb $0x28, %dil
jne 0x4c2a
movslq %ecx, %rdi
movzbl (%rbx,%rdi), %esi
cmpq $0x3b, %rsi
ja 0x4c31
btq %rsi, %rdx
jae 0x4c31
testb %sil, %sil
jne 0x4c02
jmp 0x4c5d
addq %rbx, %rdi
movl %eax, %r9d
movzbl (%rdi), %esi
incl %ecx
incl %r9d
cmpl $0x3a, %esi
je 0x4c4b
incq %rdi
testl %esi, %esi
jne 0x4c37
cmpl $0x32, %r9d
jb 0x4c2a
leaq 0xfa14(%rip), %rdi      # 0x1466c
jmp 0x52a7
movl %r12d, -0x3c(%rbp)
movq %r15, -0xa0(%rbp)
movl %r10d, -0x84(%rbp)
movq %r8, -0xa8(%rbp)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movq %rax, %r13
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
movq %rax, %r12
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1130
testq %r12, %r12
je 0x52e7
testq %r13, %r13
je 0x52e7
movq %rax, %r10
testq %rax, %rax
je 0x52e7
xorl %esi, %esi
movabsq $0x100000600, %rax      # imm = 0x100000600
movzbl (%rbx), %ecx
cmpq $0x20, %rcx
ja 0x4cd3
btq %rcx, %rax
jb 0x4cdd
movslq %esi, %rdx
incl %esi
movb %cl, (%r13,%rdx)
incq %rbx
testb %cl, %cl
jne 0x4cc4
movl %esi, -0x54(%rbp)
movl %r14d, %r15d
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq %r15, -0x30(%rbp)
pushq $0x1
popq %rax
movl %eax, -0x40(%rbp)
movq %r10, -0x68(%rbp)
movq %r15, -0xb0(%rbp)
cmpb $0x28, (%r13)
movq %r13, -0x70(%rbp)
movq %r12, -0x98(%rbp)
jne 0x4f9e
movq %r13, %r11
movb $0x28, %al
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r15d, %r15d
movl -0x88(%rbp), %esi
cmpb $0x28, %al
je 0x4d43
movzbl %al, %eax
cmpl $0x29, %eax
jne 0x4d46
jmp 0x4d55
movl %r14d, %r15d
movb 0x1(%r11,%r14), %al
incq %r14
addq %rcx, %r13
incl %ebx
jmp 0x4d35
leal 0x1(%r15), %edx
incq -0x30(%rbp)
movslq %edx, %r12
sarq $0x20, %r13
movl -0x8c(%rbp), %ecx
movq %rbx, -0xb8(%rbp)
movq %r15, -0x38(%rbp)
movl %esi, -0x88(%rbp)
movslq %esi, %r15
movl %ecx, -0x8c(%rbp)
movslq %ecx, %rdi
leaq (%r11,%r15), %rbx
incq %r12
leaq -0x1(%r12), %rax
cmpq %r13, %rax
jg 0x4ebd
movzbl -0x1(%r11,%r12), %ecx
cmpl $0x29, %ecx
je 0x4db3
cmpl $0x2c, %ecx
je 0x4db3
cmpl $0x3a, %ecx
jne 0x4d8b
jmp 0x4e21
xorl %ecx, %ecx
leaq (%r15,%rcx), %rdx
cmpq %rax, %rdx
jge 0x4dca
movb (%rbx,%rcx), %dl
movb %dl, (%r10,%rcx)
incq %rcx
jmp 0x4db5
movl %ecx, %eax
movb $0x0, (%r10,%rax)
movq %rdi, -0x60(%rbp)
movq %r10, %rdi
callq 0x1110
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %r11
movq -0x68(%rbp), %r10
movl -0x40(%rbp), %eax
movslq %eax, %rsi
incl %eax
movq -0x50(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq %rcx, (%rdx,%rsi,8)
leal 0x2(%rsi), %ecx
movq %rdi, 0x8(%rdx,%rsi,8)
cltd
pushq $0x2
popq %rsi
idivl %esi
cltq
movq -0x48(%rbp), %rdx
movsd %xmm0, (%rdx,%rax,8)
movl %ecx, -0x40(%rbp)
movl %r12d, %edx
jmp 0x4d8b
movl %edx, -0x60(%rbp)
movslq %edx, %rcx
cmpb $0x25, (%r11,%rcx)
jne 0x4e72
incq %rcx
xorl %edx, %edx
cmpq %rax, %rcx
jge 0x4e4e
movb (%r11,%rcx), %sil
cmpb $0x7c, %sil
je 0x4e4e
movb %sil, (%r10,%rdx)
incq %rdx
incq %rcx
jmp 0x4e33
movl %edx, %eax
movb $0x0, (%r10,%rax)
movq %r10, %rdi
callq 0x1190
movq -0x70(%rbp), %r11
movq -0x68(%rbp), %r10
movl %eax, %ecx
movl %r12d, %esi
movl -0x60(%rbp), %edx
jmp 0x4d75
movslq -0x3c(%rbp), %rdx
leaq (%r11,%rcx), %rdi
xorl %esi, %esi
leaq (%rcx,%rsi), %r8
cmpq %rax, %r8
jge 0x4e9b
movb (%rdi,%rsi), %r8b
movq -0x80(%rbp), %r9
movq -0x8(%r9,%rdx,8), %r9
movb %r8b, (%r9,%rsi)
incq %rsi
jmp 0x4e7c
movq -0x80(%rbp), %rax
movq -0x8(%rax,%rdx,8), %rax
movl %esi, %ecx
movb $0x0, (%rax,%rcx)
incl %edx
movl %r12d, %esi
movl -0x3c(%rbp), %ecx
movl %edx, -0x3c(%rbp)
movl -0x60(%rbp), %edx
jmp 0x4d75
movq -0x38(%rbp), %rbx
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
xorl %eax, %eax
movq -0x98(%rbp), %r12
cmpq %rax, %rbx
je 0x4ee6
movb (%r11,%rax), %cl
movb %cl, (%r12,%rax)
incq %rax
jmp 0x4ed4
movq -0x30(%rbp), %rdi
movq %r10, %rsi
pushq $0xa
popq %rdx
callq 0x49f4
movq -0x68(%rbp), %rdi
movq %rbx, -0x38(%rbp)
leaq (%r12,%rbx), %r15
incq %r15
movb $0x25, -0x1(%r15)
xorl %ebx, %ebx
movq %rdi, %r13
callq 0x1050
cltq
cmpq %rax, %rbx
jge 0x4f2b
movb (%r13,%rbx), %al
movb %al, (%r15,%rbx)
incq %rbx
movq %r13, %rdi
jmp 0x4f0b
movl -0x54(%rbp), %eax
movq -0xb8(%rbp), %r8
cmpl %r8d, %eax
cmovgl %eax, %r8d
movq -0x38(%rbp), %rax
leal 0x1(%rax,%rbx), %edi
movb $0x1, %al
movq %r13, %r10
movq -0x70(%rbp), %rsi
movq -0xb0(%rbp), %r15
cmpq %r14, %r8
je 0x4f86
movb 0x1(%rsi,%r14), %cl
cmpb $0x3a, %cl
sete %dl
notb %al
orb %dl, %al
testb $0x1, %al
jne 0x4f76
movslq %edi, %rax
incl %edi
movb $0x7c, (%r12,%rax)
movslq %edi, %rax
incl %edi
movb %cl, (%r12,%rax)
incq %r14
xorl %eax, %eax
jmp 0x4f54
movl %edi, -0x54(%rbp)
movq %r12, %r13
movq %rsi, %r12
movabsq $0x100000000, %rcx      # imm = 0x100000000
jmp 0x4d09
pushq $-0x1
popq %r13
movq -0x50(%rbp), %rbx
movq -0x80(%rbp), %r14
testl %r15d, %r15d
jle 0x4fd8
movq -0x8(%r14,%r15,8), %rsi
movq (%r14,%r15,8), %rdi
callq 0x1070
movq (%r14,%r15,8), %rdi
leaq 0xf72f(%rip), %rsi      # 0x146f7
callq 0x1160
testl %eax, %eax
cmovel %r15d, %r13d
decq %r15
jmp 0x4faa
leaq 0xf71d(%rip), %rdi      # 0x146fc
movl %r13d, -0x30(%rbp)
movl %r13d, %esi
xorl %eax, %eax
callq 0x1030
movl -0xa0(%rbp), %r13d
pushq $0x1
popq %r15
cmpq %r13, %r15
ja 0x5017
movq (%r14,%r15,8), %rdx
leaq 0xf709(%rip), %rdi      # 0x14711
movl %r15d, %esi
xorl %eax, %eax
callq 0x1030
incq %r15
jmp 0x4ff8
movslq -0x40(%rbp), %rax
movslq -0x78(%rbp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rbx,%rax,8)
pushq $0x1
popq %rax
movsd 0xf00f(%rip), %xmm0     # 0x14040
movq -0x48(%rbp), %rcx
cmpq %rdi, %rax
jg 0x504e
movapd %xmm0, %xmm1
maxsd (%rcx,%rax,8), %xmm1
movsd %xmm1, -0x8(%rcx,%rax,8)
incq %rax
jmp 0x5035
movq -0x78(%rbp), %rax
addl %eax, %eax
cltq
pushq $0x1
popq %rcx
cmpq %rax, %rcx
jg 0x506c
movq (%rbx,%rcx,8), %rdx
movq %rdx, -0x8(%rbx,%rcx,8)
incq %rcx
jmp 0x5059
movl -0x30(%rbp), %eax
testl %eax, %eax
movq %rdi, -0x38(%rbp)
jle 0x5155
movl %eax, %r12d
movq -0x50(%rbp), %r14
leaq 0x8(%r14), %rax
pushq $-0x1
popq %rbx
pushq $0x1
popq %rcx
cmpq %rdi, %rcx
jg 0x50af
movq -0x8(%rax), %rdx
movq (%rax), %rsi
cmpq %r12, %rsi
cmovel %edx, %ebx
cmpq %r12, %rdx
cmovnel %ebx, %esi
incq %rcx
addq $0x10, %rax
movl %esi, %ebx
jmp 0x508c
leaq 0xf666(%rip), %rdi      # 0x1471c
movl %ebx, %esi
movl -0x30(%rbp), %edx
xorl %eax, %eax
callq 0x1030
movq -0x38(%rbp), %rax
movslq %ebx, %rcx
leaq 0x8(%r14), %r15
pushq $0x1
popq %r14
movq %rcx, -0x30(%rbp)
cmpq %rax, %r14
jg 0x5155
movq (%r15), %rdx
cmpq %r12, %rdx
je 0x5113
cmpq %rcx, -0x8(%r15)
jne 0x5113
movq -0x48(%rbp), %rax
movabsq $0x4049000000000000, %rcx # imm = 0x4049000000000000
movq %rcx, -0x8(%rax,%r14,8)
leaq 0xf623(%rip), %rdi      # 0x14725
movl %ebx, %esi
xorl %eax, %eax
callq 0x1030
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq -0x8(%r15), %rdx
cmpq %r12, %rdx
je 0x514c
cmpq %rcx, (%r15)
jne 0x514c
movq -0x48(%rbp), %rax
movabsq $0x4049000000000000, %rcx # imm = 0x4049000000000000
movq %rcx, -0x8(%rax,%r14,8)
leaq 0xf5ea(%rip), %rdi      # 0x14725
movl %ebx, %esi
xorl %eax, %eax
callq 0x1030
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
incq %r14
addq $0x10, %r15
jmp 0x50d5
pushq $0xa
popq %rdi
callq 0x1150
movq -0x50(%rbp), %rax
leaq 0x8(%rax), %r14
pushq $0x1
popq %r15
leaq 0xf5bf(%rip), %rbx      # 0x1472f
movq -0x98(%rbp), %r12
cmpq -0x38(%rbp), %r15
jg 0x51a2
movq -0x8(%r14), %rdx
movq (%r14), %rsi
movq -0x48(%rbp), %rax
movsd -0x8(%rax,%r15,8), %xmm0
movq %rbx, %rdi
movb $0x1, %al
callq 0x1030
incq %r15
addq $0x10, %r14
jmp 0x5177
pushq $0xa
popq %rdi
callq 0x1150
movl -0x84(%rbp), %ebx
leaq (,%rbx,4), %rdi
callq 0x1130
pushq $0x1
popq %rcx
movq -0x50(%rbp), %r8
movq -0x70(%rbp), %rdi
cmpq %rbx, %rcx
jae 0x51d7
andl $0x0, -0x4(%rax,%rcx,4)
incq %rcx
jmp 0x51c8
leaq 0x8(%r8), %rcx
pushq $0x1
popq %rdx
movq -0x38(%rbp), %r10
cmpq %r10, %rdx
jg 0x51fd
movq (%rcx), %rsi
incl (%rax,%rsi,4)
movq -0x8(%rcx), %rsi
incl (%rax,%rsi,4)
incq %rdx
addq $0x10, %rcx
jmp 0x51e2
pushq $-0x1
popq %rcx
movl %ecx, %edx
movl 0x4(%rax,%r13,4), %esi
testl %esi, %esi
jle 0x521e
incq %r13
cmpl $0x2, %esi
cmovel %r13d, %ecx
cmpl $0x1, %esi
cmovel %r13d, %edx
jmp 0x5202
movslq %edx, %rsi
pushq $0x1
popq %rax
pushq $-0x1
popq %rbx
pushq $-0x8
popq %rdx
pushq $-0x10
popq %r9
cmpq %r10, %rax
jg 0x5267
cmpq %rsi, 0x8(%r8)
je 0x524a
cmpq %rsi, (%r8)
je 0x5247
incq %rax
addq $0x10, %r8
jmp 0x522e
movq %r9, %rdx
movslq %ecx, %rcx
movq %rcx, 0x10(%rdx,%r8)
movabsq $0x4059000000000000, %rcx # imm = 0x4059000000000000
movq -0x48(%rbp), %rdx
movq %rcx, -0x8(%rdx,%rax,8)
movl %eax, %ebx
callq 0x10f0
movq -0x68(%rbp), %rdi
callq 0x10f0
movq %r12, %rdi
callq 0x10f0
movq -0xa8(%rbp), %rax
movq -0x78(%rbp), %rcx
subl (%rax), %ecx
movl %ecx, (%rax)
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf32d(%rip), %rdi      # 0x145d4
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %rdi
callq 0x1100
testl %ecx, %ecx
jne 0x52d5
leaq 0xf264(%rip), %rdi      # 0x14525
jmp 0x52a7
leaq 0xf19f(%rip), %rdi      # 0x14469
jmp 0x52a7
leaq 0xf1eb(%rip), %rdi      # 0x144be
jmp 0x52a7
leaq 0xf29a(%rip), %rdi      # 0x14576
jmp 0x52a7
leaq 0xf33c(%rip), %rdi      # 0x14621
jmp 0x52a7
leaq 0xf3cc(%rip), %rdi      # 0x146ba
jmp 0x52a7