// File: /workspace/github_c_makefile_star2_O3/asford[P]tmalign/./TMalign.h
// Function: output_results(char*, char*, int, int, double*, double (*) [3], double, double, double, double, int*, int*, int, int, double, double, double)
void output_results(char *xname,
					 char *yname,
					 int x_len,
					 int y_len,
					 double t[3],
					 double u[3][3],
					 double TM1,
					 double TM2,
					 double rmsd,
					 double d0_out,
					 int m1[], 
					 int m2[],
					 int n_ali8,
					 int n_ali,
					 double TM_0,
					 double Lnorm_0,
					 double d0_0
					 )
{
    double seq_id;          
    int i, j, k;
    double d;
    int ali_len=x_len+y_len; //maximum length of alignment
	char *seqM, *seqxA, *seqyA;
	seqM=new char[ali_len];
	seqxA=new char[ali_len];
	seqyA=new char[ali_len];
	

	do_rotation(xa, xt, x_len, t, u);

	seq_id=0;
	int kk=0, i_old=0, j_old=0;
	for(k=0; k<n_ali8; k++)
	{
		for(i=i_old; i<m1[k]; i++)
		{
			//align x to gap
			seqxA[kk]=seqx[i];
			seqyA[kk]='-';
			seqM[kk]=' ';					
			kk++;
		}

		for(j=j_old; j<m2[k]; j++)
		{
			//align y to gap
			seqxA[kk]='-';
            seqyA[kk]=seqy[j];
            seqM[kk]=' ';
            kk++;
		}

		seqxA[kk]=seqx[m1[k]];
		seqyA[kk]=seqy[m2[k]];
		if(seqxA[kk]==seqyA[kk])
		{
			seq_id++;
		}
		d=sqrt(dist(&xt[m1[k]][0], &ya[m2[k]][0]));
		if(d<d0_out)
		{
			seqM[kk]=':';
		}
		else
		{
			seqM[kk]='.';
		} 
		kk++;  
		i_old=m1[k]+1;
		j_old=m2[k]+1;
	}

	//tail
	for(i=i_old; i<x_len; i++)
	{
		//align x to gap
		seqxA[kk]=seqx[i];
		seqyA[kk]='-';
		seqM[kk]=' ';					
		kk++;
	}    
	for(j=j_old; j<y_len; j++)
	{
		//align y to gap
		seqxA[kk]='-';
		seqyA[kk]=seqy[j];
		seqM[kk]=' ';
		kk++;
	}
 
    seqxA[kk]='\0';
    seqyA[kk]='\0';
    seqM[kk]='\0';
	

	seq_id=seq_id/( n_ali8+0.00000001); //what did by TMalign, but not reasonable, it should be n_ali8    




 



	
	cout <<endl;	
	cout << " *****************************************************************************" << endl
		 << " * TM-align (Version "<< version <<"): A protein structural alignment algorithm     *" << endl
		 << " * Reference: Y Zhang and J Skolnick, Nucl Acids Res 33, 2302-9 (2005)       *" << endl
		 << " * Please email your comments and suggestions to Yang Zhang (zhng@umich.edu) *" << endl
		 << " *****************************************************************************" << endl;	


	
	printf("\nName of structure A: %s\n", yname); 
	printf("Name of structure B: %s (to be superimposed onto structure A)\n", xname); 
	printf("Length of structure A: %d residues\n", y_len);
	printf("Length of structure B: %d residues\n\n", x_len);

	printf("Aligned length=%d, RMSD=%6.2f, Seq_ID=n_identical/n_aligned=%4.3f\n\n", n_ali8, rmsd, seq_id); 
	
	printf("TM-score=%6.5f (if normalized by length of structure B, i.e., LN=%d, d0=%.2f)\n", TM2, x_len, d0B);
	printf("TM-score=%6.5f (if normalized by length of structure A, i.e., LN=%d, d0=%.2f)\n", TM1, y_len, d0A);
	if(a_opt)
	{
		double L_ave=(x_len+y_len)*0.5;
		printf("TM-score=%6.5f (if normalized by average length of two structures, i.e., LN=%.2f, d0=%.2f)\n", TM3, L_ave, d0a);
	}
	if(u_opt)
	{		
		printf("TM-score=%6.5f (if normalized by user-specified LN=%.2f and d0=%.2f)\n", TM4, Lnorm_ass, d0u);
	}
	if(d_opt)
	{		
		printf("TM-score=%6.5f (if scaled by user-specified d0=%.2f, and LN=%.2f)\n", TM5, d0_scale, Lnorm_0);
	}
	printf("(You should use TM-score normalized by length of the reference protein)\n");

   

    printf("\n----- The rotation matrix to rotate Structure B to Structure A -----\n");
    
    printf("i\t%18s %15s %15s %15s\n", "t[i]", "u[i][0]", "u[i][1]", "u[i][2]");
    for(k=0; k<3; k++)
    {
        printf("%d\t%18.10f %15.10f %15.10f %15.10f\n",\
                k, t[k], u[k][0], u[k][1] ,u[k][2]);
    }
    printf("\nCode for rotating Structure B from (x,y,z) to (X,Y,Z):\n");
    printf("for(k=0; k<L; k++)\n");
    printf("{\n");
    printf("   X[k] = t[0] + u[0][0]*x[k] + u[0][1]*y[k] + u[0][2]*z[k]\n");
    printf("   Y[k] = t[1] + u[1][0]*x[k] + u[1][1]*y[k] + u[1][2]*z[k]\n");
    printf("   Z[k] = t[2] + u[2][0]*x[k] + u[2][1]*y[k] + u[2][2]*z[k]\n");    
    printf("}\n"); 
    
    
    //output structure alignment
    printf("\n(\":\" denotes residue pairs of d < %4.1f Angstrom, ", d0_out);
    printf("\".\" denotes other aligned residues)\n");
    printf("%s\n", seqxA);
    printf("%s\n", seqM);
    printf("%s\n", seqyA);

	cout << endl;




	if(o_opt)
	{
		output_superpose(xname, yname, x_len, y_len, t, u, rmsd, d0_out, m1, m2, n_ali8, seq_id, TM_0, Lnorm_0, d0_0);
	}


	delete [] seqM;
	delete [] seqxA;
	delete [] seqyA;
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm6, 0x90(%rsp)
movsd %xmm5, 0x50(%rsp)
movsd %xmm4, 0x88(%rsp)
movsd %xmm3, 0x30(%rsp)
movsd %xmm2, 0x70(%rsp)
movsd %xmm1, 0x98(%rsp)
movsd %xmm0, 0xa0(%rsp)
movq %r9, %r13
movq %r8, %rbp
movl %edx, %r14d
movq %rsi, 0x60(%rsp)
movq %rdi, 0x58(%rsp)
movl 0x100(%rsp), %eax
movq %rax, 0x38(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %rcx, 0x28(%rsp)
leal (%rcx,%r14), %eax
movl %eax, 0x44(%rsp)
movslq %eax, %rbx
movq %rbx, %rdi
callq 0x40d300
movq %rax, 0x48(%rsp)
movq %rbx, %rdi
callq 0x40d300
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x40d300
movq %rax, 0x8(%rsp)
movq %r14, 0x18(%rsp)
testl %r14d, %r14d
jle 0x40a4c9
movq 0x1f8121(%rip), %rbx    # 0x6025c0
movq 0x1f814a(%rip), %r14    # 0x6025f0
movl 0x18(%rsp), %r15d
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rdx
movq (%r14,%r12,8), %rcx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4058ff
incq %r12
cmpq %r12, %r15
jne 0x40a4ae
movq %rbp, 0x68(%rsp)
movq 0x38(%rsp), %rax
testl %eax, %eax
jle 0x40a6a1
movq 0x1f8116(%rip), %rcx    # 0x6025f8
movq 0x1f8117(%rip), %rdx    # 0x602600
movq 0x1f8100(%rip), %rsi    # 0x6025f0
movq %rsi, 0x20(%rsp)
movq 0x1f80cc(%rip), %rsi    # 0x6025c8
movq %rsi, 0xb0(%rsp)
movl %eax, %eax
movq %rax, 0xa8(%rsp)
xorl %r9d, %r9d
xorpd %xmm1, %xmm1
movsd 0x179aeb(%rip), %xmm0   # 0x584008
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %eax, %eax
movsd 0x30(%rsp), %xmm4
movq 0x48(%rsp), %rsi
movq %rsi, %rdi
movq %r13, %rbp
movq %rsi, %r13
movq %rbp, %r8
movq 0x80(%rsp), %rsi
movslq (%rsi,%r9,4), %r12
cmpl %r12d, %r14d
jge 0x40a598
movslq %eax, %r15
movslq %r14d, %r10
leaq (%rcx,%r10), %r14
movq %r12, %r11
subq %r10, %r11
movq 0x10(%rsp), %rsi
leaq (%rsi,%r15), %rbp
movq 0x8(%rsp), %rsi
leaq (%rsi,%r15), %r10
addq %r13, %r15
xorl %r13d, %r13d
movb (%r14,%r13), %sil
movb %sil, (%rbp,%r13)
movb $0x2d, (%r10,%r13)
movb $0x20, (%r15,%r13)
incq %r13
cmpq %r13, %r11
jne 0x40a574
addl %r13d, %eax
movq %rdi, %r13
movq %r8, %rbp
movq 0x78(%rsp), %rsi
movslq (%rsi,%r9,4), %r15
cmpl %r15d, %ebx
jge 0x40a5f2
movslq %eax, %r14
movslq %ebx, %r10
leaq (%rdx,%r10), %rbx
movq %r15, %r11
subq %r10, %r11
movq 0x10(%rsp), %rsi
leaq (%rsi,%r14), %rbp
movq 0x8(%rsp), %rsi
leaq (%rsi,%r14), %r10
addq %r13, %r14
xorl %r13d, %r13d
movb $0x2d, (%rbp,%r13)
movb (%rbx,%r13), %sil
movb %sil, (%r10,%r13)
movb $0x20, (%r14,%r13)
incq %r13
cmpq %r13, %r11
jne 0x40a5ce
addl %r13d, %eax
movq %rdi, %r13
movq %r8, %rbp
movb (%rcx,%r12), %sil
cltq
movq 0x10(%rsp), %r10
movb %sil, (%r10,%rax)
movb (%rdx,%r15), %r10b
movq 0x8(%rsp), %r11
movb %r10b, (%r11,%rax)
movapd %xmm1, %xmm5
addsd %xmm0, %xmm5
cmpb %r10b, %sil
je 0x40a61f
movapd %xmm1, %xmm5
movq 0x20(%rsp), %rsi
movq (%rsi,%r12,8), %rsi
movq 0xb0(%rsp), %r10
movq (%r10,%r15,8), %r10
movsd (%rsi), %xmm1
subsd (%r10), %xmm1
mulsd %xmm1, %xmm1
movupd 0x8(%rsi), %xmm2
movupd 0x8(%r10), %xmm3
subpd %xmm3, %xmm2
mulpd %xmm2, %xmm2
addsd %xmm2, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtsd %xmm2, %xmm1
ucomisd %xmm4, %xmm1
movl $0x2e, %esi
movl $0x3a, %r10d
cmovbl %r10d, %esi
movb %sil, (%r13,%rax)
incl %eax
leal 0x1(%r12), %r14d
leal 0x1(%r15), %ebx
incq %r9
movapd %xmm5, %xmm1
cmpq 0xa8(%rsp), %r9
jne 0x40a53b
jmp 0x40a6b4
xorpd %xmm5, %xmm5
xorl %eax, %eax
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r13, %rbp
movq 0x48(%rsp), %r13
movq 0x18(%rsp), %rsi
cmpl %esi, %r14d
jge 0x40a705
movslq %eax, %rcx
movslq %r14d, %rdx
movslq %esi, %rsi
subq %rdx, %rsi
addq 0x1f7f27(%rip), %rdx    # 0x6025f8
movq 0x10(%rsp), %rdi
addq %rcx, %rdi
movq 0x8(%rsp), %r8
leaq (%r8,%rcx), %r9
addq %r13, %rcx
xorl %r8d, %r8d
movb (%rdx,%r8), %r10b
movb %r10b, (%rdi,%r8)
movb $0x2d, (%r9,%r8)
movb $0x20, (%rcx,%r8)
incq %r8
cmpq %r8, %rsi
jne 0x40a6e8
addl %r8d, %eax
movq 0x28(%rsp), %r14
cmpl %r14d, %ebx
movq 0x38(%rsp), %r12
jge 0x40a75d
movslq %ebx, %rcx
movslq %r14d, %rdx
subq %rcx, %rdx
addq 0x1f7edc(%rip), %rcx    # 0x602600
movslq %eax, %r8
movq 0x10(%rsp), %rsi
addq %r8, %rsi
movq 0x8(%rsp), %rdi
addq %r8, %rdi
movq %r13, %r9
addq %r8, %r9
xorl %r8d, %r8d
movb $0x2d, (%rsi,%r8)
movb (%rcx,%r8), %r10b
movb %r10b, (%rdi,%r8)
movb $0x20, (%r9,%r8)
incq %r8
cmpq %r8, %rdx
jne 0x40a740
addl %r8d, %eax
cltq
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
movb %cl, (%rdx,%rax)
movq 0x8(%rsp), %rdx
movb %cl, (%rdx,%rax)
cvtsi2sd %r12d, %xmm0
movb %cl, (%r13,%rax)
addsd 0x17989d(%rip), %xmm0   # 0x584020
divsd %xmm0, %xmm5
movsd %xmm5, 0x20(%rsp)
movq $0x605d20, %rbx         # imm = 0x605D20
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4571d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x475b80
movq %rax, %rdi
callq 0x475150
leaq 0x179c56(%rip), %rsi    # 0x584418
movl $0x4e, %edx
movq %rbx, %rdi
callq 0x476080
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4571d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x475b80
movq %rax, %rdi
callq 0x475150
movq %rax, %rbx
leaq 0x179c67(%rip), %rsi    # 0x584467
movl $0x15, %edx
movq %rax, %rdi
callq 0x476080
leaq 0x1f7d3c(%rip), %r15    # 0x602550
movq %r15, %rdi
callq 0x401120
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x476080
leaq 0x179c4c(%rip), %rsi    # 0x58447d
movl $0x31, %edx
movq %rbx, %rdi
callq 0x476080
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4571d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x475b80
movq %rax, %rdi
callq 0x475150
movq %rax, %rbx
leaq 0x179c40(%rip), %rsi    # 0x5844af
movl $0x4e, %edx
movq %rax, %rdi
callq 0x476080
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4571d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x475b80
movq %rax, %rdi
callq 0x475150
movq %rax, %rbx
leaq 0x179c51(%rip), %rsi    # 0x5844fe
movl $0x4e, %edx
movq %rax, %rdi
callq 0x476080
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4571d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x475b80
movq %rax, %rdi
callq 0x475150
movq %rax, %rbx
movl $0x4e, %edx
movq %rax, %rdi
leaq 0x179b25(%rip), %rsi    # 0x584418
callq 0x476080
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4571d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x475b80
movq %rax, %rdi
callq 0x475150
leaq 0x179c27(%rip), %rdi    # 0x58454d
movq 0x60(%rsp), %rsi
xorl %eax, %eax
callq 0x4d9ab0
leaq 0x179c2e(%rip), %rdi    # 0x584567
movq 0x58(%rsp), %rsi
xorl %eax, %eax
callq 0x4d9ab0
leaq 0x179c5a(%rip), %rdi    # 0x5845a6
movl %r14d, %esi
xorl %eax, %eax
callq 0x4d9ab0
leaq 0x179c6d(%rip), %rdi    # 0x5845ca
movq 0x18(%rsp), %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x4d9ab0
leaq 0x179c7d(%rip), %rdi    # 0x5845ef
movl %r12d, %esi
movsd 0x70(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movb $0x2, %al
callq 0x4d9ab0
movsd 0x1fa440(%rip), %xmm1   # 0x604dd0
leaq 0x179c9c(%rip), %rdi    # 0x584633
movsd 0x98(%rsp), %xmm0
movl %ebx, %esi
movb $0x2, %al
callq 0x4d9ab0
movsd 0x1fa417(%rip), %xmm1   # 0x604dc8
leaq 0x179cca(%rip), %rdi    # 0x584682
movsd 0xa0(%rsp), %xmm0
movl %r14d, %esi
movb $0x2, %al
callq 0x4d9ab0
cmpb $0x1, 0x1fa417(%rip)    # 0x604de9
jne 0x40aa03
xorps %xmm1, %xmm1
cvtsi2sdl 0x44(%rsp), %xmm1
mulsd 0x179633(%rip), %xmm1   # 0x584018
movsd 0x1fa403(%rip), %xmm0   # 0x604df0
movsd 0x1fa3eb(%rip), %xmm2   # 0x604de0
leaq 0x179cd5(%rip), %rdi    # 0x5846d1
movb $0x3, %al
callq 0x4d9ab0
cmpb $0x1, 0x1fa3e0(%rip)    # 0x604dea
jne 0x40aa32
movsd 0x1fa3e4(%rip), %xmm0   # 0x604df8
movsd 0x1fa394(%rip), %xmm1   # 0x604db0
movsd 0x1fa3b4(%rip), %xmm2   # 0x604dd8
leaq 0x179d02(%rip), %rdi    # 0x58472d
movb $0x3, %al
callq 0x4d9ab0
cmpb $0x1, 0x1fa3b2(%rip)    # 0x604deb
jne 0x40aa5f
movsd 0x1fa3bd(%rip), %xmm0   # 0x604e00
movsd 0x1fa375(%rip), %xmm1   # 0x604dc0
leaq 0x179d21(%rip), %rdi    # 0x584773
movsd 0x50(%rsp), %xmm2
movb $0x3, %al
callq 0x4d9ab0
leaq 0x17a3e0(%rip), %rdi    # 0x584e46
callq 0x4e8fd0
leaq 0x17a41c(%rip), %rdi    # 0x584e8e
callq 0x4e8fd0
leaq 0x179d38(%rip), %rdi    # 0x5847b6
leaq 0x179d48(%rip), %rsi    # 0x5847cd
leaq 0x179d46(%rip), %rdx    # 0x5847d2
leaq 0x179d47(%rip), %rcx    # 0x5847da
leaq 0x179d48(%rip), %r8     # 0x5847e2
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4d9ab0
movq %rbp, %r12
leaq 0x10(%rbp), %r14
leaq 0x179d39(%rip), %r15    # 0x5847ea
movq 0x68(%rsp), %rbp
movsd (%rbp,%rbx,8), %xmm0
movsd -0x10(%r14), %xmm1
movsd -0x8(%r14), %xmm2
movsd (%r14), %xmm3
movq %r15, %rdi
movl %ebx, %esi
movb $0x4, %al
callq 0x4d9ab0
incq %rbx
addq $0x18, %r14
cmpq $0x3, %rbx
jne 0x40aab6
leaq 0x17a3e7(%rip), %rdi    # 0x584ed4
callq 0x4e8fd0
leaq 0x17a413(%rip), %rdi    # 0x584f0c
callq 0x4e8fd0
leaq 0x17a41a(%rip), %rdi    # 0x584f1f
callq 0x4e8fd0
leaq 0x17a410(%rip), %rdi    # 0x584f21
callq 0x4e8fd0
leaq 0x17a440(%rip), %rdi    # 0x584f5d
callq 0x4e8fd0
leaq 0x17a470(%rip), %rdi    # 0x584f99
callq 0x4e8fd0
leaq 0x17a4a0(%rip), %rdi    # 0x584fd5
callq 0x4e8fd0
leaq 0x179ccd(%rip), %rdi    # 0x58480e
movsd 0x30(%rsp), %xmm0
movb $0x1, %al
callq 0x4d9ab0
leaq 0x17a482(%rip), %rdi    # 0x584fd7
callq 0x4e8fd0
movq 0x10(%rsp), %rdi
callq 0x4e8fd0
movq %r13, %rdi
callq 0x4e8fd0
movq 0x8(%rsp), %rdi
callq 0x4e8fd0
movq $0x605d20, %rbx         # imm = 0x605D20
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4571d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x475b80
movq %rax, %rdi
callq 0x475150
cmpb $0x1, 0x1fa23d(%rip)    # 0x604de8
jne 0x40ac12
subq $0x8, %rsp
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x70(%rsp), %r8
movq %r12, %r9
movsd 0x78(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movsd 0x90(%rsp), %xmm3
movsd 0x58(%rsp), %xmm4
movsd 0x98(%rsp), %xmm5
pushq 0x40(%rsp)
pushq 0x88(%rsp)
pushq 0x98(%rsp)
callq 0x409989
addq $0x20, %rsp
movq %r13, %rdi
callq 0x40c600
movq 0x10(%rsp), %rdi
callq 0x40c600
movq 0x8(%rsp), %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40c600