// File: /workspace/github_c_makefile_star2_O1/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 %rcx, %r12
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r14
movss 0x1d38(%rcx), %xmm0
movss %xmm0, 0x10(%rsp)
movl $0x13880, %edi          # imm = 0x13880
callq 0x595c
movq %rax, %r15
movslq %ebp, %rbp
movq (%r14,%rbp,8), %rax
movslq (%rax), %rdx
testq %rdx, %rdx
jle 0x626c
shlq $0x2, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20f0
movq (%r14,%rbp,8), %rax
movl (%rax), %ecx
cmpl $0x6, %ecx
movq %rbx, 0x20(%rsp)
movq %r12, 0x18(%rsp)
jl 0x63fe
movss 0x10(%rsp), %xmm0
addss 0x138fd(%rip), %xmm0    # 0x19b90
cvtss2sd %xmm0, %xmm3
xorl %ebx, %ebx
movq 0x68(%rax), %r12
movq (%r12,%rbx,8), %rdx
movq 0x768(%rdx), %rax
cmpl $-0x1, 0xc(%rax)
je 0x63db
cmpl $-0x1, 0x10(%rax)
je 0x63db
movq 0x8(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x63db
cmpl $-0x1, 0x10(%rax)
je 0x63db
movq 0x10(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x63db
cmpl $-0x1, 0x10(%rax)
je 0x63db
movq 0x18(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x63db
cmpl $-0x1, 0x10(%rax)
je 0x63db
movq 0x20(%r12,%rbx,8), %rsi
movq 0x768(%rsi), %rax
cmpl $-0x1, 0xc(%rax)
je 0x63db
cmpl $-0x1, 0x10(%rax)
je 0x63db
movq %r13, %rdi
movsd %xmm3, 0x10(%rsp)
callq 0xa4c5
movsd 0x13846(%rip), %xmm4    # 0x19b98
movsd 0x10(%rsp), %xmm3
cmpl $-0x1, %eax
je 0x63db
cltq
movq (%r13,%rax,8), %rax
xorps %xmm0, %xmm0
cvtss2sd 0x1c(%rax), %xmm0
movq 0x18(%rsp), %rax
xorps %xmm1, %xmm1
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
xorps %xmm0, %xmm0
cvtsd2ss %xmm2, %xmm0
movss %xmm0, (%r15,%rbx,4)
incq %rbx
movq (%r14,%rbp,8), %rax
movslq (%rax), %rcx
addq $-0x5, %rcx
cmpq %rcx, %rbx
jl 0x6299
movq 0x20(%rsp), %rbx
movq 0x18(%rsp), %r12
jmp 0x6401
addl $-0x5, %ecx
testl %ecx, %ecx
jle 0x64f3
movss 0x1d10(%r12), %xmm0
movl %ecx, %ecx
xorl %edx, %edx
movb $0x48, %sil
ucomiss (%r15,%rdx,4), %xmm0
jbe 0x64e7
ucomiss 0x4(%r15,%rdx,4), %xmm0
jbe 0x64e7
movq 0x68(%rax), %rdi
movq 0x8(%rdi,%rdx,8), %r8
movq 0x768(%r8), %r8
movb %sil, 0x1c(%r8)
movq 0x10(%rdi,%rdx,8), %r8
movq 0x768(%r8), %r8
movb %sil, 0x1c(%r8)
movq 0x18(%rdi,%rdx,8), %r8
movq 0x768(%r8), %r8
movb %sil, 0x1c(%r8)
movq 0x20(%rdi,%rdx,8), %r8
movq 0x768(%r8), %r8
movb %sil, 0x1c(%r8)
movq (%rdi,%rdx,8), %r8
movq 0x768(%r8), %r8
movslq 0xc(%r8), %r9
cmpq $-0x1, %r9
je 0x64ae
movslq 0x10(%r8), %r10
cmpq $-0x1, %r10
je 0x64ae
movq (%rbx,%r9,8), %r9
movss (%r9,%r10,4), %xmm1
ucomiss 0x1d18(%r12), %xmm1
jbe 0x64ae
movb $0x48, 0x1c(%r8)
movq 0x28(%rdi,%rdx,8), %rdi
movq 0x768(%rdi), %rdi
movslq 0xc(%rdi), %r8
cmpq $-0x1, %r8
je 0x64e7
movslq 0x10(%rdi), %r9
cmpq $-0x1, %r9
je 0x64e7
movq (%rbx,%r8,8), %r8
movss (%r8,%r9,4), %xmm1
ucomiss 0x1d1c(%r12), %xmm1
jbe 0x64e7
movb $0x48, 0x1c(%rdi)
incq %rdx
cmpq %rdx, %rcx
jne 0x641a
movq (%r14,%rbp,8), %rax
cmpl $0x5, (%rax)
jl 0x65b9
xorl %ebx, %ebx
movq 0x68(%rax), %r12
movq (%r12,%rbx,8), %rdx
movq 0x18(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0xa52c
cmpl $-0x1, %eax
je 0x65a2
movq 0x8(%r12,%rbx,8), %rdx
movq 0x20(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0xa52c
cmpl $-0x1, %eax
je 0x65a2
movq 0x8(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpb $0x48, 0x1c(%rax)
je 0x655b
movq 0x10(%r12,%rbx,8), %rcx
movq 0x768(%rcx), %rcx
cmpb $0x48, 0x1c(%rcx)
jne 0x657f
movq 0x10(%r12,%rbx,8), %rcx
movq 0x768(%rcx), %rcx
cmpb $0x48, 0x1c(%rcx)
je 0x65a2
movq 0x18(%r12,%rbx,8), %rcx
movq 0x768(%rcx), %rcx
cmpb $0x48, 0x1c(%rcx)
je 0x65a2
movb $0x47, %cl
movb %cl, 0x1c(%rax)
movq 0x10(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
movb %cl, 0x1c(%rax)
movq 0x18(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
movb %cl, 0x1c(%rax)
incq %rbx
movq (%r14,%rbp,8), %rax
movslq (%rax), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rbx
jl 0x6502
movq (%r14,%rbp,8), %rax
cmpl $0x7, (%rax)
jl 0x6685
xorl %ebx, %ebx
movq 0x68(%rax), %r12
movq (%r12,%rbx,8), %rdx
movq 0x28(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0xa52c
cmpl $-0x1, %eax
je 0x666e
movq 0x8(%r12,%rbx,8), %rdx
movq 0x30(%r12,%rbx,8), %rsi
movq %r13, %rdi
callq 0xa52c
cmpl $-0x1, %eax
je 0x666e
movq 0x8(%r12,%rbx,8), %rax
movq 0x768(%rax), %rax
cmpb $0x43, 0x1c(%rax)
jne 0x666e
movq 0x10(%r12,%rbx,8), %rcx
movq 0x768(%rcx), %rcx
cmpb $0x43, 0x1c(%rcx)
jne 0x666e
movq 0x18(%r12,%rbx,8), %rdx
movq 0x768(%rdx), %rdx
cmpb $0x43, 0x1c(%rdx)
jne 0x666e
movq 0x20(%r12,%rbx,8), %rsi
movq 0x768(%rsi), %rsi
cmpb $0x43, 0x1c(%rsi)
jne 0x666e
movq 0x28(%r12,%rbx,8), %rdi
movq 0x768(%rdi), %rdi
cmpb $0x43, 0x1c(%rdi)
jne 0x666e
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
movslq (%rax), %rcx
addq $-0x6, %rcx
cmpq %rcx, %rbx
jl 0x65c8
movq 0x18(%rsp), %rcx
cmpl $0x0, 0x1d60(%rcx)
je 0x676c
movq 0x1a932(%rip), %rbx     # 0x20fd0
movq (%rbx), %rdi
movq 0x48(%rax), %rdx
movsbl 0x40(%rax), %ecx
leaq 0x14697(%rip), %rsi     # 0x1ad47
xorl %eax, %eax
callq 0x2160
movq (%r14,%rbp,8), %rax
cmpl $0x5, (%rax)
jl 0x676c
xorl %r12d, %r12d
leaq 0x134d2(%rip), %r13     # 0x19ba0
movq 0x68(%rax), %rdi
movq (%rdi,%r12,8), %rdx
movq 0x768(%rdx), %rax
movslq 0xc(%rax), %rcx
cmpq $-0x1, %rcx
je 0x6755
movslq 0x10(%rax), %rsi
cmpq $-0x1, %rsi
je 0x6755
movq 0x20(%rdi,%r12,8), %rdi
movq 0x768(%rdi), %rdi
movslq 0xc(%rdi), %r9
cmpq $-0x1, %r9
je 0x6755
movslq 0x10(%rdi), %r10
cmpq $-0x1, %r10
je 0x6755
movq (%rbx), %rdi
xorps %xmm0, %xmm0
cvtss2sd (%r15,%r12,4), %xmm0
addq $0x4, %rdx
movq 0x20(%rsp), %r11
movq (%r11,%rcx,8), %rcx
xorps %xmm1, %xmm1
cvtss2sd (%rcx,%rsi,4), %xmm1
movsbl 0x1c(%rax), %r8d
movq (%r11,%r9,8), %rax
xorps %xmm2, %xmm2
cvtss2sd (%rax,%r10,4), %xmm2
movl %r10d, (%rsp)
movq %r13, %rsi
movl %r12d, %ecx
movb $0x3, %al
callq 0x2160
incq %r12
movq (%r14,%rbp,8), %rax
movslq (%rax), %rcx
addq $-0x4, %rcx
cmpq %rcx, %r12
jl 0x66ce
movq %r15, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
nop