// File: /workspace/github_c_makefile_star2_O2/josch[P]stride/turn.c
// Function: GammaTurn
void GammaTurn(CHAIN **Chain, int Cn, HBOND **HBond)
{

  register int i;
  RESIDUE **r;
  TURN *t;
  int Tn;
  float Phi2, Psi2;
  char TurnType, Asn;

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

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

    Asn = r[2]->Prop->Asn;

    if( Asn == 'H' || Asn == 'T' || Asn == 'G' || Asn == 'I' ||
        FindBnd(HBond,r[3],r[1]) == ERR ||
        (i > 0 && FindBnd(HBond,r[3],r[0]) != ERR) || 
        (i < Chain[Cn]->NRes-3 && FindBnd(HBond,r[4],r[1]) != ERR) )
      continue;
    
    Phi2 = r[2]->Prop->Phi;
    Psi2 = r[2]->Prop->Psi;
    
    if( Phi2 > 0.0 && Psi2 < 0.0 )
      TurnType = '@';
    else
    if( Phi2 < 0.0 && Psi2 > 0.0 )
      TurnType = '&';
    else 
      continue;

    if( r[1]->Prop->Asn == 'C' )
      r[1]->Prop->Asn = 'T';
    
    if( r[2]->Prop->Asn == 'C' )
      r[2]->Prop->Asn = 'T';
    
    if( r[3]->Prop->Asn == 'C' )
      r[3]->Prop->Asn = 'T';
    
    Tn = Chain[Cn]->NAssignedTurn;
    Chain[Cn]->AssignedTurn[Tn] = (TURN *)ckalloc(sizeof(TURN));
    t = Chain[Cn]->AssignedTurn[Tn];
    strcpy(t->Res1,r[1]->ResType);
    strcpy(t->Res2,r[3]->ResType);
    strcpy(t->PDB_ResNumb1,r[1]->PDB_ResNumb);
    strcpy(t->PDB_ResNumb2,r[3]->PDB_ResNumb);
    t->TurnType = TurnType;
    Chain[Cn]->NAssignedTurn++;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
movq %rdi, %r14
movslq %esi, %r13
xorl %ebp, %ebp
movl $0x2007, %r15d          # imm = 0x2007
movq %rdx, 0x10(%rsp)
movq (%r14,%r13,8), %rax
movslq (%rax), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rbp
jge 0x1502d
movq 0x68(%rax), %rbx
movq 0x8(%rbx,%rbp,8), %rax
movq 0x768(%rax), %rax
movzbl 0x1c(%rax), %eax
addl $-0x47, %eax
cmpl $0xd, %eax
ja 0x14ec9
btl %eax, %r15d
jae 0x14ec9
incq %rbp
jmp 0x14e8e
movq (%rbx,%rbp,8), %rdx
movq 0x10(%rbx,%rbp,8), %rsi
movq %r12, %rdi
callq 0x987f
cmpl $-0x1, %eax
je 0x14ec4
testq %rbp, %rbp
je 0x14efb
movq -0x8(%rbx,%rbp,8), %rdx
movq 0x10(%rbx,%rbp,8), %rsi
movq %r12, %rdi
callq 0x987f
cmpl $-0x1, %eax
jne 0x14ec4
movq (%r14,%r13,8), %rax
movslq (%rax), %rax
addq $-0x3, %rax
cmpq %rax, %rbp
jge 0x14f21
movq (%rbx,%rbp,8), %rdx
movq 0x18(%rbx,%rbp,8), %rsi
movq %r12, %rdi
callq 0x987f
cmpl $-0x1, %eax
jne 0x14ec4
movq 0x8(%rbx,%rbp,8), %rax
movq 0x768(%rax), %rax
movss (%rax), %xmm1
movss 0x4(%rax), %xmm0
ucomiss 0x3f63(%rip), %xmm1     # 0x18ea0
jbe 0x14f49
movb $0x40, %cl
xorps %xmm2, %xmm2
ucomiss %xmm0, %xmm2
ja 0x14f64
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x14ec4
movb $0x26, %cl
ucomiss 0x3f42(%rip), %xmm0     # 0x18ea0
jbe 0x14ec4
movb %cl, 0xf(%rsp)
movq (%rbx,%rbp,8), %rcx
movq 0x768(%rcx), %rcx
cmpb $0x43, 0x1c(%rcx)
jne 0x14f7d
movb $0x54, 0x1c(%rcx)
cmpb $0x43, 0x1c(%rax)
jne 0x14f87
movb $0x54, 0x1c(%rax)
movq 0x10(%rbx,%rbp,8), %rax
movq 0x768(%rax), %rax
cmpb $0x43, 0x1c(%rax)
jne 0x14f9d
movb $0x54, 0x1c(%rax)
movq (%r14,%r13,8), %rax
movslq 0x28(%rax), %r12
pushq $0x1b
popq %rdi
callq 0x50f4
movq (%r14,%r13,8), %rcx
movq 0x98(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
movq (%r14,%r13,8), %rax
movq 0x98(%rax), %rax
movq (%rax,%r12,8), %r12
movq (%rbx,%rbp,8), %rsi
addq $0xa, %rsi
movq %r12, %rdi
callq 0x2070
leaq 0x6(%r12), %rdi
movq 0x10(%rbx,%rbp,8), %rsi
addq $0xa, %rsi
callq 0x2070
leaq 0xc(%r12), %rdi
movq (%rbx,%rbp,8), %rsi
addq $0x4, %rsi
callq 0x2070
leaq 0x12(%r12), %rdi
movq 0x10(%rbx,%rbp,8), %rsi
addq $0x4, %rsi
callq 0x2070
movb 0xf(%rsp), %al
movb %al, 0x1a(%r12)
movq (%r14,%r13,8), %rax
incl 0x28(%rax)
movq 0x10(%rsp), %r12
jmp 0x14ec4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq