// File: /workspace/github_c_makefile_star2_O2/jiqingxiaoxi[P]RPA/RPA.c
// Function: calc_terminal_bp
void calc_terminal_bp(double temp,double dangleEntropies3[],double dangleEnthalpies3[],double dangleEntropies5[],double dangleEnthalpies5[],double tstack2Entropies[],double tstack2Enthalpies[],double atpS[],double atpH[],double Initdouble[],int Initint[],double enthalpyDPT[],double entropyDPT[],double send5[],double hend5[],char numSeq1[])
{
	int i,max;
	double T1,T2,T3,T4,T5,G,end5_11,end5_12,end5_21,end5_22,end5_31,end5_32,end5_41,end5_42;
	
	send5[0]=send5[1]= -1.0;
	hend5[0]=hend5[1]=1.0*INFINITY;

	for(i=2;i<=Initint[0];i++)
	{
		send5[i]=-3224.0;
		hend5[i]=0;
	}

// adding terminal penalties to 3' end and to 5' end 
	for(i=2;i<=Initint[0];++i)
	{
		max=0;
		T1=(hend5[i-1]+Initdouble[0])/(send5[i-1]+Initdouble[1]+Initdouble[2]);
		end5_11=END5_1(i,1,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		end5_12=END5_1(i,2,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		T2=(end5_11+Initdouble[0])/(end5_12+Initdouble[1]+Initdouble[2]);
		end5_21=END5_2(i,1,dangleEntropies5,dangleEnthalpies5,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		end5_22=END5_2(i,2,dangleEntropies5,dangleEnthalpies5,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		T3=(end5_21+Initdouble[0])/(end5_22+Initdouble[1]+Initdouble[2]);
		end5_31=END5_3(i,1,dangleEntropies3,dangleEnthalpies3,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		end5_32=END5_3(i,2,dangleEntropies3,dangleEnthalpies3,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		T4=(end5_31+Initdouble[0])/(end5_32+Initdouble[1]+Initdouble[2]);
		end5_41=END5_4(i,1,tstack2Entropies,tstack2Enthalpies,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		end5_42=END5_4(i,2,tstack2Entropies,tstack2Enthalpies,atpS,atpH,Initdouble,Initint,enthalpyDPT,entropyDPT,send5,hend5,numSeq1);
		T5=(end5_41+Initdouble[0])/(end5_42+Initdouble[1]+Initdouble[2]);

		max=max5(T1,T2,T3,T4,T5);
		switch(max)
		{
			case 1:
				send5[i]=send5[i-1];
				hend5[i]=hend5[i-1];
				break;
			case 2:
				G=end5_11-temp*end5_12;
				if(G<0.0)
				{
					send5[i]=end5_12;
					hend5[i]=end5_11;
				}
				else
				{
					send5[i]=send5[i-1];
					hend5[i]=hend5[i-1];
				}
				break;
			case 3:
				G=end5_21-temp*end5_22;
				if(G<0.0)
				{
					send5[i]=end5_22;
					hend5[i]=end5_21;
				}
				else
				{
					send5[i]=send5[i-1];
					hend5[i]=hend5[i-1];
				}
				break;
			case 4:
				G=end5_31-temp*end5_32;
				if(G<0.0)
				{
					send5[i]=end5_32;
					hend5[i]=end5_31;
				}
				else
				{
					send5[i]=send5[i-1];
					hend5[i]=hend5[i-1];
				}
				break;
			case 5:
				G=end5_41-temp*end5_42;
				if(G<0.0)
				{
					send5[i]=end5_42;
					hend5[i]=end5_41;
				}
				else
				{
					send5[i]=send5[i-1];
					hend5[i]=hend5[i-1];
				}
				break;
			default:
				break;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, -0xc0(%rbp)
movq %r8, -0xb8(%rbp)
movq %rcx, -0xb0(%rbp)
movq %rdx, -0xa8(%rbp)
movq %rsi, -0xa0(%rbp)
movq %rdi, -0x98(%rbp)
movaps %xmm0, -0x70(%rbp)
movq 0x48(%rbp), %rbx
movq 0x40(%rbp), %r14
movq 0x28(%rbp), %rcx
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x8(%r14)
movq %rax, (%r14)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rbx)
movq %rax, (%rbx)
movslq (%rcx), %rdx
pushq $0x2
popq %rax
movabsq $-0x3f56d00000000000, %rcx # imm = 0xC0A9300000000000
cmpq %rdx, %rax
jg 0x4e97
movq %rcx, (%r14,%rax,8)
andq $0x0, (%rbx,%rax,8)
incq %rax
jmp 0x4e84
movapd -0x70(%rbp), %xmm0
xorpd 0x824c(%rip), %xmm0     # 0xd0f0
movapd %xmm0, -0x70(%rbp)
pushq $0x2
popq %rcx
movq %rdx, -0x30(%rbp)
cmpq %rdx, %rcx
jg 0x52a1
movq 0x20(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x8(%rax), %xmm2
movsd %xmm2, -0x58(%rbp)
movsd -0x8(%rbx,%rcx,8), %xmm1
addsd %xmm0, %xmm1
movsd -0x8(%r14,%rcx,8), %xmm0
movsd %xmm0, -0x48(%rbp)
addsd %xmm2, %xmm0
movsd 0x10(%rax), %xmm2
movsd %xmm2, -0x50(%rbp)
movq %rax, %r8
addsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0xf8(%rbp)
subq $0x8, %rsp
movq %rcx, %rbx
movl %ebx, %edi
pushq $0x1
popq %rsi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq 0x28(%rbp), %r9
movq 0x50(%rbp), %r15
pushq %r15
pushq 0x48(%rbp)
pushq %r14
movq 0x38(%rbp), %r12
pushq %r12
movq 0x30(%rbp), %r13
pushq %r13
callq 0x44bb
addq $0x30, %rsp
movsd %xmm0, -0x90(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
pushq $0x2
popq %rsi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq 0x20(%rbp), %r8
movq 0x28(%rbp), %r9
pushq %r15
pushq 0x48(%rbp)
pushq %r14
pushq %r12
pushq %r13
callq 0x44bb
addq $0x30, %rsp
movsd -0x40(%rbp), %xmm2
addsd -0x90(%rbp), %xmm2
movsd -0x58(%rbp), %xmm1
movsd %xmm0, -0xd8(%rbp)
addsd %xmm0, %xmm1
addsd -0x50(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xf0(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
pushq $0x1
popq %rsi
movq -0xa8(%rbp), %r13
movq %r13, %rdx
movq -0xb0(%rbp), %r12
movq %r12, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq %r15
pushq 0x48(%rbp)
pushq %r14
movq 0x38(%rbp), %rax
pushq %rax
movq 0x30(%rbp), %rax
pushq %rax
movq 0x28(%rbp), %rax
pushq %rax
movq 0x20(%rbp), %r15
pushq %r15
callq 0x46b6
addq $0x40, %rsp
movsd %xmm0, -0x88(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
pushq $0x2
popq %rsi
movq %r13, %rdx
movq %r12, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq 0x48(%rbp)
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq %r15
callq 0x46b6
addq $0x40, %rsp
movsd -0x40(%rbp), %xmm2
addsd -0x88(%rbp), %xmm2
movsd -0x58(%rbp), %xmm1
movsd %xmm0, -0xd0(%rbp)
addsd %xmm0, %xmm1
addsd -0x50(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xe8(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
pushq $0x1
popq %rsi
movq -0x98(%rbp), %r13
movq %r13, %rdx
movq -0xa0(%rbp), %r12
movq %r12, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x50(%rbp), %rax
pushq %rax
pushq 0x48(%rbp)
pushq %r14
movq 0x38(%rbp), %rax
pushq %rax
movq 0x30(%rbp), %rax
pushq %rax
movq 0x28(%rbp), %r15
pushq %r15
movq 0x20(%rbp), %rax
pushq %rax
callq 0x491e
addq $0x40, %rsp
movsd %xmm0, -0x80(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
pushq $0x2
popq %rsi
movq %r13, %rdx
movq %r12, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq 0x48(%rbp)
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq %r15
pushq 0x20(%rbp)
callq 0x491e
addq $0x40, %rsp
movsd -0x40(%rbp), %xmm2
addsd -0x80(%rbp), %xmm2
movsd -0x58(%rbp), %xmm1
movsd %xmm0, -0xc8(%rbp)
addsd %xmm0, %xmm1
addsd -0x50(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xe0(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
pushq $0x1
popq %rsi
movq -0xb8(%rbp), %r12
movq %r12, %rdx
movq -0xc0(%rbp), %r13
movq %r13, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq 0x48(%rbp)
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq %r15
pushq 0x20(%rbp)
callq 0x4b84
addq $0x40, %rsp
movsd %xmm0, -0x78(%rbp)
subq $0x8, %rsp
movq %rbx, -0x38(%rbp)
movl %ebx, %edi
pushq $0x2
popq %rsi
movq %r12, %rdx
movq %r13, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
movq 0x48(%rbp), %rbx
pushq %rbx
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x4b84
addq $0x40, %rsp
movsd -0x40(%rbp), %xmm4
addsd -0x78(%rbp), %xmm4
movsd -0x58(%rbp), %xmm1
movsd %xmm0, -0x40(%rbp)
addsd %xmm0, %xmm1
addsd -0x50(%rbp), %xmm1
divsd %xmm1, %xmm4
movsd -0xf8(%rbp), %xmm0
movsd -0xf0(%rbp), %xmm1
movsd -0xe8(%rbp), %xmm2
movsd -0xe0(%rbp), %xmm3
callq 0x4312
decl %eax
leaq 0x7e3d(%rip), %rcx      # 0xd014
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movapd -0x70(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x90(%rbp), %xmm2
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x527b
movapd %xmm2, %xmm0
movq -0x38(%rbp), %rcx
movsd %xmm3, (%r14,%rcx,8)
jmp 0x5290
movapd -0x70(%rbp), %xmm0
movsd -0x40(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x78(%rbp), %xmm2
jmp 0x525d
movapd -0x70(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x88(%rbp), %xmm2
jmp 0x525d
movapd -0x70(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x80(%rbp), %xmm2
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x527b
movq -0x38(%rbp), %rcx
movsd %xmm3, (%r14,%rcx,8)
movapd %xmm2, %xmm0
jmp 0x5290
movq -0x38(%rbp), %rcx
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r14,%rcx,8)
movsd -0x8(%rbx,%rcx,8), %xmm0
movq -0x30(%rbp), %rdx
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
jmp 0x4eb0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq