// File: /workspace/github_c_makefile_star2_O1/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 0x3f81
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), %r12
movl (%r12), %r14d
cmpl %edi, %r14d
jl 0x3fc5
cmpl %esi, 0x4(%r12)
jge 0x3fc5
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%rdx)
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rdx)
jmp 0x430b
movq 0xa0(%rbp), %r10
movl 0x4(%r12), %ebx
xorl %r15d, %r15d
cmpl %edi, %ebx
cmovgel %r15d, %ebx
cmovgel %r15d, %r14d
subl %r14d, %edi
cmpl $0x1e, %r11d
jg 0x3ffc
leal -0x1(%r11), %r14d
movsd (%r9,%r14,8), %xmm0
movsd %xmm0, 0x8(%rdx)
leaq (%r8,%r14,8), %r8
jmp 0x4011
movsd 0xe8(%r9), %xmm0
movsd %xmm0, 0x8(%rdx)
addq $0xe8, %r8
subl %ebx, %esi
movsd (%r8), %xmm0
movsd %xmm0, (%rdx)
movslq %edi, %rax
leaq (%r10,%rax), %r8
movq %rax, -0x30(%rbp)
movsbq (%r10,%rax), %r15
cmpl $0x3, %r11d
jne 0x4063
movq 0x78(%rbp), %rax
movq 0x70(%rbp), %r14
movslq %esi, %r9
leaq (%r10,%r9), %rbx
movsbq (%r10,%r9), %r9
leaq (%r15,%r15,4), %r15
leaq (%rax,%r15,8), %rax
movsd (%rax,%r9,8), %xmm1
addsd 0x8(%rdx), %xmm1
movsd %xmm1, 0x8(%rdx)
movq %r8, %r15
jmp 0x40d0
movq %r12, %r14
movsbq 0x1(%r8), %r12
movslq %esi, %r13
leaq (%r10,%r13), %rbx
decq %rbx
movsbq 0x1(%rbx), %rax
imulq $0x3e8, %r15, %r15      # imm = 0x3E8
addq 0x18(%rbp), %r15
movsbq (%rbx), %r9
imulq $0xc8, %r12, %r12
addq %r15, %r12
leaq (%rax,%rax,4), %rax
leaq (%r12,%rax,8), %rax
movq %r14, %r12
movsd (%rax,%r9,8), %xmm1
addsd 0x8(%rdx), %xmm1
leaq (%r10,%r13), %r15
movsd %xmm1, 0x8(%rdx)
movsbq (%r8), %rax
movsbq 0x1(%r8), %r9
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
addq 0x10(%rbp), %rax
imulq $0xc8, %r9, %r14
addq %rax, %r14
movsbq (%rbx), %rax
movsbq (%r15), %r9
leaq (%r9,%r9,4), %r9
leaq (%r14,%r9,8), %r9
addsd (%r9,%rax,8), %xmm0
movsd %xmm0, (%rdx)
cmpl $0x4, %r11d
je 0x413c
cmpl $0x3, %r11d
jne 0x425e
movl 0x60(%rbp), %r14d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl %r14d, %ebx
testl %r14d, %r14d
jle 0x4184
movq %r12, %r9
movq 0x28(%rbp), %r12
xorl %r15d, %r15d
xorl %r13d, %r13d
movb (%r8,%r13), %al
cmpb (%r12,%r13), %al
jne 0x412e
incq %r13
cmpq $0x5, %r13
jne 0x4119
jmp 0x417e
incq %r15
addq $0x5, %r12
cmpq %rbx, %r15
jne 0x4116
jmp 0x4181
movl 0x68(%rbp), %r10d
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl %r10d, %r9d
testl %r10d, %r10d
jle 0x41ef
movq 0x38(%rbp), %r14
xorl %ebx, %ebx
xorl %r15d, %r15d
movb (%r8,%r15), %al
cmpb (%r14,%r15), %al
jne 0x4170
incq %r15
cmpq $0x6, %r15
jne 0x415b
jmp 0x41ec
incq %rbx
addq $0x6, %r14
cmpq %r9, %rbx
jne 0x4158
jmp 0x41ef
movl %r15d, %r11d
movq %r9, %r12
cmpl $-0x1, %r11d
je 0x41a1
movq 0x48(%rbp), %rax
movslq %r11d, %r8
movsd (%rax,%r8,8), %xmm1
addsd 0x8(%rdx), %xmm1
movsd %xmm1, 0x8(%rdx)
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
testl %r14d, %r14d
jle 0x41e0
movq 0x20(%rbp), %r8
addq -0x30(%rbp), %r10
xorl %r9d, %r9d
xorl %r14d, %r14d
movb (%r10,%r14), %al
cmpb (%r8,%r14), %al
jne 0x41cf
incq %r14
cmpq $0x5, %r14
jne 0x41ba
jmp 0x41dd
incq %r9
addq $0x5, %r8
cmpq %rbx, %r9
jne 0x41b7
jmp 0x41e0
movl %r9d, %r11d
cmpl $-0x1, %r11d
je 0x425e
movq 0x40(%rbp), %r8
jmp 0x4251
movl %ebx, %r11d
cmpl $-0x1, %r11d
je 0x420c
movq 0x58(%rbp), %rax
movslq %r11d, %r11
movsd (%rax,%r11,8), %xmm1
addsd 0x8(%rdx), %xmm1
movsd %xmm1, 0x8(%rdx)
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
testl %r10d, %r10d
jle 0x4247
movq 0x30(%rbp), %rbx
xorl %r10d, %r10d
xorl %r14d, %r14d
movb (%r8,%r14), %al
cmpb (%rbx,%r14), %al
jne 0x4236
incq %r14
cmpq $0x6, %r14
jne 0x4221
jmp 0x4244
incq %r10
addq $0x6, %rbx
cmpq %r9, %r10
jne 0x421e
jmp 0x4247
movl %r10d, %r11d
cmpl $-0x1, %r11d
je 0x425e
movq 0x50(%rbp), %r8
movslq %r11d, %rax
addsd (%r8,%rax,8), %xmm0
movsd %xmm0, (%rdx)
movsd 0x8(%rdx), %xmm0
andpd 0x9e45(%rip), %xmm0     # 0xe0b0
ucomisd 0x9dbd(%rip), %xmm0     # 0xe030
jbe 0x4290
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
movq %rax, 0x8(%rdx)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%rdx)
testl %ecx, %ecx
jne 0x430b
movq 0x98(%rbp), %r8
movq 0x90(%rbp), %rcx
movq 0x80(%rbp), %rax
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm2
movsd 0x8(%rdx), %xmm3
addsd %xmm1, %xmm3
movsd (%rdx), %xmm0
addsd %xmm2, %xmm0
movsd 0x10(%rax), %xmm4
addsd %xmm4, %xmm0
divsd %xmm0, %xmm3
decl %edi
imull 0x8(%r12), %edi
addl %esi, %edi
movslq %edi, %rax
addsd -0x8(%rcx,%rax,8), %xmm1
movsd -0x8(%r8,%rax,8), %xmm0
addsd %xmm0, %xmm2
addsd %xmm4, %xmm2
divsd %xmm2, %xmm1
ucomisd %xmm3, %xmm1
jbe 0x430b
movsd %xmm0, (%rdx)
movsd -0x8(%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rdx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq