// File: /workspace/github_c_makefile_star2_O3/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 $0xc8, %rsp
movq %r9, -0xb8(%rbp)
movq %r8, -0xb0(%rbp)
movq %rcx, -0xa8(%rbp)
movq %rdx, -0xa0(%rbp)
movq %rsi, -0x98(%rbp)
movq %rdi, -0x90(%rbp)
movapd %xmm0, -0x60(%rbp)
movq 0x48(%rbp), %rdx
movq 0x40(%rbp), %rsi
movq 0x28(%rbp), %rcx
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x8(%rsi)
movq %rax, (%rsi)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rdx)
movq %rax, (%rdx)
movl (%rcx), %eax
cmpl $0x2, %eax
jl 0x5499
movq %rsi, %r12
movq %rdx, %r15
movq %rax, %rsi
incq %rsi
movl $0x2, %ecx
movabsq $-0x3f56d00000000000, %rdx # imm = 0xC0A9300000000000
movq %rdx, (%r12,%rcx,8)
movq $0x0, (%r15,%rcx,8)
incq %rcx
cmpq %rcx, %rsi
jne 0x503e
cmpl $0x2, %eax
jl 0x5499
movapd -0x60(%rbp), %xmm0
xorpd 0x9068(%rip), %xmm0     # 0xe0d0
movapd %xmm0, -0x60(%rbp)
movl $0x2, %ebx
movq %rsi, -0x50(%rbp)
movq 0x20(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x8(%rax), %xmm1
movsd %xmm1, -0x48(%rbp)
movsd -0x8(%r15,%rbx,8), %xmm2
addsd %xmm0, %xmm2
movq %r12, %r14
movsd -0x8(%r12,%rbx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
addsd %xmm1, %xmm0
movsd 0x10(%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
movq %rax, %r8
addsd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, -0xe8(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x1, %esi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq 0x28(%rbp), %r9
movq 0x50(%rbp), %r13
pushq %r13
pushq %r15
pushq %r12
movq 0x38(%rbp), %rax
pushq %rax
movq 0x30(%rbp), %r12
pushq %r12
callq 0x4685
addq $0x30, %rsp
movsd %xmm0, -0x78(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x2, %esi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
movq 0x20(%rbp), %r8
movq 0x28(%rbp), %r9
pushq %r13
pushq %r15
pushq %r14
pushq 0x38(%rbp)
pushq %r12
callq 0x4685
addq $0x30, %rsp
movsd -0x38(%rbp), %xmm2
addsd -0x78(%rbp), %xmm2
movsd -0x48(%rbp), %xmm1
movsd %xmm0, -0xc0(%rbp)
addsd %xmm0, %xmm1
addsd -0x40(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xe0(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x1, %esi
movq -0xa0(%rbp), %r13
movq %r13, %rdx
movq %r15, %r12
movq -0xa8(%rbp), %r15
movq %r15, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x50(%rbp), %rax
pushq %rax
pushq %r12
pushq %r14
movq 0x38(%rbp), %rax
pushq %rax
movq 0x30(%rbp), %rax
pushq %rax
movq 0x28(%rbp), %rax
pushq %rax
movq 0x20(%rbp), %rax
pushq %rax
callq 0x488c
addq $0x40, %rsp
movsd %xmm0, -0x70(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x2, %esi
movq %r13, %rdx
movq %r15, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq %r12
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x488c
addq $0x40, %rsp
movsd -0x38(%rbp), %xmm2
addsd -0x70(%rbp), %xmm2
movsd -0x48(%rbp), %xmm1
movsd %xmm0, -0x88(%rbp)
addsd %xmm0, %xmm1
addsd -0x40(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xd8(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x1, %esi
movq -0x90(%rbp), %r13
movq %r13, %rdx
movq -0x98(%rbp), %r15
movq %r15, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x50(%rbp), %rax
pushq %rax
pushq %r12
pushq %r14
movq 0x38(%rbp), %rax
pushq %rax
movq 0x30(%rbp), %rax
pushq %rax
movq 0x28(%rbp), %rax
pushq %rax
movq 0x20(%rbp), %rax
pushq %rax
callq 0x4ad4
addq $0x40, %rsp
movsd %xmm0, -0x68(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x2, %esi
movq %r13, %rdx
movq %r15, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq %r12
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x4ad4
addq $0x40, %rsp
movsd -0x38(%rbp), %xmm2
addsd -0x68(%rbp), %xmm2
movsd -0x48(%rbp), %xmm1
movsd %xmm0, -0x80(%rbp)
addsd %xmm0, %xmm1
addsd -0x40(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xd0(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x1, %esi
movq -0xb0(%rbp), %r15
movq %r15, %rdx
movq -0xb8(%rbp), %r13
movq %r13, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq %r12
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x4d35
addq $0x40, %rsp
movsd %xmm0, -0xc8(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x2, %esi
movq %r15, %rdx
movq %r13, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
movq %r12, %r15
pushq %r12
movq %r14, %r12
pushq %r14
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x4d35
movsd -0xc8(%rbp), %xmm6
movsd -0xd0(%rbp), %xmm5
movsd -0xd8(%rbp), %xmm4
movsd -0xe8(%rbp), %xmm2
movsd -0x38(%rbp), %xmm1
addq $0x40, %rsp
addsd %xmm6, %xmm1
movsd -0x48(%rbp), %xmm3
addsd %xmm0, %xmm3
addsd -0x40(%rbp), %xmm3
divsd %xmm3, %xmm1
movsd -0xe0(%rbp), %xmm3
ucomisd %xmm3, %xmm2
jbe 0x53bf
ucomisd %xmm4, %xmm2
jbe 0x53bf
ucomisd %xmm5, %xmm2
jbe 0x53bf
ucomisd %xmm1, %xmm2
jbe 0x53bf
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12,%rbx,8)
movsd -0x8(%r15,%rbx,8), %xmm2
movq -0x50(%rbp), %rsi
jmp 0x5487
ucomisd %xmm4, %xmm3
jbe 0x53fb
ucomisd %xmm5, %xmm3
jbe 0x53fb
ucomisd %xmm1, %xmm3
jbe 0x53fb
movapd -0x60(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x78(%rbp), %xmm2
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movq -0x50(%rbp), %rsi
ja 0x544a
jmp 0x5475
ucomisd %xmm5, %xmm4
movq -0x50(%rbp), %rsi
jbe 0x5423
ucomisd %xmm1, %xmm4
jbe 0x5423
movapd -0x60(%rbp), %xmm0
movsd -0x88(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x70(%rbp), %xmm2
jmp 0x543c
ucomisd %xmm1, %xmm5
jbe 0x5452
movapd -0x60(%rbp), %xmm0
movsd -0x80(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x68(%rbp), %xmm2
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5475
movsd %xmm3, (%r12,%rbx,8)
jmp 0x5487
movapd -0x60(%rbp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm6, %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x5475
movsd %xmm0, (%r12,%rbx,8)
movapd %xmm6, %xmm2
jmp 0x5487
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12,%rbx,8)
movsd -0x8(%r15,%rbx,8), %xmm2
movsd %xmm2, (%r15,%rbx,8)
incq %rbx
cmpq %rbx, %rsi
jne 0x5076
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq