// File: /workspace/github_c_makefile_star2_O2/jiqingxiaoxi[P]RPA/RPA.c
// Function: calc_hairpin
void calc_hairpin(int i,int j,double *EntropyEnthalpy,int traceback,double hairpinLoopEntropies[],double hairpinLoopEnthalpies[],double tstack2Entropies[],double tstack2Enthalpies[],char *triloopEntropies1,char *triloopEnthalpies1,char *tetraloopEntropies1,char *tetraloopEnthalpies1,double *triloopEntropies2,double *triloopEnthalpies2,double *tetraloopEntropies2,double *tetraloopEnthalpies2,int numTriloops,int numTetraloops,double atpS[],double atpH[],double Initdouble[],int Initint[],double enthalpyDPT[],double entropyDPT[],char numSeq1[])
{
	int pos,loopSize=j-i-1;
	double T1,T2;
	
	if(loopSize < 3)
	{
		EntropyEnthalpy[0]=-1.0;
		EntropyEnthalpy[1]=1.0*INFINITY;
		return;
	}
	if(i<=Initint[0]&&Initint[1]<j)
	{
		EntropyEnthalpy[0]=-1.0;
		EntropyEnthalpy[1]=1.0*INFINITY;
		return;
	}
	else if(i>Initint[1])
	{
		i-= Initint[0];
		j-= Initint[1];
	}
	if(loopSize<=30)
	{
		EntropyEnthalpy[1]=hairpinLoopEnthalpies[loopSize-1];
		EntropyEnthalpy[0]=hairpinLoopEntropies[loopSize-1];
	}
	else
	{
		EntropyEnthalpy[1]=hairpinLoopEnthalpies[29];
		EntropyEnthalpy[0]=hairpinLoopEntropies[29];
	}

	if(loopSize>3) // for loops 4 bp and more in length, terminal mm are accounted
	{
		EntropyEnthalpy[1]+=tstack2Enthalpies[numSeq1[i]*125+numSeq1[i+1]*25+numSeq1[j]*5+numSeq1[j-1]];
		EntropyEnthalpy[0]+=tstack2Entropies[numSeq1[i]*125+numSeq1[i+1]*25+numSeq1[j]*5+numSeq1[j-1]];
	}
	else if(loopSize == 3) // for loops 3 bp in length at-penalty is considered
	{
		EntropyEnthalpy[1]+=atpH[numSeq1[i]*5+numSeq1[j]];
		EntropyEnthalpy[0]+=atpS[numSeq1[i]*5+numSeq1[j]];
	}

	if(loopSize==3) // closing AT-penalty (+), triloop bonus, hairpin of 3 (+) 
	{
		pos=find_pos(numSeq1,i,triloopEnthalpies1,5,numTriloops);
		if(pos!=-1)
			EntropyEnthalpy[1]+=triloopEnthalpies2[pos];

		pos=find_pos(numSeq1,i,triloopEntropies1,5,numTriloops);
		if(pos!=-1)
			EntropyEnthalpy[0]+=triloopEntropies2[pos];
	}
	else if (loopSize == 4) // terminal mismatch, tetraloop bonus, hairpin of 4
	{
		pos=find_pos(numSeq1,i,tetraloopEnthalpies1,6,numTetraloops);
		if(pos!=-1)
			EntropyEnthalpy[1]+=tetraloopEnthalpies2[pos];

		pos=find_pos(numSeq1,i,tetraloopEntropies1,6,numTetraloops);
		if(pos!=-1)
			EntropyEnthalpy[0]+=tetraloopEntropies2[pos];
	}
	if(fabs(EntropyEnthalpy[1])>999999999)
	{
		EntropyEnthalpy[1] =1.0*INFINITY;
		EntropyEnthalpy[0] = -1.0;
	}
	T1 = (EntropyEnthalpy[1] +Initdouble[0]) / ((EntropyEnthalpy[0] +Initdouble[1]+ Initdouble[2]));
	T2 = (enthalpyDPT[(i-1)*Initint[2]+j-1] +Initdouble[0]) / ((entropyDPT[(i-1)*Initint[2]+j-1]) +Initdouble[1]+ Initdouble[2]);
	if(T1 < T2 && traceback == 0)
	{
		EntropyEnthalpy[0] =entropyDPT[(i-1)*Initint[2]+j-1];
		EntropyEnthalpy[1] =enthalpyDPT[(i-1)*Initint[2]+j-1];
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movl %edi, %eax
notl %eax
addl %esi, %eax
cmpl $0x2, %eax
jle 0x3d7f
movl %ecx, %r12d
movl %esi, %r15d
movl %edi, %r14d
movq 0x88(%rbp), %r10
movl (%r10), %ecx
movl 0x4(%r10), %edx
cmpl %edi, %ecx
setge %sil
cmpl %r15d, %edx
setl %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x3da9
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%rbx)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %esi, %esi
cmpl %r14d, %edx
cmovgel %esi, %edx
cmovgel %esi, %ecx
movq 0xa0(%rbp), %r13
subl %edx, %r15d
subl %ecx, %r14d
cmpl $0x1f, %eax
jae 0x3e97
leal -0x1(%rax), %ecx
movsd (%r9,%rcx,8), %xmm4
movsd %xmm4, 0x8(%rbx)
movsd (%r8,%rcx,8), %xmm5
movsd %xmm5, (%rbx)
cmpl $0x3, %eax
jne 0x3eb2
movq 0x70(%rbp), %rax
movl 0x60(%rbp), %r8d
movq 0x28(%rbp), %rdx
movslq %r14d, %rcx
movsbq (%r13,%rcx), %rsi
movslq %r15d, %rdi
movsbq (%r13,%rdi), %r9
imulq $0x28, %rsi, %rsi
addq 0x78(%rbp), %rsi
addsd (%rsi,%r9,8), %xmm4
movapd %xmm4, -0x40(%rbp)
movsd %xmm4, 0x8(%rbx)
movsbq (%r13,%rcx), %rcx
movsbq (%r13,%rdi), %rsi
imulq $0x28, %rcx, %rcx
addq %rax, %rcx
addsd (%rcx,%rsi,8), %xmm5
movsd %xmm5, -0x30(%rbp)
movsd %xmm5, (%rbx)
pushq $0x5
popq %rcx
movq %r13, %rdi
movl %r14d, %esi
callq 0x3ce1
cmpl $-0x1, %eax
je 0x3e6f
movq 0x48(%rbp), %rcx
cltq
movapd -0x40(%rbp), %xmm0
addsd (%rcx,%rax,8), %xmm0
movapd %xmm0, -0x40(%rbp)
movsd %xmm0, 0x8(%rbx)
pushq $0x5
popq %rcx
movq %r13, %rdi
movl %r14d, %esi
movq 0x20(%rbp), %rdx
movl 0x60(%rbp), %r8d
callq 0x3ce1
cmpl $-0x1, %eax
je 0x3fbc
movq 0x40(%rbp), %rcx
jmp 0x3f9e
movsd 0xe8(%r9), %xmm4
movsd %xmm4, 0x8(%rbx)
movsd 0xe8(%r8), %xmm5
movsd %xmm5, (%rbx)
movslq %r14d, %rcx
movsbq (%r13,%rcx), %rdx
movsbq 0x1(%r13,%rcx), %rsi
movslq %r15d, %rdi
movsbq (%r13,%rdi), %r8
movsbq -0x1(%r13,%rdi), %r9
imulq $0x3e8, %rdx, %rdx      # imm = 0x3E8
addq 0x18(%rbp), %rdx
imulq $0xc8, %rsi, %rsi
imulq $0x28, %r8, %r8
addq %rsi, %r8
addq %rdx, %r8
addsd (%r8,%r9,8), %xmm4
movq 0x10(%rbp), %rdx
movsd %xmm4, 0x8(%rbx)
movsbq (%r13,%rcx), %rsi
movsbq 0x1(%r13,%rcx), %rcx
movsbq (%r13,%rdi), %r8
movsbq -0x1(%r13,%rdi), %rdi
imulq $0x3e8, %rsi, %rsi      # imm = 0x3E8
addq %rdx, %rsi
imulq $0xc8, %rcx, %rcx
imulq $0x28, %r8, %rdx
addq %rcx, %rdx
addq %rsi, %rdx
addsd (%rdx,%rdi,8), %xmm5
movsd %xmm5, (%rbx)
cmpl $0x4, %eax
jne 0x3fcd
movsd %xmm5, -0x30(%rbp)
movapd %xmm4, -0x40(%rbp)
movl 0x68(%rbp), %r8d
movq 0x38(%rbp), %rdx
pushq $0x6
popq %rcx
movq %r13, %rdi
movl %r14d, %esi
callq 0x3ce1
cmpl $-0x1, %eax
je 0x3f7f
movq 0x58(%rbp), %rcx
cltq
movapd -0x40(%rbp), %xmm0
addsd (%rcx,%rax,8), %xmm0
movapd %xmm0, -0x40(%rbp)
movsd %xmm0, 0x8(%rbx)
pushq $0x6
popq %rcx
movq %r13, %rdi
movl %r14d, %esi
movq 0x30(%rbp), %rdx
movl 0x68(%rbp), %r8d
callq 0x3ce1
cmpl $-0x1, %eax
je 0x3fbc
movq 0x50(%rbp), %rcx
movq 0x88(%rbp), %r10
movapd -0x40(%rbp), %xmm4
movsd -0x30(%rbp), %xmm5
cltq
addsd (%rcx,%rax,8), %xmm5
movsd %xmm5, (%rbx)
jmp 0x3fcd
movq 0x88(%rbp), %r10
movapd -0x40(%rbp), %xmm4
movsd -0x30(%rbp), %xmm5
movapd 0x910b(%rip), %xmm0     # 0xd0e0
andpd %xmm4, %xmm0
ucomisd 0x904f(%rip), %xmm0     # 0xd030
jbe 0x400e
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rbx)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%rbx)
movsd 0x9022(%rip), %xmm4     # 0xd028
movsd 0x9032(%rip), %xmm5     # 0xd040
testl %r12d, %r12d
jne 0x3d9a
movq 0x98(%rbp), %rdx
movq 0x90(%rbp), %rax
movq 0x80(%rbp), %rcx
movsd (%rcx), %xmm1
movsd 0x8(%rcx), %xmm2
addsd %xmm1, %xmm4
addsd %xmm2, %xmm5
movsd 0x10(%rcx), %xmm3
addsd %xmm3, %xmm5
divsd %xmm5, %xmm4
decl %r14d
imull 0x8(%r10), %r14d
addl %r15d, %r14d
movslq %r14d, %rcx
addsd -0x8(%rax,%rcx,8), %xmm1
movsd -0x8(%rdx,%rcx,8), %xmm0
addsd %xmm0, %xmm2
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
ucomisd %xmm4, %xmm1
jbe 0x3d9a
movsd %xmm0, (%rbx)
movsd -0x8(%rax,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rbx)
jmp 0x3d9a