// File: /workspace/github_c_makefile_star2_O2/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 $0xd8, %rsp
movsd %xmm6, 0x80(%rsp)
movsd %xmm5, 0x40(%rsp)
movsd %xmm4, 0x78(%rsp)
movsd %xmm3, 0x28(%rsp)
movsd %xmm2, 0x58(%rsp)
movsd %xmm1, 0x88(%rsp)
movsd %xmm0, 0x90(%rsp)
movq %r9, %r15
movq %r8, %r13
movl %edx, %ebp
movq %rsi, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movl 0x120(%rsp), %r14d
movq 0x118(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x70(%rsp)
movq %rcx, 0x98(%rsp)
leal (%rcx,%rbp), %eax
movl %eax, 0x3c(%rsp)
movslq %eax, %rbx
movq %rbx, %rdi
callq 0x40be00
movq %rax, %r12
movq %rbx, %rdi
callq 0x40be00
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x40be00
movq %rax, 0x8(%rsp)
movq 0x1f9082(%rip), %rdi    # 0x6025c0
movq 0x1f90ab(%rip), %rsi    # 0x6025f0
movq %rbp, 0x20(%rsp)
movl %ebp, %edx
movq %r13, 0x60(%rsp)
movq %r13, %rcx
movq %r15, 0xa0(%rsp)
movq %r15, %r8
callq 0x405577
movq %r12, %r9
movq 0x1f908a(%rip), %r12    # 0x6025f8
movq 0x1f908b(%rip), %rbx    # 0x602600
movq 0x1f9074(%rip), %rax    # 0x6025f0
movq %rax, 0xb8(%rsp)
xorl %ebp, %ebp
testl %r14d, %r14d
movl $0x0, %eax
movq %r14, 0xa8(%rsp)
cmovgl %r14d, %eax
movq %rax, 0xc0(%rsp)
movq 0x1f901f(%rip), %rax    # 0x6025c8
movq %rax, 0xb0(%rsp)
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
xorl %eax, %eax
xorl %edx, %edx
movq %r9, 0x30(%rsp)
cmpq 0xc0(%rsp), %rbp
je 0x4096fc
movslq %eax, %rsi
movq %rcx, 0xd0(%rsp)
movslq %ecx, %rax
movslq %edx, %rcx
movq 0x70(%rsp), %rdx
movslq (%rdx,%rbp,4), %r15
movq %rax, %r14
shlq $0x20, %r14
xorl %r13d, %r13d
movq %rax, %rdx
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r10
movabsq $0x100000000, %r11      # imm = 0x100000000
cmpq %r15, %rsi
jge 0x40962e
movb (%r12,%rsi), %dil
movb %dil, (%r8,%rdx)
movb $0x2d, (%r10,%rdx)
movb $0x20, (%r9,%rdx)
incq %rdx
incq %rsi
addq %r11, %r14
incq %r13
jmp 0x409609
movq 0x68(%rsp), %rdx
movq %rbp, 0x18(%rsp)
movslq (%rdx,%rbp,4), %rbp
leaq (%r8,%rax), %rdx
leaq (%r10,%rax), %rsi
addq %r9, %rax
cmpq %rbp, %rcx
jge 0x409669
movb $0x2d, (%rdx,%r13)
movb (%rbx,%rcx), %dil
movb %dil, (%rsi,%r13)
movb $0x20, (%rax,%r13)
incq %rcx
addq %r11, %r14
incq %r13
jmp 0x409647
movb (%r12,%r15), %al
sarq $0x20, %r14
movb %al, (%r8,%r14)
movb (%rbx,%rbp), %cl
movb %cl, (%r10,%r14)
movapd %xmm1, %xmm0
addsd 0x179980(%rip), %xmm0   # 0x583008
cmpb %cl, %al
je 0x409690
movapd %xmm1, %xmm0
movsd %xmm0, 0xc8(%rsp)
movq 0xb8(%rsp), %rax
movq (%rax,%r15,8), %rdi
movq 0xb0(%rsp), %rax
movq (%rax,%rbp,8), %rsi
callq 0x4054a5
sqrtsd %xmm0, %xmm0
ucomisd 0x28(%rsp), %xmm0
pushq $0x2e
popq %rax
pushq $0x3a
popq %rcx
cmovbl %ecx, %eax
movq 0x30(%rsp), %r9
movb %al, (%r9,%r14)
movq 0xd0(%rsp), %rcx
leal 0x1(%rcx,%r13), %ecx
leal 0x1(%r15), %eax
leal 0x1(%rbp), %edx
movq 0x18(%rsp), %rbp
incq %rbp
movsd 0xc8(%rsp), %xmm1
jmp 0x4095c0
movslq %eax, %rsi
movslq 0x20(%rsp), %rdi
movslq %ecx, %rcx
movq %rcx, %rax
shlq $0x20, %rax
movq 0x10(%rsp), %r10
movq 0x98(%rsp), %r13
movq 0x8(%rsp), %r11
cmpq %rdi, %rsi
jge 0x40974c
movb (%r12,%rsi), %r8b
movb %r8b, (%r10,%rcx)
movb $0x2d, (%r11,%rcx)
movb $0x20, (%r9,%rcx)
incq %rcx
incq %rsi
movabsq $0x100000000, %r8       # imm = 0x100000000
addq %r8, %rax
jmp 0x409720
movslq %edx, %rdx
movslq %r13d, %rsi
movq 0xa8(%rsp), %r15
movq 0xa0(%rsp), %r12
cmpq %rsi, %rdx
jge 0x40978e
movb $0x2d, (%r10,%rcx)
movb (%rbx,%rdx), %dil
movb %dil, (%r11,%rcx)
movb $0x20, (%r9,%rcx)
incq %rcx
incq %rdx
movabsq $0x100000000, %rdi      # imm = 0x100000000
addq %rdi, %rax
jmp 0x409762
sarq $0x20, %rax
xorl %ecx, %ecx
movb %cl, (%r10,%rax)
movb %cl, (%r11,%rax)
cvtsi2sd %r15d, %xmm0
movb %cl, (%r9,%rax)
addsd 0x17987b(%rip), %xmm0   # 0x583028
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movq $0x605d20, %rbx         # imm = 0x605D20
movq %rbx, %rdi
callq 0x473f90
leaq 0x179c1b(%rip), %rbp    # 0x5833e8
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4746b0
movq %rax, %rdi
callq 0x473f90
leaq 0x179c50(%rip), %rsi    # 0x583437
movq %rax, %rdi
callq 0x4746b0
leaq 0x1f8d5a(%rip), %rsi    # 0x602550
movq %rax, %rdi
callq 0x4746b0
leaq 0x179c48(%rip), %rsi    # 0x58344d
movq %rax, %rdi
callq 0x4746b0
movq %rax, %rdi
callq 0x473f90
leaq 0x179c63(%rip), %rsi    # 0x58347f
movq %rax, %rdi
callq 0x4746b0
movq %rax, %rdi
callq 0x473f90
leaq 0x179c9b(%rip), %rsi    # 0x5834ce
movq %rax, %rdi
callq 0x4746b0
movq %rax, %rdi
callq 0x473f90
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4746b0
movq %rax, %rdi
callq 0x473f90
leaq 0x179cc0(%rip), %rdi    # 0x58351d
movq 0x50(%rsp), %rsi
xorl %eax, %eax
callq 0x4d8720
leaq 0x179cc7(%rip), %rdi    # 0x583537
movq 0x48(%rsp), %rsi
xorl %eax, %eax
callq 0x4d8720
leaq 0x179cf3(%rip), %rdi    # 0x583576
movl %r13d, %esi
xorl %eax, %eax
callq 0x4d8720
leaq 0x179d06(%rip), %rdi    # 0x58359a
movq 0x20(%rsp), %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x4d8720
leaq 0x179d16(%rip), %rdi    # 0x5835bf
movl %r15d, %esi
movsd 0x58(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movb $0x2, %al
callq 0x4d8720
movsd 0x1fb509(%rip), %xmm1   # 0x604dd0
leaq 0x179d35(%rip), %rdi    # 0x583603
movsd 0x88(%rsp), %xmm0
movl %ebx, %esi
movb $0x2, %al
callq 0x4d8720
movsd 0x1fb4e0(%rip), %xmm1   # 0x604dc8
leaq 0x179d63(%rip), %rdi    # 0x583652
movsd 0x90(%rsp), %xmm0
movl %r13d, %esi
movb $0x2, %al
callq 0x4d8720
cmpb $0x1, 0x1fb4e0(%rip)    # 0x604de9
jne 0x409937
cvtsi2sdl 0x3c(%rsp), %xmm1
mulsd 0x1796ff(%rip), %xmm1   # 0x583018
movsd 0x1fb4cf(%rip), %xmm0   # 0x604df0
movsd 0x1fb4b7(%rip), %xmm2   # 0x604de0
leaq 0x179d71(%rip), %rdi    # 0x5836a1
movb $0x3, %al
callq 0x4d8720
cmpb $0x1, 0x1fb4ac(%rip)    # 0x604dea
jne 0x409966
movsd 0x1fb4b0(%rip), %xmm0   # 0x604df8
movsd 0x1fb460(%rip), %xmm1   # 0x604db0
movsd 0x1fb480(%rip), %xmm2   # 0x604dd8
leaq 0x179d9e(%rip), %rdi    # 0x5836fd
movb $0x3, %al
callq 0x4d8720
cmpb $0x1, 0x1fb47e(%rip)    # 0x604deb
jne 0x409993
movsd 0x1fb489(%rip), %xmm0   # 0x604e00
movsd 0x1fb441(%rip), %xmm1   # 0x604dc0
leaq 0x179dbd(%rip), %rdi    # 0x583743
movsd 0x40(%rsp), %xmm2
movb $0x3, %al
callq 0x4d8720
leaq 0x17a47c(%rip), %rdi    # 0x583e16
callq 0x4e7c40
leaq 0x17a4b8(%rip), %rdi    # 0x583e5e
callq 0x4e7c40
leaq 0x179dd4(%rip), %rdi    # 0x583786
leaq 0x179de4(%rip), %rsi    # 0x58379d
leaq 0x179de2(%rip), %rdx    # 0x5837a2
leaq 0x179de3(%rip), %rcx    # 0x5837aa
leaq 0x179de4(%rip), %r8     # 0x5837b2
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x4d8720
leaq 0x10(%r12), %r14
leaq 0x179dd7(%rip), %rbx    # 0x5837ba
cmpq $0x3, %rbp
je 0x409a19
movq 0x60(%rsp), %rax
movsd (%rax,%rbp,8), %xmm0
movsd -0x10(%r14), %xmm1
movsd -0x8(%r14), %xmm2
movsd (%r14), %xmm3
movq %rbx, %rdi
movl %ebp, %esi
movb $0x4, %al
callq 0x4d8720
incq %rbp
addq $0x18, %r14
jmp 0x4099e3
leaq 0x17a484(%rip), %rdi    # 0x583ea4
callq 0x4e7c40
leaq 0x17a4b0(%rip), %rdi    # 0x583edc
callq 0x4e7c40
leaq 0x17a4b7(%rip), %rdi    # 0x583eef
callq 0x4e7c40
leaq 0x17a4ad(%rip), %rdi    # 0x583ef1
callq 0x4e7c40
leaq 0x17a4dd(%rip), %rdi    # 0x583f2d
callq 0x4e7c40
leaq 0x17a50d(%rip), %rdi    # 0x583f69
callq 0x4e7c40
leaq 0x17a53d(%rip), %rdi    # 0x583fa5
callq 0x4e7c40
leaq 0x179d6a(%rip), %rdi    # 0x5837de
movsd 0x28(%rsp), %xmm0
movb $0x1, %al
callq 0x4d8720
leaq 0x17a51f(%rip), %rdi    # 0x583fa7
callq 0x4e7c40
movq 0x10(%rsp), %rdi
callq 0x4e7c40
movq 0x30(%rsp), %rdi
callq 0x4e7c40
movq 0x8(%rsp), %rdi
callq 0x4e7c40
movq $0x605d20, %rdi         # imm = 0x605D20
callq 0x473f90
cmpb $0x1, 0x1fb32a(%rip)    # 0x604de8
jne 0x409b1e
subq $0x8, %rsp
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %r13d, %ecx
movq 0x68(%rsp), %r8
movq %r12, %r9
movsd 0x60(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movsd 0x80(%rsp), %xmm3
movsd 0x48(%rsp), %xmm4
movsd 0x88(%rsp), %xmm5
pushq %r15
pushq 0x78(%rsp)
pushq 0x88(%rsp)
callq 0x408c75
addq $0x20, %rsp
movq 0x30(%rsp), %rdi
callq 0x40b100
movq 0x10(%rsp), %rdi
callq 0x40b100
movq 0x8(%rsp), %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40b100