// File: /workspace/github_c_makefile_star2_O1/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, -0xa8(%rbp)
movq %r8, -0xa0(%rbp)
movq %rcx, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
movq %rsi, -0x88(%rbp)
movq %rdi, -0x80(%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 %rsi, %r14
movq %rax, (%rsi)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rdx)
movq %rdx, %r12
movq %rax, (%rdx)
movl (%rcx), %eax
movq %rax, -0x30(%rbp)
cmpl $0x2, %eax
jl 0x515f
movq -0x30(%rbp), %rax
incq %rax
movl $0x2, %ecx
movabsq $-0x3f56d00000000000, %rdx # imm = 0xC0A9300000000000
movq %rdx, (%r14,%rcx,8)
movq $0x0, (%r12,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x514b
cmpl $0x2, -0x30(%rbp)
jl 0x55a7
movapd -0x60(%rbp), %xmm0
xorpd 0x8f4a(%rip), %xmm0     # 0xe0c0
movapd %xmm0, -0x60(%rbp)
movq -0x30(%rbp), %rax
incl %eax
movq %rax, -0x30(%rbp)
movl $0x2, %ebx
movq 0x20(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x8(%rax), %xmm1
movsd %xmm1, -0x50(%rbp)
movq %r12, %r15
movsd -0x8(%r12,%rbx,8), %xmm2
addsd %xmm0, %xmm2
movq %r14, %r13
movsd -0x8(%r14,%rbx,8), %xmm0
movsd %xmm0, -0x38(%rbp)
addsd %xmm1, %xmm0
movsd 0x10(%rax), %xmm1
movsd %xmm1, -0x48(%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), %r12
pushq %r12
pushq %r15
pushq %r14
movq 0x38(%rbp), %rax
pushq %rax
movq 0x30(%rbp), %r14
pushq %r14
callq 0x4756
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 %r12
pushq %r15
pushq %r13
pushq 0x38(%rbp)
pushq %r14
callq 0x4756
addq $0x30, %rsp
movsd -0x40(%rbp), %xmm2
addsd -0x78(%rbp), %xmm2
movsd -0x50(%rbp), %xmm1
movsd %xmm0, -0xc0(%rbp)
addsd %xmm0, %xmm1
addsd -0x48(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xe0(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x1, %esi
movq -0x90(%rbp), %r12
movq %r12, %rdx
movq -0x98(%rbp), %r14
movq %r14, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x50(%rbp), %rax
pushq %rax
pushq %r15
pushq %r13
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 0x496b
addq $0x40, %rsp
movsd %xmm0, -0x70(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x2, %esi
movq %r12, %rdx
movq %r14, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq %r15
pushq %r13
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x496b
addq $0x40, %rsp
movsd -0x40(%rbp), %xmm2
addsd -0x70(%rbp), %xmm2
movsd -0x50(%rbp), %xmm1
movsd %xmm0, -0xb8(%rbp)
addsd %xmm0, %xmm1
addsd -0x48(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xd8(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x1, %esi
movq -0x80(%rbp), %r12
movq %r12, %rdx
movq -0x88(%rbp), %r14
movq %r14, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x50(%rbp), %rax
pushq %rax
pushq %r15
pushq %r13
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 0x4be5
addq $0x40, %rsp
movsd %xmm0, -0x68(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x2, %esi
movq %r12, %rdx
movq %r14, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq %r15
pushq %r13
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x4be5
addq $0x40, %rsp
movsd -0x40(%rbp), %xmm2
addsd -0x68(%rbp), %xmm2
movsd -0x50(%rbp), %xmm1
movsd %xmm0, -0xb0(%rbp)
addsd %xmm0, %xmm1
addsd -0x48(%rbp), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, -0xd0(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x1, %esi
movq -0xa0(%rbp), %r14
movq %r14, %rdx
movq -0xa8(%rbp), %r12
movq %r12, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
pushq %r15
pushq %r13
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x4e51
addq $0x40, %rsp
movsd %xmm0, -0xc8(%rbp)
subq $0x8, %rsp
movl %ebx, %edi
movl $0x2, %esi
movq %r14, %rdx
movq %r12, %rcx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %r9
pushq 0x50(%rbp)
movq %r15, %r12
pushq %r15
movq %r13, %r14
pushq %r13
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
callq 0x4e51
movsd -0xd0(%rbp), %xmm6
movsd -0xc8(%rbp), %xmm5
movsd -0xd8(%rbp), %xmm4
movsd -0xe8(%rbp), %xmm2
movl $0x1, %edx
movsd -0x40(%rbp), %xmm1
addq $0x40, %rsp
addsd %xmm5, %xmm1
movsd -0x50(%rbp), %xmm3
addsd %xmm0, %xmm3
addsd -0x48(%rbp), %xmm3
divsd %xmm3, %xmm1
movsd -0xe0(%rbp), %xmm3
ucomisd %xmm3, %xmm2
jbe 0x54bd
ucomisd %xmm4, %xmm2
jbe 0x54bd
ucomisd %xmm6, %xmm2
jbe 0x54bd
ucomisd %xmm1, %xmm2
ja 0x54f1
ucomisd %xmm4, %xmm3
jbe 0x54d4
ucomisd %xmm6, %xmm3
jbe 0x54d4
movl $0x2, %edx
ucomisd %xmm1, %xmm3
ja 0x54f1
ucomisd %xmm6, %xmm4
jbe 0x54e5
movl $0x3, %edx
ucomisd %xmm1, %xmm4
ja 0x54f1
xorl %edx, %edx
ucomisd %xmm1, %xmm6
seta %dl
xorl $0x5, %edx
decl %edx
leaq 0x8b1a(%rip), %rcx      # 0xe014
movslq (%rcx,%rdx,4), %rax
addq %rcx, %rax
jmpq *%rax
movapd -0x60(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x78(%rbp), %xmm2
jmp 0x556c
movapd -0x60(%rbp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm5, %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x5582
movsd %xmm0, (%r14,%rbx,8)
movapd %xmm5, %xmm2
jmp 0x5594
movapd -0x60(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x70(%rbp), %xmm2
jmp 0x556c
movapd -0x60(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm3
mulsd %xmm3, %xmm0
movsd -0x68(%rbp), %xmm2
addsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5582
movsd %xmm3, (%r14,%rbx,8)
jmp 0x5594
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r14,%rbx,8)
movsd -0x8(%r12,%rbx,8), %xmm2
movsd %xmm2, (%r12,%rbx,8)
incq %rbx
cmpq %rbx, -0x30(%rbp)
jne 0x518a
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq