// File: /workspace/github_c_makefile_star2_O2/asford[P]tmalign/./TMalign.h
// Function: DP_iter(double**, double**, int, int, double*, double (*) [3], int*, int, int, int)
double DP_iter( double **x,
                double **y, 
                int x_len, 
                int y_len, 
                double t[3],
                double u[3][3],
				int invmap0[],
				int g1,
				int g2,
				int iteration_max                                   
				)
{
    double gap_open[2]={-0.6, 0};
    double rmsd; 
    int *invmap=new int[y_len+1];
    
    int iteration, i, j, k;
    double tmscore, tmscore_max, tmscore_old=0;    
    int score_sum_method=8, simplify_step=40;
    tmscore_max=-1;

	//double d01=d0+1.5;
    double d02=d0*d0;
    for(int g=g1; g<g2; g++)
    {
        for(iteration=0; iteration<iteration_max; iteration++)
        {           
			NWDP_TM(x, y, x_len, y_len, t, u, d02, gap_open[g], invmap);
            
            k=0;
            for(j=0; j<y_len; j++) 
            {
                i=invmap[j];

                if(i>=0) //aligned
                {
                    xtm[k][0]=x[i][0];
                    xtm[k][1]=x[i][1];
                    xtm[k][2]=x[i][2];
                    
                    ytm[k][0]=y[j][0];
                    ytm[k][1]=y[j][1];
                    ytm[k][2]=y[j][2];
                    k++;
                }
            }

            tmscore=TMscore8_search(xtm, ytm, k, t, u, simplify_step, score_sum_method, &rmsd);

           
            if(tmscore>tmscore_max)
            {
                tmscore_max=tmscore;
                for(i=0; i<y_len; i++) 
                {                
                    invmap0[i]=invmap[i];                                      
                }				
            }
    
            if(iteration>0)
            {
                if(fabs(tmscore_old-tmscore)<0.000001)
                {     
                    break;       
                }
            }
            tmscore_old=tmscore;
        }// for iteration           
        
    }//for gapopen
    
    
    delete []invmap;
    return tmscore_max;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movl %ecx, %r14d
movl %edx, 0x18(%rsp)
movq %rsi, %r12
movq %rdi, %r13
movq 0x90(%rsp), %r15
movslq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
movslq 0xa0(%rsp), %rax
movq %rax, 0x38(%rsp)
leal 0x1(%r14), %eax
shlq $0x2, %rax
cmpl $-0x1, %ecx
pushq $-0x1
popq %rdi
cmovgeq %rax, %rdi
callq 0x40be00
movq %rax, %rbp
xorl %eax, %eax
testl %r14d, %r14d
movl $0x0, %ebx
movq %r14, 0x48(%rsp)
cmovgl %r14d, %ebx
movsd 0x1f9aad(%rip), %xmm0   # 0x602580
movl 0xa8(%rsp), %ecx
testl %ecx, %ecx
cmovlel %eax, %ecx
movl %ecx, 0x1c(%rsp)
movq 0x8(%rsp), %rax
mulsd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x17a52c(%rip), %xmm0   # 0x583030
movsd %xmm0, 0x10(%rsp)
cmpq 0x38(%rsp), %rax
jge 0x408c58
xorl %r14d, %r14d
movq %rax, 0x8(%rsp)
cmpl 0x1c(%rsp), %r14d
je 0x408c50
leaq 0x17a641(%rip), %rcx    # 0x583170
movsd (%rcx,%rax,8), %xmm1
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %rsi
movl 0x20(%rsp), %edx
movq 0x50(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
movsd 0x48(%rsp), %xmm0
pushq %rbp
callq 0x40584b
addq $0x10, %rsp
movq 0x1f9a78(%rip), %rdi    # 0x6025e0
xorl %eax, %eax
movq 0x1f9a77(%rip), %rsi    # 0x6025e8
xorl %edx, %edx
cmpq %rax, %rbx
je 0x408bdb
movslq (%rbp,%rax,4), %rcx
testq %rcx, %rcx
js 0x408bd6
movq (%r13,%rcx,8), %rcx
movsd (%rcx), %xmm0
movslq %edx, %rdx
movq (%rdi,%rdx,8), %r8
movsd %xmm0, (%r8)
movsd 0x8(%rcx), %xmm0
movsd %xmm0, 0x8(%r8)
movsd 0x10(%rcx), %xmm0
movsd %xmm0, 0x10(%r8)
movq (%r12,%rax,8), %rcx
movsd (%rcx), %xmm0
movq (%rsi,%rdx,8), %r8
movsd %xmm0, (%r8)
movsd 0x8(%rcx), %xmm0
movsd %xmm0, 0x8(%r8)
movsd 0x10(%rcx), %xmm0
movsd %xmm0, 0x10(%r8)
incl %edx
incq %rax
jmp 0x408b73
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %r8
pushq $0x28
popq %r9
leaq 0x50(%rsp), %rax
pushq %rax
pushq $0x8
callq 0x406ed7
addq $0x10, %rsp
ucomisd 0x10(%rsp), %xmm0
jbe 0x408c1c
xorl %eax, %eax
cmpq %rax, %rbx
je 0x408c16
movl (%rbp,%rax,4), %ecx
movl %ecx, (%r15,%rax,4)
incq %rax
jmp 0x408c04
movsd %xmm0, 0x10(%rsp)
testl %r14d, %r14d
movq 0x8(%rsp), %rax
je 0x408c42
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
andpd 0x17a508(%rip), %xmm1   # 0x583140
ucomisd 0x17a468(%rip), %xmm1   # 0x5830a8
jb 0x408c50
incl %r14d
movsd %xmm0, 0x20(%rsp)
jmp 0x408b1d
incq %rax
jmp 0x408b0a
movq %rbp, %rdi
callq 0x40b100
movsd 0x10(%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq