// File: /workspace/github_c_makefile_star2_O3/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:
movl %edi, %r11d
notl %r11d
addl %esi, %r11d
cmpl $0x2, %r11d
jg 0x3ecf
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%rdx)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rdx)
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x88(%rbp), %rax
movl (%rax), %ebx
movl 0x4(%rax), %r14d
cmpl %edi, %ebx
setge %r10b
cmpl %esi, %r14d
setl %r15b
andb %r10b, %r15b
cmpb $0x1, %r15b
jne 0x3f1f
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%rdx)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rdx)
jmp 0x4229
xorl %r10d, %r10d
cmpl %edi, %r14d
cmovgel %r10d, %r14d
cmovgel %r10d, %ebx
movq 0xa0(%rbp), %r10
subl %r14d, %esi
subl %ebx, %edi
cmpl $0x1f, %r11d
jae 0x3ffc
leal -0x1(%r11), %ebx
movsd (%r9,%rbx,8), %xmm0
movsd %xmm0, 0x8(%rdx)
movsd (%r8,%rbx,8), %xmm1
movsd %xmm1, (%rdx)
cmpl $0x3, %r11d
jne 0x4017
movq 0x78(%rbp), %r8
movq 0x70(%rbp), %r9
movl 0x60(%rbp), %ebx
movslq %edi, %r15
movsbq (%r10,%r15), %r11
movslq %esi, %r14
movsbq (%r10,%r14), %r12
leaq (%r11,%r11,4), %r11
leaq (%r8,%r11,8), %r8
addsd (%r8,%r12,8), %xmm0
movsd %xmm0, 0x8(%rdx)
movsbq (%r10,%r15), %r8
movsbq (%r10,%r14), %r11
leaq (%r8,%r8,4), %r8
leaq (%r9,%r8,8), %r8
addsd (%r8,%r11,8), %xmm1
movsd %xmm1, (%rdx)
testl %ebx, %ebx
jle 0x4175
movq 0x48(%rbp), %r11
movq 0x40(%rbp), %r8
movq 0x28(%rbp), %r14
movq 0x20(%rbp), %r9
addq %r15, %r10
movl %ebx, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
movb (%r10,%r12), %r13b
cmpb (%r14,%r12), %r13b
jne 0x3feb
incq %r12
cmpq $0x5, %r12
jne 0x3fd3
jmp 0x4131
incq %r15
addq $0x5, %r14
cmpq %rbx, %r15
jne 0x3fd0
jmp 0x413f
movsd 0xe8(%r9), %xmm0
movsd %xmm0, 0x8(%rdx)
movsd 0xe8(%r8), %xmm1
movsd %xmm1, (%rdx)
movl 0x68(%rbp), %ebx
movslq %edi, %r14
movsbq (%r10,%r14), %r8
movsbq 0x1(%r10,%r14), %r9
movslq %esi, %r15
movsbq (%r10,%r15), %r12
movsbq -0x1(%r10,%r15), %r13
imulq $0x3e8, %r8, %r8        # imm = 0x3E8
addq 0x18(%rbp), %r8
imulq $0xc8, %r9, %r9
addq %r8, %r9
leaq (%r12,%r12,4), %r8
leaq (%r9,%r8,8), %r8
addsd (%r8,%r13,8), %xmm0
movq 0x10(%rbp), %r8
movsd %xmm0, 0x8(%rdx)
movsbq (%r10,%r14), %r9
movsbq 0x1(%r10,%r14), %r12
movsbq (%r10,%r15), %r13
movsbq -0x1(%r10,%r15), %r15
imulq $0x3e8, %r9, %r9        # imm = 0x3E8
addq %r8, %r9
imulq $0xc8, %r12, %r8
addq %r9, %r8
leaq (,%r13,4), %r9
addq %r13, %r9
leaq (%r8,%r9,8), %r8
addsd (%r8,%r15,8), %xmm1
movsd %xmm1, (%rdx)
cmpl $0x4, %r11d
sete %r8b
testl %ebx, %ebx
setg %r9b
testb %r9b, %r8b
je 0x4175
movq 0x58(%rbp), %r11
movq 0x50(%rbp), %r8
movq 0x38(%rbp), %r15
movq 0x30(%rbp), %r9
addq %r14, %r10
movl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
movb (%r10,%r12), %r13b
cmpb (%r15,%r12), %r13b
jne 0x40ec
incq %r12
cmpq $0x6, %r12
jne 0x40d7
jmp 0x40fa
incq %r14
addq $0x6, %r15
cmpq %rbx, %r14
jne 0x40d4
jmp 0x4108
movslq %r14d, %r14
addsd (%r11,%r14,8), %xmm0
movsd %xmm0, 0x8(%rdx)
xorl %r11d, %r11d
xorl %r14d, %r14d
movb (%r10,%r14), %r15b
cmpb (%r9,%r14), %r15b
jne 0x4123
incq %r14
cmpq $0x6, %r14
jne 0x410e
jmp 0x4168
incq %r11
addq $0x6, %r9
cmpq %rbx, %r11
jne 0x410b
jmp 0x4175
movslq %r15d, %r14
addsd (%r11,%r14,8), %xmm0
movsd %xmm0, 0x8(%rdx)
xorl %r11d, %r11d
xorl %r14d, %r14d
movb (%r10,%r14), %r15b
cmpb (%r9,%r14), %r15b
jne 0x415a
incq %r14
cmpq $0x5, %r14
jne 0x4145
jmp 0x4168
incq %r11
addq $0x5, %r9
cmpq %rbx, %r11
jne 0x4142
jmp 0x4175
movslq %r11d, %r9
addsd (%r8,%r9,8), %xmm1
movsd %xmm1, (%rdx)
movapd 0x9f43(%rip), %xmm2     # 0xe0c0
andpd %xmm0, %xmm2
ucomisd 0x9e97(%rip), %xmm2     # 0xe020
jbe 0x41b6
movabsq $0x7ff0000000000000, %r8 # imm = 0x7FF0000000000000
movq %r8, 0x8(%rdx)
movabsq $-0x4010000000000000, %r8 # imm = 0xBFF0000000000000
movq %r8, (%rdx)
movsd 0x9e6a(%rip), %xmm0     # 0xe018
movsd 0x9e7a(%rip), %xmm1     # 0xe030
testl %ecx, %ecx
jne 0x4229
movq 0x98(%rbp), %r8
movq 0x90(%rbp), %rcx
movq 0x80(%rbp), %r9
movsd (%r9), %xmm2
movsd 0x8(%r9), %xmm3
addsd %xmm2, %xmm0
addsd %xmm3, %xmm1
movsd 0x10(%r9), %xmm4
addsd %xmm4, %xmm1
divsd %xmm1, %xmm0
decl %edi
imull 0x8(%rax), %edi
addl %esi, %edi
movslq %edi, %rax
addsd -0x8(%rcx,%rax,8), %xmm2
movsd -0x8(%r8,%rax,8), %xmm1
addsd %xmm1, %xmm3
addsd %xmm4, %xmm3
divsd %xmm3, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x4229
movsd %xmm1, (%rdx)
movsd -0x8(%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rdx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq