// File: /workspace/github_c_makefile_star2_O2/josch[P]stride/helix.c
// Function: Helix
void Helix(CHAIN **Chain, int Cn, HBOND **HBond, COMMAND *Cmd, float **PhiPsiMap)
{

  int BondNumb, i;
  float *Prob, CONST;
  RESIDUE **r;

  CONST = 1+Cmd->C1_H;

  Prob = (float *)ckalloc(MAX_RES*sizeof(float));

  for( i=0; i<Chain[Cn]->NRes; i++ )
    Prob[i] = 0.0; 


  for( i=0; i<Chain[Cn]->NRes-5; i++ ) {

    r = &Chain[Cn]->Rsd[i];

    if( r[0]->Prop->PhiZn != ERR && r[0]->Prop->PsiZn != ERR &&
        r[1]->Prop->PhiZn != ERR && r[1]->Prop->PsiZn != ERR &&
        r[2]->Prop->PhiZn != ERR && r[2]->Prop->PsiZn != ERR &&
        r[3]->Prop->PhiZn != ERR && r[3]->Prop->PsiZn != ERR &&
        r[4]->Prop->PhiZn != ERR && r[4]->Prop->PsiZn != ERR ) {

      if( (BondNumb = FindPolInt(HBond,r[4],r[0])) != ERR ) {
	Prob[i] = HBond[BondNumb]->Energy*(CONST+Cmd->C2_H*
	    0.5*(PhiPsiMap[r[0]->Prop->PhiZn][r[0]->Prop->PsiZn]+
		 PhiPsiMap[r[4]->Prop->PhiZn][r[4]->Prop->PsiZn]));

      }
    }
  }
  
  for( i=0; i<Chain[Cn]->NRes-5; i++ ) {

    if( Prob[i] < Cmd->Treshold_H1 && Prob[i+1] < Cmd->Treshold_H1 ) {

      r = &Chain[Cn]->Rsd[i];

      r[1]->Prop->Asn = 'H'; 
      r[2]->Prop->Asn = 'H'; 
      r[3]->Prop->Asn = 'H'; 
      r[4]->Prop->Asn = 'H';
      if( r[0]->Prop->PhiZn!= ERR && r[0]->Prop->PsiZn != ERR &&
	  PhiPsiMap[r[0]->Prop->PhiZn][r[0]->Prop->PsiZn] > Cmd->Treshold_H3 )
	r[0]->Prop->Asn = 'H';
      if( r[5]->Prop->PhiZn != ERR && r[5]->Prop->PsiZn != ERR &&
	  PhiPsiMap[r[5]->Prop->PhiZn][r[5]->Prop->PsiZn] > Cmd->Treshold_H4 )
	r[5]->Prop->Asn = 'H';
    }
  }

  for( i=0; i<Chain[Cn]->NRes-4; i++ ) {

    r = &Chain[Cn]->Rsd[i];

    if(  FindBnd(HBond,r[3],r[0]) != ERR && FindBnd(HBond,r[4],r[1]) != ERR &&
       /*************************** This should be improved **************************/
         ( (r[1]->Prop->Asn != 'H' && r[2]->Prop->Asn != 'H') ||
	   (r[2]->Prop->Asn != 'H' && r[3]->Prop->Asn != 'H') ) ) 
       /******************************************************************************/
      {
	r[1]->Prop->Asn = 'G'; 
	r[2]->Prop->Asn = 'G'; 
	r[3]->Prop->Asn = 'G'; 
      }
  }

  for( i=0; i<Chain[Cn]->NRes-6; i++ ) {

    r = &Chain[Cn]->Rsd[i];

    if( FindBnd(HBond,r[5],r[0]) != ERR && FindBnd(HBond,r[6],r[1]) != ERR &&
        r[1]->Prop->Asn == 'C' && r[2]->Prop->Asn == 'C' && 
        r[3]->Prop->Asn == 'C' && r[4]->Prop->Asn == 'C' && 
        r[5]->Prop->Asn == 'C' ) {
      r[1]->Prop->Asn = 'I'; 
      r[2]->Prop->Asn = 'I';
      r[3]->Prop->Asn = 'I'; 
      r[4]->Prop->Asn = 'I'; 
      r[5]->Prop->Asn = 'I'; 
    }
  }

  if( Cmd->Info ) {
    fprintf(stdout,"%s%c\n",Chain[Cn]->File,Chain[Cn]->Id);

    for( i=0; i<Chain[Cn]->NRes-4; i++ ) {

      r = &Chain[Cn]->Rsd[i];

      if( r[0]->Prop->PhiZn != ERR && r[0]->Prop->PsiZn != ERR &&
	  r[4]->Prop->PhiZn != ERR && r[4]->Prop->PsiZn != ERR ) {
	
	fprintf(stdout,"%s (%d) %c %10.7f %8.5f %8.5f | %4d %4d\n",
		r[0]->PDB_ResNumb,i,r[0]->Prop->Asn,Prob[i],
		PhiPsiMap[r[0]->Prop->PhiZn][r[0]->Prop->PsiZn],
		PhiPsiMap[r[4]->Prop->PhiZn][r[4]->Prop->PsiZn],
		r[4]->Prop->PhiZn,r[4]->Prop->PsiZn);
      }
    }
  }
  free(Prob);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %rbx
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r14
movq %rcx, 0x10(%rsp)
movss 0x1d38(%rcx), %xmm0
movss %xmm0, 0x18(%rsp)
movl $0x13880, %edi          # imm = 0x13880
callq 0x50f4
movq %rax, %r15
movslq %ebp, %rbp
movq (%r14,%rbp,8), %rax
movl (%rax), %ecx
xorl %edx, %edx
testl %ecx, %ecx
movl $0x0, %esi
cmovgl %ecx, %esi
cmpq %rdx, %rsi
je 0x57d5
andl $0x0, (%r15,%rdx,4)
incq %rdx
jmp 0x57c6
movq %rbx, 0x20(%rsp)
movss 0x18(%rsp), %xmm0
addss 0x133b8(%rip), %xmm0    # 0x18ba0
cvtss2sd %xmm0, %xmm3
xorl %ebx, %ebx
leal -0x5(%rcx), %edx
movslq %edx, %rsi
cmpq %rsi, %rbx
jge 0x5944
movq 0x68(%rax), %r12
movq (%r12,%rbx,8), %rdx
movq 0x768(%rdx), %rax
cmpl $-0x1, 0xc(%rax)
je 0x5936
cmpl $-0x1, 0x10(%rax)
je 0x5936
movq 0x8(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x5936
cmpl $-0x1, 0x10(%rax)
je 0x5936
movq 0x10(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x5936
cmpl $-0x1, 0x10(%rax)
je 0x5936
movq 0x18(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x5936
cmpl $-0x1, 0x10(%rax)
je 0x5936
movq 0x20(%r12,%rbx,8), %rsi
movq 0x768(%rsi), %rax
cmpl $-0x1, 0xc(%rax)
je 0x5936
cmpl $-0x1, 0x10(%rax)
je 0x5936
movq %r13, %rdi
movsd %xmm3, 0x18(%rsp)
callq 0x9813
movsd 0x132f2(%rip), %xmm4    # 0x18ba8
movsd 0x18(%rsp), %xmm3
cmpl $-0x1, %eax
je 0x5936
cltq
movq (%r13,%rax,8), %rax
cvtss2sd 0x1c(%rax), %xmm0
movq 0x10(%rsp), %rax
cvtss2sd 0x1d3c(%rax), %xmm1
movq (%r12,%rbx,8), %rax
movq 0x20(%r12,%rbx,8), %rcx
movq 0x768(%rax), %rax
movslq 0xc(%rax), %rdx
movq 0x20(%rsp), %rsi
movq (%rsi,%rdx,8), %rdx
movslq 0x10(%rax), %rax
movss (%rdx,%rax,4), %xmm2
movq 0x768(%rcx), %rax
movslq 0xc(%rax), %rcx
movq (%rsi,%rcx,8), %rcx
movslq 0x10(%rax), %rax
addss (%rcx,%rax,4), %xmm2
mulsd %xmm4, %xmm1
cvtss2sd %xmm2, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm3, %xmm2
mulsd %xmm0, %xmm2
cvtsd2ss %xmm2, %xmm0
movss %xmm0, (%r15,%rbx,4)
incq %rbx
movq (%r14,%rbp,8), %rax
movl (%rax), %ecx
jmp 0x57ee
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
movb $0x48, %dil
movq 0x20(%rsp), %rbx
cmpq %rsi, %rdx
je 0x5a48
movq 0x10(%rsp), %r8
movss 0x1d10(%r8), %xmm0
ucomiss (%r15,%rsi,4), %xmm0
jbe 0x5a40
ucomiss 0x4(%r15,%rsi,4), %xmm0
jbe 0x5a40
movq 0x68(%rax), %r8
movq 0x8(%r8,%rsi,8), %r9
movq 0x768(%r9), %r9
movb %dil, 0x1c(%r9)
movq 0x10(%r8,%rsi,8), %r9
movq 0x768(%r9), %r9
movb %dil, 0x1c(%r9)
movq 0x18(%r8,%rsi,8), %r9
movq 0x768(%r9), %r9
movb %dil, 0x1c(%r9)
movq 0x20(%r8,%rsi,8), %r9
movq 0x768(%r9), %r9
movb %dil, 0x1c(%r9)
movq (%r8,%rsi,8), %r9
movq 0x768(%r9), %r9
movslq 0xc(%r9), %r10
cmpq $-0x1, %r10
je 0x5a02
movslq 0x10(%r9), %r11
cmpq $-0x1, %r11
je 0x5a02
movq (%rbx,%r10,8), %r10
movss (%r10,%r11,4), %xmm0
movq 0x10(%rsp), %r10
ucomiss 0x1d18(%r10), %xmm0
jbe 0x5a02
movb $0x48, 0x1c(%r9)
movq 0x28(%r8,%rsi,8), %r8
movq 0x768(%r8), %r8
movslq 0xc(%r8), %r9
cmpq $-0x1, %r9
je 0x5a40
movslq 0x10(%r8), %r10
cmpq $-0x1, %r10
je 0x5a40
movq (%rbx,%r9,8), %r9
movss (%r9,%r10,4), %xmm0
movq 0x10(%rsp), %r9
ucomiss 0x1d1c(%r9), %xmm0
jbe 0x5a40
movb $0x48, 0x1c(%r8)
incq %rsi
jmp 0x5953
xorl %ebx, %ebx
leal -0x4(%rcx), %edx
movslq %edx, %rdx
cmpq %rdx, %rbx
jge 0x5af2
movq 0x68(%rax), %r12
movq (%r12,%rbx,8), %rdx
movq 0x18(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0x987f
cmpl $-0x1, %eax
je 0x5ae4
movq 0x8(%r12,%rbx,8), %rdx
movq 0x20(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0x987f
cmpl $-0x1, %eax
je 0x5ae4
movq 0x8(%r12,%rbx,8), %rax
movq 0x10(%r12,%rbx,8), %rcx
movq 0x768(%rax), %rax
cmpb $0x48, 0x1c(%rax)
movq 0x768(%rcx), %rcx
movb 0x1c(%rcx), %dl
jne 0x5ac4
cmpb $0x48, %dl
je 0x5ae4
movq 0x18(%r12,%rbx,8), %rdx
movq 0x768(%rdx), %rdx
cmpb $0x48, 0x1c(%rdx)
jne 0x5ad5
jmp 0x5ae4
cmpb $0x48, %dl
je 0x5ae4
movq 0x18(%r12,%rbx,8), %rdx
movq 0x768(%rdx), %rdx
movb $0x47, %sil
movb %sil, 0x1c(%rax)
movb %sil, 0x1c(%rcx)
movb %sil, 0x1c(%rdx)
incq %rbx
movq (%r14,%rbp,8), %rax
movl (%rax), %ecx
jmp 0x5a4a
xorl %ebx, %ebx
addl $-0x6, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jge 0x5bb7
movq 0x68(%rax), %r12
movq (%r12,%rbx,8), %rdx
movq 0x28(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0x987f
cmpl $-0x1, %eax
je 0x5ba9
movq 0x8(%r12,%rbx,8), %rdx
movq 0x30(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0x987f
cmpl $-0x1, %eax
je 0x5ba9
movq 0x8(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpb $0x43, 0x1c(%rax)
jne 0x5ba9
movq 0x10(%r12,%rbx,8), %rcx
movq 0x768(%rcx), %rcx
cmpb $0x43, 0x1c(%rcx)
jne 0x5ba9
movq 0x18(%r12,%rbx,8), %rdx
movq 0x768(%rdx), %rdx
cmpb $0x43, 0x1c(%rdx)
jne 0x5ba9
movq 0x20(%r12,%rbx,8), %rsi
movq 0x768(%rsi), %rsi
cmpb $0x43, 0x1c(%rsi)
jne 0x5ba9
movq 0x28(%r12,%rbx,8), %rdi
movq 0x768(%rdi), %rdi
cmpb $0x43, 0x1c(%rdi)
jne 0x5ba9
movb $0x49, %r8b
movb %r8b, 0x1c(%rax)
movb %r8b, 0x1c(%rcx)
movb %r8b, 0x1c(%rdx)
movb %r8b, 0x1c(%rsi)
movb %r8b, 0x1c(%rdi)
incq %rbx
movq (%r14,%rbp,8), %rax
movl (%rax), %ecx
jmp 0x5af4
movq 0x10(%rsp), %rcx
cmpl $0x0, 0x1d60(%rcx)
je 0x5c8d
movq 0x1a400(%rip), %rbx     # 0x1ffd0
movq (%rbx), %rdi
movq 0x48(%rax), %rdx
movsbl 0x40(%rax), %ecx
leaq 0x14105(%rip), %rsi     # 0x19ce7
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x2160
leaq 0x12fbd(%rip), %r13     # 0x18bb0
movq (%r14,%rbp,8), %rax
movslq (%rax), %rcx
addq $-0x4, %rcx
cmpq %rcx, %r12
jge 0x5c8d
movq 0x68(%rax), %rdi
movq (%rdi,%r12,8), %rdx
movq 0x768(%rdx), %rax
movslq 0xc(%rax), %rcx
cmpq $-0x1, %rcx
je 0x5c85
movslq 0x10(%rax), %rsi
cmpq $-0x1, %rsi
je 0x5c85
movq 0x20(%rdi,%r12,8), %rdi
movq 0x768(%rdi), %rdi
movslq 0xc(%rdi), %r9
cmpq $-0x1, %r9
je 0x5c85
movslq 0x10(%rdi), %r10
cmpq $-0x1, %r10
je 0x5c85
movq (%rbx), %rdi
cvtss2sd (%r15,%r12,4), %xmm0
addq $0x4, %rdx
movq 0x20(%rsp), %r11
movq (%r11,%rcx,8), %rcx
cvtss2sd (%rcx,%rsi,4), %xmm1
movsbl 0x1c(%rax), %r8d
movq (%r11,%r9,8), %rax
cvtss2sd (%rax,%r10,4), %xmm2
movl %r10d, (%rsp)
movq %r13, %rsi
movl %r12d, %ecx
movb $0x3, %al
callq 0x2160
incq %r12
jmp 0x5bf3
movq %r15, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
nop