// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa8, %rsp
movl 0xc8(%rsp), %eax
movl 0xc0(%rsp), %eax
movl 0xb8(%rsp), %eax
movq 0xb0(%rsp), %rax
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movl %edx, 0x94(%rsp)
movl %ecx, 0x90(%rsp)
movq %r8, 0x88(%rsp)
movq %r9, 0x80(%rsp)
movq 0x17f617(%rip), %rax    # 0x58c160
movq %rax, 0x70(%rsp)
movq 0x17f613(%rip), %rax    # 0x58c168
movq %rax, 0x78(%rsp)
movl 0x90(%rsp), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x411b60
movq %rax, 0x60(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x8, 0x34(%rsp)
movl $0x28, 0x30(%rsp)
movsd 0x17f493(%rip), %xmm0   # 0x58c040
movsd %xmm0, 0x40(%rsp)
movsd 0x1fd9c5(%rip), %xmm0   # 0x60a580
mulsd 0x1fd9bd(%rip), %xmm0   # 0x60a580
movsd %xmm0, 0x28(%rsp)
movl 0xb8(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0xc0(%rsp), %eax
jge 0x40cea1
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jge 0x40ce8f
movq 0xa0(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl 0x94(%rsp), %edx
movl 0x90(%rsp), %ecx
movq 0x88(%rsp), %r8
movq 0x80(%rsp), %r9
movsd 0x28(%rsp), %xmm0
movslq 0x24(%rsp), %rax
movsd 0x70(%rsp,%rax,8), %xmm1
movq 0x60(%rsp), %rax
movq %rax, (%rsp)
callq 0x4067b0
movl $0x0, 0x50(%rsp)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x90(%rsp), %eax
jge 0x40cda3
movq 0x60(%rsp), %rax
movslq 0x54(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x58(%rsp)
cmpl $0x0, 0x58(%rsp)
jl 0x40cd91
movq 0xa0(%rsp), %rax
movslq 0x58(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
movq 0x1fd93c(%rip), %rax    # 0x60a5e0
movslq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax)
movq 0xa0(%rsp), %rax
movslq 0x58(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x8(%rax), %xmm0
movq 0x1fd912(%rip), %rax    # 0x60a5e0
movslq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x8(%rax)
movq 0xa0(%rsp), %rax
movslq 0x58(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x10(%rax), %xmm0
movq 0x1fd8e7(%rip), %rax    # 0x60a5e0
movslq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x10(%rax)
movq 0x98(%rsp), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
movq 0x1fd8c5(%rip), %rax    # 0x60a5e8
movslq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax)
movq 0x98(%rsp), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x8(%rax), %xmm0
movq 0x1fd89b(%rip), %rax    # 0x60a5e8
movslq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x8(%rax)
movq 0x98(%rsp), %rax
movslq 0x54(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x10(%rax), %xmm0
movq 0x1fd870(%rip), %rax    # 0x60a5e8
movslq 0x50(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x10(%rax)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x40cd93
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x40cc5b
movq 0x1fd836(%rip), %rdi    # 0x60a5e0
movq 0x1fd837(%rip), %rsi    # 0x60a5e8
movl 0x50(%rsp), %edx
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %r8
movl 0x30(%rsp), %r9d
movl 0x34(%rsp), %r10d
leaq 0x68(%rsp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x4097f0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
jbe 0x40ce43
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x90(%rsp), %eax
jge 0x40ce41
movq 0x60(%rsp), %rax
movslq 0x58(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0xb0(%rsp), %rax
movslq 0x58(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x40ce0a
jmp 0x40ce43
cmpl $0x0, 0x5c(%rsp)
jle 0x40ce73
movsd 0x38(%rsp), %xmm1
subsd 0x48(%rsp), %xmm1
movaps 0x17f2e3(%rip), %xmm0   # 0x58c140
pand %xmm0, %xmm1
movsd 0x17f24f(%rip), %xmm0   # 0x58c0b8
ucomisd %xmm1, %xmm0
jbe 0x40ce71
jmp 0x40ce8f
jmp 0x40ce73
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x40cbed
jmp 0x40ce91
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x40cbd4
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x40cebb
movq 0x18(%rsp), %rdi
callq 0x410cc0
movsd 0x40(%rsp), %xmm0
addq $0xa8, %rsp
retq
nopl (%rax)