// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %rbx
movq %rcx, -0x98(%rbp)
movq %rdx, %r14
movq %rsi, -0x50(%rbp)
movq %rdi, %r15
xorl %eax, %eax
movb $0x20, %r11b
movl $0x1, %ecx
movq %rdi, %rdx
xorl %esi, %esi
xorl %r8d, %r8d
movl %r8d, %r10d
movl %esi, %r13d
movl %r11d, %r12d
movb (%rdx), %r11b
leal -0x30(%r11), %edi
cmpb $0xa, %dil
cmovbl %ecx, %esi
cmpb $0x29, %r12b
setne %dil
cmovnel %r13d, %esi
movl $0x0, %r8d
cmpl $0x1, %esi
je 0x530f
movl %esi, %r8d
xorl %r9d, %r9d
cmpb $0x3a, %r11b
sete %r9b
cmovel %r8d, %esi
addl %r9d, %eax
cmpl $0x1, %r13d
setne %r8b
andb %r8b, %dil
andb %dil, %r9b
movzbl %r9b, %r8d
addl %r10d, %r8d
incq %rdx
testb %r11b, %r11b
jne 0x52de
leal -0x3(,%r8,2), %ecx
cmpl %ecx, %eax
movl %ecx, -0x8c(%rbp)
cmovll %eax, %ecx
movl %ecx, (%rbx)
testl %eax, %eax
je 0x5c7d
leal (%r8,%r8), %r9d
xorl %eax, %eax
movq %r15, %rcx
movb (%rcx), %dl
xorl %esi, %esi
cmpb $0x28, %dl
sete %sil
addl %esi, %eax
incq %rcx
testb %dl, %dl
jne 0x5364
xorl %ecx, %ecx
movq %r15, %rdx
movb (%rdx), %sil
xorl %edi, %edi
cmpb $0x29, %sil
sete %dil
addl %edi, %ecx
incq %rdx
testb %sil, %sil
jne 0x537d
cmpl %eax, %ecx
jne 0x5c86
xorl %eax, %eax
movq %r15, %rcx
movb (%rcx), %dl
xorl %esi, %esi
cmpb $0x3b, %dl
sete %sil
addl %esi, %eax
incq %rcx
testb %dl, %dl
jne 0x53a1
cmpl $0x1, %eax
jne 0x5c70
movq %r15, %rax
movzbl (%rax), %ecx
incq %rax
cmpl $0x20, %ecx
je 0x53c1
cmpl $0x28, %ecx
jne 0x5c4f
xorl %eax, %eax
movq %r15, %rcx
movb (%rcx), %dl
xorl %esi, %esi
cmpb $0x25, %dl
sete %sil
addl %esi, %eax
incq %rcx
testb %dl, %dl
jne 0x53da
testl %eax, %eax
jne 0x5c98
xorl %eax, %eax
movabsq $0xc00110000000000, %rcx # imm = 0xC00110000000000
movslq %eax, %rdx
incl %eax
movb (%r15,%rdx), %dl
movl %edx, %esi
andb $-0x5, %sil
cmpb $0x28, %sil
jne 0x5436
movslq %eax, %rsi
movzbl (%r15,%rsi), %edx
cmpq $0x3b, %rdx
ja 0x543c
btq %rdx, %rcx
jae 0x543c
xorl %esi, %esi
testb %sil, %sil
jne 0x5c58
testb %dl, %dl
jne 0x5402
jmp 0x5460
addq %r15, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movzbl (%rsi), %edx
incl %eax
incl %edi
cmpl $0x3a, %edx
je 0x5457
incq %rsi
testl %edx, %edx
jne 0x5444
cmpl $0x32, %edi
setae %sil
jmp 0x542d
movl %r9d, -0xac(%rbp)
movl %r13d, -0x30(%rbp)
movb %r12b, -0x29(%rbp)
movq %r11, -0x70(%rbp)
movq %r8, -0x38(%rbp)
movq %r10, -0x78(%rbp)
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1140
movq %rax, %r12
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1140
movq %rax, %r13
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x1140
movq %r13, %rdi
testq %r13, %r13
je 0x5ca1
testq %r12, %r12
je 0x5ca1
movq %rax, %r13
testq %rax, %rax
je 0x5ca1
movl $0x0, -0x44(%rbp)
movabsq $0x100000600, %rax      # imm = 0x100000600
movq -0x98(%rbp), %r10
movzbl (%r15), %ecx
cmpq $0x20, %rcx
ja 0x54e8
btq %rcx, %rax
jb 0x54f7
movl -0x44(%rbp), %esi
movslq %esi, %rdx
incl %esi
movl %esi, -0x44(%rbp)
movb %cl, (%r12,%rdx)
incq %r15
testb %cl, %cl
jne 0x54d8
movl $0x1, %eax
cmpb $0x28, (%r12)
movq %r14, -0x60(%rbp)
movq %rbx, -0xb8(%rbp)
jne 0x580c
cmpl $0x1, -0x30(%rbp)
setne %al
cmpb $0x29, -0x29(%rbp)
setne %cl
cmpb $0x3a, -0x70(%rbp)
sete %dl
andb %al, %cl
andb %dl, %cl
movzbl %cl, %eax
addl -0x78(%rbp), %eax
movq %rax, -0xa0(%rbp)
movl $0x1, %eax
movq %rax, -0x68(%rbp)
movl $0x1, -0x54(%rbp)
movq %r12, %rsi
movq %rdi, %rcx
xorl %ebx, %ebx
xorl %r14d, %r14d
movzbl (%rsi,%rbx), %eax
cmpl $0x28, %eax
je 0x556a
cmpl $0x29, %eax
jne 0x556d
jmp 0x5572
movl %ebx, %r14d
incq %rbx
jmp 0x555a
movq %rcx, -0x80(%rbp)
incq -0xa0(%rbp)
cmpl %ebx, %r14d
movq %rsi, -0x88(%rbp)
jge 0x573b
leaq 0x1(%rbx), %rax
movq %rax, -0x40(%rbp)
leal 0x1(%r14), %r11d
movslq %r14d, %r12
incq %r12
movl %r14d, %r15d
movzbl (%rsi,%r12), %eax
cmpl $0x29, %eax
je 0x561b
cmpl $0x2c, %eax
je 0x561b
cmpl $0x3a, %eax
jne 0x56aa
movslq %r11d, %rax
leal 0x1(%r12), %ecx
movl %ecx, -0xa8(%rbp)
cmpb $0x25, (%rsi,%rax)
jne 0x56bc
incq %rax
movslq %eax, %rcx
cmpq %rcx, %r12
movl %r11d, -0xb0(%rbp)
jle 0x56ea
movl %r15d, %ecx
subl %r11d, %ecx
leaq (%rsi,%rax), %rdx
xorl %esi, %esi
movb (%rdx,%rsi), %dil
cmpb $0x7c, %dil
je 0x5709
movb %dil, (%r13,%rsi)
leaq (%rax,%rsi), %rdi
incq %rdi
incq %rsi
cmpq %r12, %rdi
jl 0x55f4
jmp 0x570b
movslq -0xa8(%rbp), %rax
cmpq %rax, %r12
jle 0x5646
movl %r12d, %ecx
subl %eax, %ecx
addq %rsi, %rax
xorl %edx, %edx
movb (%rax,%rdx), %sil
movb %sil, (%r13,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x5631
movl %edx, %eax
jmp 0x5648
xorl %eax, %eax
movb $0x0, (%r13,%rax)
movq %r13, %rdi
callq 0x1120
movq -0x68(%rbp), %rsi
movslq %esi, %rax
incl %esi
movq -0x50(%rbp), %rdx
movq -0xa0(%rbp), %rcx
movq %rcx, (%rdx,%rax,8)
movslq -0x90(%rbp), %rcx
movq %rcx, 0x8(%rdx,%rax,8)
leal 0x2(%rax), %ecx
shrl $0x1f, %esi
addl %esi, %eax
incl %eax
sarl %eax
cltq
movq -0x60(%rbp), %rdx
movsd %xmm0, (%rdx,%rax,8)
leal 0x1(%r12), %r11d
movl %ecx, %eax
movq %rax, -0x68(%rbp)
movq -0x88(%rbp), %rsi
movq -0x98(%rbp), %r10
incq %r12
incl %r15d
cmpl %r12d, -0x40(%rbp)
jne 0x55a2
jmp 0x573b
movslq -0x54(%rbp), %rcx
cmpq %rax, %r12
jle 0x56ee
movl %r12d, %edx
subl %eax, %edx
addq %rsi, %rax
xorl %r9d, %r9d
movb (%rax,%r9), %dil
movq -0x8(%r10,%rcx,8), %r8
movb %dil, (%r8,%r9)
incq %r9
cmpq %r9, %rdx
jne 0x56d0
movl %r9d, %eax
jmp 0x56f0
xorl %eax, %eax
jmp 0x570d
xorl %eax, %eax
movq -0x8(%r10,%rcx,8), %rdx
movb $0x0, (%rdx,%rax)
incl %ecx
movl -0x54(%rbp), %eax
movl %eax, -0x90(%rbp)
movl %ecx, -0x54(%rbp)
jmp 0x56aa
movl %esi, %ecx
movl %ecx, %eax
movb $0x0, (%r13,%rax)
movq %r13, %rdi
callq 0x11a0
movl %eax, -0x90(%rbp)
movq -0x88(%rbp), %rsi
movq -0x98(%rbp), %r10
movl -0xb0(%rbp), %r11d
jmp 0x56aa
testl %r14d, %r14d
jle 0x5751
movl %r14d, %edx
movq -0x80(%rbp), %r12
movq %r12, %rdi
callq 0x1080
jmp 0x5758
xorl %r14d, %r14d
movq -0x80(%rbp), %r12
movq -0xa0(%rbp), %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x51ca
movl %r14d, %r15d
movb $0x25, (%r12,%r15)
movq %r13, %rdi
callq 0x1050
incl %r14d
testl %eax, %eax
jle 0x57ae
addq %r15, %r12
incq %r12
xorl %r15d, %r15d
movb (%r13,%r15), %al
movb %al, (%r12,%r15)
incq %r15
movq %r13, %rdi
callq 0x1050
cltq
cmpq %rax, %r15
jl 0x578c
addl %r15d, %r14d
movq -0x80(%rbp), %r12
movl -0x44(%rbp), %eax
cmpl %ebx, %eax
movq -0x88(%rbp), %rsi
movq -0x98(%rbp), %r10
jle 0x57f4
movl %eax, %eax
movb $0x1, %dl
movb 0x1(%rsi,%rbx), %cl
testb $0x1, %dl
je 0x57e0
cmpb $0x3a, %cl
je 0x57e0
movslq %r14d, %rdx
incl %r14d
movb $0x7c, (%r12,%rdx)
incq %rbx
movslq %r14d, %rdx
incl %r14d
movb %cl, (%r12,%rdx)
xorl %edx, %edx
cmpq %rbx, %rax
jne 0x57c7
cmpb $0x28, (%r12)
movq %rsi, %rdi
movl %r14d, -0x44(%rbp)
je 0x554f
movslq -0x68(%rbp), %rax
jmp 0x580f
movq %rdi, %rsi
movq %rax, -0x40(%rbp)
movq %rsi, -0x88(%rbp)
movq %r12, -0x80(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x5889
cmpl $0x1, -0x30(%rbp)
setne %al
cmpb $0x29, -0x29(%rbp)
setne %cl
cmpb $0x3a, -0x70(%rbp)
sete %dl
andb %al, %cl
andb %dl, %cl
movzbl %cl, %eax
movq -0x78(%rbp), %rcx
leal (%rcx,%rax), %r12d
leal (%rcx,%rax), %r14d
incl %r14d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r10, %r15
movq -0x8(%r15,%r12,8), %rsi
movq (%r15,%r12,8), %rdi
callq 0x1090
movq (%r15,%r12,8), %rdi
leaq 0xfe87(%rip), %rsi      # 0x156f7
callq 0x1170
testl %eax, %eax
cmovel %r12d, %ebx
decq %r12
decl %r14d
cmpl $0x1, %r14d
jg 0x5857
jmp 0x5891
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r10, %r15
leaq 0xfe64(%rip), %rdi      # 0x156fc
movl %ebx, %r12d
movl %ebx, %esi
xorl %eax, %eax
callq 0x1030
movq -0x38(%rbp), %rax
movl %eax, %r14d
testl %eax, %eax
je 0x58d4
movl $0x1, %ebx
movq (%r15,%rbx,8), %rdx
leaq 0xfe52(%rip), %rdi      # 0x15711
movl %ebx, %esi
xorl %eax, %eax
callq 0x1030
leaq 0x1(%rbx), %rax
cmpq %r14, %rbx
movq %rax, %rbx
jb 0x58b4
xorpd %xmm0, %xmm0
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movupd %xmm0, (%rax,%rcx,8)
movslq -0x8c(%rbp), %rsi
cmpl $0x2, -0x38(%rbp)
movq -0x60(%rbp), %rcx
jb 0x5917
xorl %eax, %eax
movsd 0xf740(%rip), %xmm0     # 0x15040
movapd %xmm0, %xmm1
maxsd 0x8(%rcx,%rax,8), %xmm1
movsd %xmm1, (%rcx,%rax,8)
incq %rax
cmpq %rsi, %rax
jl 0x5900
movq %r14, -0xa8(%rbp)
cmpl $0x2, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
jb 0x596e
cmpl $0x1, -0x30(%rbp)
setne %al
cmpb $0x29, -0x29(%rbp)
setne %cl
cmpb $0x3a, -0x70(%rbp)
sete %dl
movq -0x50(%rbp), %rdi
leaq 0x8(%rdi), %rsi
andb %al, %cl
andb %dl, %cl
movzbl %cl, %eax
addl -0x78(%rbp), %eax
leal -0x6(,%rax,4), %eax
cmpl $0x2, %eax
movl $0x1, %edx
cmovgel %eax, %edx
shlq $0x3, %rdx
callq 0x11c0
movq -0x40(%rbp), %rsi
testl %r12d, %r12d
jle 0x5a63
movl %r12d, %edx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r12d, %r12d
cmpl $0x2, -0x38(%rbp)
jb 0x59b5
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movq -0x50(%rbp), %rcx
movq 0x8(%rcx), %r14
cmpq %r12, %r14
jne 0x599f
movl (%rcx), %edi
cmpq %r12, (%rcx)
cmovnel %edi, %r14d
addq $0x10, %rcx
incq %rax
movl %r14d, %edi
cmpq %rsi, %rax
jl 0x5994
leaq 0xfd60(%rip), %rdi      # 0x1571c
movl %r14d, %esi
xorl %eax, %eax
callq 0x1030
movq -0x40(%rbp), %rsi
cmpl $0x2, -0x38(%rbp)
jb 0x5a63
movslq %r14d, %rcx
movq -0x50(%rbp), %rax
leaq 0x8(%rax), %r15
xorl %ebx, %ebx
movq %rcx, -0x68(%rbp)
movq (%r15), %rdx
cmpq %r12, %rdx
je 0x5a1e
cmpq %rcx, -0x8(%r15)
jne 0x5a1e
movq -0x60(%rbp), %rax
movabsq $0x4049000000000000, %rcx # imm = 0x4049000000000000
movq %rcx, (%rax,%rbx,8)
leaq 0xfd19(%rip), %rdi      # 0x15725
movl %r14d, %esi
xorl %eax, %eax
callq 0x1030
movq -0x68(%rbp), %rcx
movq -0x40(%rbp), %rsi
movq -0x8(%r15), %rdx
cmpq %r12, %rdx
je 0x5a57
cmpq %rcx, (%r15)
jne 0x5a57
movq -0x60(%rbp), %rax
movabsq $0x4049000000000000, %rcx # imm = 0x4049000000000000
movq %rcx, (%rax,%rbx,8)
leaq 0xfce0(%rip), %rdi      # 0x15725
movl %r14d, %esi
xorl %eax, %eax
callq 0x1030
movq -0x68(%rbp), %rcx
movq -0x40(%rbp), %rsi
addq $0x10, %r15
incq %rbx
cmpq %rsi, %rbx
jl 0x59e5
movl $0xa, %edi
movq %rsi, %r14
callq 0x1160
cmpl $0x2, -0x38(%rbp)
movq -0x60(%rbp), %r12
jb 0x5aac
movq -0x50(%rbp), %rax
leaq 0x8(%rax), %rbx
xorl %r15d, %r15d
movq -0x8(%rbx), %rdx
movq (%rbx), %rsi
movsd (%r12,%r15,8), %xmm0
leaq 0xfc96(%rip), %rdi      # 0x1572f
movb $0x1, %al
callq 0x1030
addq $0x10, %rbx
incq %r15
cmpq %r14, %r15
jl 0x5a85
movl $0xa, %edi
callq 0x1160
movl -0xac(%rbp), %edi
shlq $0x2, %rdi
callq 0x1140
movq %rax, %r14
cmpl $0x0, -0x38(%rbp)
je 0x5b0f
cmpl $0x1, -0x30(%rbp)
setne %al
cmpb $0x29, -0x29(%rbp)
setne %cl
cmpb $0x3a, -0x70(%rbp)
sete %dl
andb %al, %cl
andb %dl, %cl
movzbl %cl, %eax
addl -0x78(%rbp), %eax
addl %eax, %eax
cmpl $0x3, %eax
movl $0x2, %ecx
cmovael %eax, %ecx
addl $-0x2, %ecx
leaq 0x4(,%rcx,4), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1060
cmpl $0x2, -0x38(%rbp)
movq -0xb8(%rbp), %rbx
movq -0x50(%rbp), %r9
movq -0x80(%rbp), %rdi
movq -0x40(%rbp), %r10
jb 0x5b49
leaq 0x8(%r9), %rax
xorl %ecx, %ecx
movq (%rax), %rdx
incl (%r14,%rdx,4)
movq -0x8(%rax), %rdx
incl (%r14,%rdx,4)
addq $0x10, %rax
incq %rcx
cmpq %r10, %rcx
jl 0x5b2e
movq -0xa8(%rbp), %rax
movl 0x4(%r14,%rax,4), %eax
testl %eax, %eax
jle 0x5bac
cmpl $0x1, -0x30(%rbp)
setne %cl
cmpb $0x29, -0x29(%rbp)
setne %dl
cmpb $0x3a, -0x70(%rbp)
sete %sil
andb %cl, %dl
andb %sil, %dl
movzbl %dl, %ecx
movq -0x78(%rbp), %r8
addl %ecx, %r8d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x1(%r8), %rdx
cmpl $0x2, %eax
cmovel %edx, %esi
cmpl $0x1, %eax
cmovel %edx, %ecx
movl 0x8(%r14,%r8,4), %eax
movq %rdx, %r8
testl %eax, %eax
jg 0x5b88
movslq %ecx, %rdx
movslq %esi, %rax
jmp 0x5bba
movq $-0x1, %rax
movq $-0x1, %rdx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x2, -0x38(%rbp)
jb 0x5bfb
xorl %ecx, %ecx
cmpq %rdx, 0x8(%r9)
je 0x5be1
cmpq %rdx, (%r9)
je 0x5bea
incq %rcx
addq $0x10, %r9
cmpq %r10, %rcx
jl 0x5bc8
jmp 0x5bfb
movq $-0x8, %rdx
jmp 0x5bf1
movq $-0x10, %rdx
incl %ecx
movq %rax, 0x10(%rdx,%r9)
movl %ecx, %r14d
cmpl $-0x1, %r14d
je 0x5c17
movslq %r14d, %rax
movabsq $0x4059000000000000, %rcx # imm = 0x4059000000000000
movq -0x60(%rbp), %rdx
movq %rcx, -0x8(%rdx,%rax,8)
callq 0x1100
movq %r13, %rdi
callq 0x1100
movq -0x88(%rbp), %rdi
callq 0x1100
movl -0x8c(%rbp), %eax
subl (%rbx), %eax
movl %eax, (%rbx)
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf97e(%rip), %rdi      # 0x155d4
jmp 0x5c5f
leaq 0xfa0d(%rip), %rdi      # 0x1566c
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
testl %eax, %eax
jne 0x5c8f
leaq 0xf8aa(%rip), %rdi      # 0x15525
jmp 0x5c5f
leaq 0xf7e5(%rip), %rdi      # 0x15469
jmp 0x5c5f
leaq 0xf831(%rip), %rdi      # 0x154be
jmp 0x5c5f
leaq 0xf8e0(%rip), %rdi      # 0x15576
jmp 0x5c5f
leaq 0xf982(%rip), %rdi      # 0x15621
jmp 0x5c5f
leaq 0xfa12(%rip), %rdi      # 0x156ba
jmp 0x5c5f