// File: /workspace/github_c_makefile_star2_O3/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, 0x20(%rsp)
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r14
movq %rcx, 0x8(%rsp)
movss 0x1d38(%rcx), %xmm0
movss %xmm0, 0x18(%rsp)
movl $0x13880, %edi          # imm = 0x13880
callq 0x5880
movslq %ebp, %rbp
movq (%r14,%rbp,8), %rbx
movslq (%rbx), %r12
testq %r12, %r12
movq %rax, 0x10(%rsp)
jle 0x65a5
movq %r12, %rdx
shlq $0x2, %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x20f0
cmpl $0x6, %r12d
jb 0x642d
movss 0x18(%rsp), %xmm0
addss 0x139df(%rip), %xmm0    # 0x19ba0
cvtss2sd %xmm0, %xmm3
xorl %r15d, %r15d
movq 0x68(%rbx), %rbx
movq (%rbx,%r15,8), %rdx
movq 0x768(%rdx), %rax
cmpl $-0x1, 0xc(%rax)
je 0x6313
cmpl $-0x1, 0x10(%rax)
je 0x6313
movq 0x8(%rbx,%r15,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x6313
cmpl $-0x1, 0x10(%rax)
je 0x6313
movq 0x10(%rbx,%r15,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x6313
cmpl $-0x1, 0x10(%rax)
je 0x6313
movq 0x18(%rbx,%r15,8), %rax
movq 0x768(%rax), %rax
cmpl $-0x1, 0xc(%rax)
je 0x6313
cmpl $-0x1, 0x10(%rax)
je 0x6313
movq 0x20(%rbx,%r15,8), %rsi
movq 0x768(%rsi), %rax
cmpl $-0x1, 0xc(%rax)
je 0x6313
cmpl $-0x1, 0x10(%rax)
je 0x6313
movq %r13, %rdi
movsd %xmm3, 0x18(%rsp)
callq 0xa3cd
movsd 0x13927(%rip), %xmm4    # 0x19ba8
movsd 0x18(%rsp), %xmm3
cmpl $-0x1, %eax
je 0x6313
cltq
movq (%r13,%rax,8), %rax
xorps %xmm0, %xmm0
cvtss2sd 0x1c(%rax), %xmm0
movq 0x8(%rsp), %rax
xorps %xmm1, %xmm1
cvtss2sd 0x1d3c(%rax), %xmm1
movq (%rbx,%r15,8), %rax
movq 0x20(%rbx,%r15,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
movq 0x10(%rsp), %rax
movss %xmm0, (%rax,%r15,4)
incq %r15
movq (%r14,%rbp,8), %rbx
movslq (%rbx), %r12
leaq -0x5(%r12), %rax
cmpq %rax, %r15
jl 0x61c8
cmpl $0x6, %r12d
jl 0x642d
movq 0x8(%rsp), %rcx
movss 0x1d10(%rcx), %xmm0
movl %eax, %eax
xorl %ecx, %ecx
movb $0x48, %dl
movq 0x20(%rsp), %r10
movq 0x10(%rsp), %r15
ucomiss (%r15,%rcx,4), %xmm0
jbe 0x6421
ucomiss 0x4(%r15,%rcx,4), %xmm0
jbe 0x6421
movq 0x68(%rbx), %rsi
movq 0x8(%rsi,%rcx,8), %rdi
movq 0x768(%rdi), %rdi
movb %dl, 0x1c(%rdi)
movq 0x10(%rsi,%rcx,8), %rdi
movq 0x768(%rdi), %rdi
movb %dl, 0x1c(%rdi)
movq 0x18(%rsi,%rcx,8), %rdi
movq 0x768(%rdi), %rdi
movb %dl, 0x1c(%rdi)
movq 0x20(%rsi,%rcx,8), %rdi
movq 0x768(%rdi), %rdi
movb %dl, 0x1c(%rdi)
movq (%rsi,%rcx,8), %rdi
movq 0x768(%rdi), %rdi
movslq 0xc(%rdi), %r8
cmpq $-0x1, %r8
je 0x63e5
movslq 0x10(%rdi), %r9
cmpq $-0x1, %r9
je 0x63e5
movq (%r10,%r8,8), %r8
movss (%r8,%r9,4), %xmm1
movq 0x8(%rsp), %r8
ucomiss 0x1d18(%r8), %xmm1
jbe 0x63e5
movb $0x48, 0x1c(%rdi)
movq 0x28(%rsi,%rcx,8), %rsi
movq 0x768(%rsi), %rsi
movslq 0xc(%rsi), %rdi
cmpq $-0x1, %rdi
je 0x6421
movslq 0x10(%rsi), %r8
cmpq $-0x1, %r8
je 0x6421
movq (%r10,%rdi,8), %rdi
movss (%rdi,%r8,4), %xmm1
movq 0x8(%rsp), %rdi
ucomiss 0x1d1c(%rdi), %xmm1
jbe 0x6421
movb $0x48, 0x1c(%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0x6352
cmpl $0x5, %r12d
jl 0x65a5
xorl %r15d, %r15d
movb $0x47, %r12b
movq 0x68(%rbx), %rbx
movq (%rbx,%r15,8), %rdx
movq 0x18(%rbx,%r15,8), %rsi
movq %r13, %rdi
callq 0xa434
cmpl $-0x1, %eax
je 0x64c5
movq 0x8(%rbx,%r15,8), %rdx
movq 0x20(%rbx,%r15,8), %rsi
movq %r13, %rdi
callq 0xa434
cmpl $-0x1, %eax
je 0x64c5
movq 0x8(%rbx,%r15,8), %rax
movq 0x10(%rbx,%r15,8), %rcx
movq 0x768(%rax), %rax
cmpb $0x48, 0x1c(%rax)
movq 0x768(%rcx), %rcx
movb 0x1c(%rcx), %dl
jne 0x64a8
cmpb $0x48, %dl
je 0x64c5
movq 0x18(%rbx,%r15,8), %rdx
movq 0x768(%rdx), %rdx
cmpb $0x48, 0x1c(%rdx)
jne 0x64b9
jmp 0x64c5
cmpb $0x48, %dl
je 0x64c5
movq 0x18(%rbx,%r15,8), %rdx
movq 0x768(%rdx), %rdx
movb %r12b, 0x1c(%rax)
movb %r12b, 0x1c(%rcx)
movb %r12b, 0x1c(%rdx)
incq %r15
movq (%r14,%rbp,8), %rbx
movslq (%rbx), %rax
leaq -0x4(%rax), %rcx
cmpq %rcx, %r15
jl 0x643d
cmpl $0x7, %eax
jl 0x65a5
xorl %r15d, %r15d
movb $0x49, %r12b
movq 0x68(%rbx), %rbx
movq (%rbx,%r15,8), %rdx
movq 0x28(%rbx,%r15,8), %rsi
movq %r13, %rdi
callq 0xa434
cmpl $-0x1, %eax
je 0x658e
movq 0x8(%rbx,%r15,8), %rdx
movq 0x30(%rbx,%r15,8), %rsi
movq %r13, %rdi
callq 0xa434
cmpl $-0x1, %eax
je 0x658e
movq 0x8(%rbx,%r15,8), %rax
movq 0x768(%rax), %rax
cmpb $0x43, 0x1c(%rax)
jne 0x658e
movq 0x10(%rbx,%r15,8), %rcx
movq 0x768(%rcx), %rcx
cmpb $0x43, 0x1c(%rcx)
jne 0x658e
movq 0x18(%rbx,%r15,8), %rdx
movq 0x768(%rdx), %rdx
cmpb $0x43, 0x1c(%rdx)
jne 0x658e
movq 0x20(%rbx,%r15,8), %rsi
movq 0x768(%rsi), %rsi
cmpb $0x43, 0x1c(%rsi)
jne 0x658e
movq 0x28(%rbx,%r15,8), %rdi
movq 0x768(%rdi), %rdi
cmpb $0x43, 0x1c(%rdi)
jne 0x658e
movb %r12b, 0x1c(%rax)
movb %r12b, 0x1c(%rcx)
movb %r12b, 0x1c(%rdx)
movb %r12b, 0x1c(%rsi)
movb %r12b, 0x1c(%rdi)
incq %r15
movq (%r14,%rbp,8), %rbx
movslq (%rbx), %rax
addq $-0x6, %rax
cmpq %rax, %r15
jl 0x64eb
movq 0x8(%rsp), %rax
cmpl $0x0, 0x1d60(%rax)
movq 0x20(%rsp), %r15
je 0x6697
movq 0x1aa0d(%rip), %r13     # 0x20fd0
movq (%r13), %rdi
movq 0x48(%rbx), %rdx
movsbl 0x40(%rbx), %ecx
leaq 0x14761(%rip), %rsi     # 0x1ad37
xorl %eax, %eax
callq 0x2160
movq (%r14,%rbp,8), %rax
movl (%rax), %ecx
cmpl $0x5, %ecx
jl 0x6697
xorl %r12d, %r12d
leaq 0x135ba(%rip), %rbx     # 0x19bb0
movq 0x68(%rax), %rdi
movq (%rdi,%r12,8), %rdx
movq 0x768(%rdx), %rsi
movslq 0xc(%rsi), %r8
cmpq $-0x1, %r8
je 0x6685
movslq 0x10(%rsi), %r10
cmpq $-0x1, %r10
je 0x6685
movq 0x20(%rdi,%r12,8), %rdi
movq 0x768(%rdi), %rdi
movslq 0xc(%rdi), %r9
cmpq $-0x1, %r9
je 0x6685
movslq 0x10(%rdi), %r11
cmpq $-0x1, %r11
je 0x6685
movq (%r13), %rdi
movq 0x10(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
addq $0x4, %rdx
movq (%r15,%r8,8), %rax
xorps %xmm1, %xmm1
cvtss2sd (%rax,%r10,4), %xmm1
movsbl 0x1c(%rsi), %r8d
movq (%r15,%r9,8), %rax
xorps %xmm2, %xmm2
cvtss2sd (%rax,%r11,4), %xmm2
movl %r11d, (%rsp)
movq %rbx, %rsi
movl %r12d, %ecx
movb $0x3, %al
callq 0x2160
movq (%r14,%rbp,8), %rax
movl (%rax), %ecx
incq %r12
leal -0x4(%rcx), %edx
movslq %edx, %rdx
cmpq %rdx, %r12
jl 0x65f6
movq 0x10(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
nop