// File: /workspace/github_c_makefile_star2_O3/josch[P]stride/turn.c
// Function: BetaTurn
void BetaTurn(CHAIN **Chain, int Cn)
{

  register int i;
  RESIDUE **r;
  TURN *t;
  int CA1, CA4, Tn;
  float Phi2, Phi3, Psi2, Psi3, Range1 = 30.0, Range2 = 45.0;
  char TurnType;

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

    r = &Chain[Cn]->Rsd[i];
    
    if( r[1]->Prop->Asn == 'H' || r[2]->Prop->Asn == 'H' || 
        r[1]->Prop->Asn == 'G' || r[2]->Prop->Asn == 'G' || 
        r[1]->Prop->Asn == 'I' || r[2]->Prop->Asn == 'G' || 
       !FindAtom(Chain[Cn],i,"CA",&CA1) || !FindAtom(Chain[Cn],i+3,"CA",&CA4) ||
       Dist(r[0]->Coord[CA1],r[3]->Coord[CA4]) > 7.0 )
      continue;
    
    Phi2 = r[1]->Prop->Phi;
    Psi2 = r[1]->Prop->Psi;
    Phi3 = r[2]->Prop->Phi;
    Psi3 = r[2]->Prop->Psi;
    
    if( TurnCondition(Phi2,-60.0,Psi2,-30,Phi3,-90.0,Psi3,0,Range1,Range2) )
      TurnType = '1';
    else
    if( TurnCondition(Phi2,60.0,Psi2,30,Phi3,90.0,Psi3,0,Range1,Range2) )
      TurnType = '2';
    else
    if( TurnCondition(Phi2,-60.0,Psi2,120,Phi3,80.0,Psi3,0,Range1,Range2) )
      TurnType = '3';
    else
    if( TurnCondition(Phi2,60.0,Psi2,-120,Phi3,-80.0,Psi3,0,Range1,Range2) )
      TurnType = '4';
    else
    if( TurnCondition(Phi2,-60.0,Psi2,120,Phi3,-90.0,Psi3,0,Range1,Range2) )
      TurnType = '5';
    else
    if( TurnCondition(Phi2,-120.0,Psi2,120,Phi3,-60.0,Psi3,0,Range1,Range2) )
      TurnType = '6';
    else
    if( TurnCondition(Phi2,-60.0,Psi2,-30,Phi3,-120.0,Psi3,120,Range1,Range2) )
      TurnType = '7';
    else
      TurnType = '8';
  
    if( r[0]->Prop->Asn == 'C' ) 
      r[0]->Prop->Asn = 'T';
    
    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[0]->ResType);
    strcpy(t->Res2,r[3]->ResType);
    strcpy(t->PDB_ResNumb1,r[0]->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 $0x28, %rsp
movq %rdi, %rbx
movslq %esi, %r13
movq (%rdi,%r13,8), %rdi
cmpl $0x5, (%rdi)
jl 0x151fa
xorl %r14d, %r14d
leaq 0x6051(%rip), %r15      # 0x1ae38
leaq 0x18(%rsp), %rbp
movq 0x68(%rdi), %r12
movq 0x8(%r12,%r14,8), %rax
movq 0x768(%rax), %rax
movzbl 0x1c(%rax), %eax
cmpl $0x48, %eax
je 0x151e3
movq 0x10(%r12,%r14,8), %rcx
movq 0x768(%rcx), %rcx
movb 0x1c(%rcx), %cl
addb $-0x47, %cl
cmpb $0x2, %cl
jb 0x151e3
cmpl $0x47, %eax
je 0x151e3
cmpl $0x49, %eax
je 0x151e3
movl %r14d, %esi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x4ea0
testl %eax, %eax
je 0x151e3
movq (%rbx,%r13,8), %rdi
leal 0x3(%r14), %esi
movq %r15, %rdx
leaq 0x1c(%rsp), %rcx
callq 0x4ea0
testl %eax, %eax
je 0x151e3
movslq 0x18(%rsp), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x2, %rdi
addq (%r12,%r14,8), %rdi
movl $0x188, %ecx            # imm = 0x188
addq %rcx, %rdi
movslq 0x1c(%rsp), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x2, %rsi
addq 0x18(%r12,%r14,8), %rsi
addq %rcx, %rsi
callq 0x40c3
ucomiss 0x5dcd(%rip), %xmm0     # 0x1ac70
ja 0x151e3
movq 0x8(%r12,%r14,8), %rax
movq 0x10(%r12,%r14,8), %rcx
movq 0x768(%rax), %rbp
movss (%rbp), %xmm0
movss 0x4(%rbp), %xmm2
movq 0x768(%rcx), %rax
movss (%rax), %xmm4
movq %rax, 0x20(%rsp)
movss 0x4(%rax), %xmm6
xorps %xmm7, %xmm7
movss %xmm0, 0x8(%rsp)
movss 0x5d8a(%rip), %xmm1     # 0x1ac74
movss %xmm2, 0x10(%rsp)
movss 0x5d80(%rip), %xmm3     # 0x1ac78
movss %xmm4, 0xc(%rsp)
movss 0x5d76(%rip), %xmm5     # 0x1ac7c
movss %xmm6, 0x14(%rsp)
pushq $0x42340000             # imm = 0x42340000
pushq $0x41f00000             # imm = 0x41F00000
callq 0x15209
addq $0x10, %rsp
movb $0x31, %r15b
testl %eax, %eax
jne 0x15113
xorps %xmm7, %xmm7
movss 0x8(%rsp), %xmm0
movss 0x4f99(%rip), %xmm1     # 0x19ed4
movss 0x10(%rsp), %xmm2
movss 0x5d37(%rip), %xmm3     # 0x1ac80
movss 0xc(%rsp), %xmm4
movss 0x4bb1(%rip), %xmm5     # 0x19b08
movss 0x14(%rsp), %xmm6
pushq $0x42340000             # imm = 0x42340000
pushq $0x41f00000             # imm = 0x41F00000
callq 0x15209
addq $0x10, %rsp
movb $0x32, %r15b
testl %eax, %eax
jne 0x15113
xorps %xmm7, %xmm7
movss 0x8(%rsp), %xmm0
movss 0x5ce8(%rip), %xmm1     # 0x1ac74
movss 0x10(%rsp), %xmm2
movss 0x5cea(%rip), %xmm3     # 0x1ac84
movss 0xc(%rsp), %xmm4
movss 0x5ce0(%rip), %xmm5     # 0x1ac88
movss 0x14(%rsp), %xmm6
pushq $0x42340000             # imm = 0x42340000
pushq $0x41f00000             # imm = 0x41F00000
callq 0x15209
addq $0x10, %rsp
movb $0x33, %r15b
testl %eax, %eax
jne 0x15113
xorps %xmm7, %xmm7
movss 0x8(%rsp), %xmm0
movss 0x4ef7(%rip), %xmm1     # 0x19ed4
movss 0x10(%rsp), %xmm2
movss 0x5ca1(%rip), %xmm3     # 0x1ac8c
movss 0xc(%rsp), %xmm4
movss 0x5c97(%rip), %xmm5     # 0x1ac90
movss 0x14(%rsp), %xmm6
pushq $0x42340000             # imm = 0x42340000
pushq $0x41f00000             # imm = 0x41F00000
callq 0x15209
addq $0x10, %rsp
movb $0x34, %r15b
testl %eax, %eax
jne 0x15113
xorps %xmm7, %xmm7
movss 0x8(%rsp), %xmm0
movss 0x5c46(%rip), %xmm1     # 0x1ac74
movss 0x10(%rsp), %xmm2
movss 0x5c48(%rip), %xmm3     # 0x1ac84
movss 0xc(%rsp), %xmm4
movss 0x5c32(%rip), %xmm5     # 0x1ac7c
movss 0x14(%rsp), %xmm6
pushq $0x42340000             # imm = 0x42340000
pushq $0x41f00000             # imm = 0x41F00000
callq 0x15209
addq $0x10, %rsp
movb $0x35, %r15b
testl %eax, %eax
jne 0x15113
xorps %xmm7, %xmm7
movss 0x8(%rsp), %xmm0
movss 0x5c0d(%rip), %xmm1     # 0x1ac8c
movss 0x10(%rsp), %xmm2
movss 0x5bf7(%rip), %xmm3     # 0x1ac84
movss 0xc(%rsp), %xmm4
movss 0x5bd9(%rip), %xmm5     # 0x1ac74
movss 0x14(%rsp), %xmm6
pushq $0x42340000             # imm = 0x42340000
pushq $0x41f00000             # imm = 0x41F00000
callq 0x15209
addq $0x10, %rsp
movb $0x36, %r15b
testl %eax, %eax
jne 0x15113
movss 0x8(%rsp), %xmm0
movss 0x5bab(%rip), %xmm1     # 0x1ac74
movss 0x10(%rsp), %xmm2
movss 0x5ba1(%rip), %xmm3     # 0x1ac78
movss 0xc(%rsp), %xmm4
movss 0x5ba7(%rip), %xmm5     # 0x1ac8c
movss 0x14(%rsp), %xmm6
movss 0x5b91(%rip), %xmm7     # 0x1ac84
pushq $0x42340000             # imm = 0x42340000
pushq $0x41f00000             # imm = 0x41F00000
callq 0x15209
addq $0x10, %rsp
cmpl $0x1, %eax
movl $0x0, %r15d
adcb $0x37, %r15b
movq (%r12,%r14,8), %rax
movq 0x768(%rax), %rax
cmpb $0x43, 0x1c(%rax)
jne 0x15128
movb $0x54, 0x1c(%rax)
cmpb $0x43, 0x1c(%rbp)
jne 0x15132
movb $0x54, 0x1c(%rbp)
movq 0x20(%rsp), %rax
cmpb $0x43, 0x1c(%rax)
jne 0x15141
movb $0x54, 0x1c(%rax)
movq 0x18(%r12,%r14,8), %rax
movq 0x768(%rax), %rax
cmpb $0x43, 0x1c(%rax)
jne 0x15157
movb $0x54, 0x1c(%rax)
movq (%rbx,%r13,8), %rax
movslq 0x28(%rax), %rbp
movl $0x1b, %edi
callq 0x5880
movq (%rbx,%r13,8), %rcx
movq 0x98(%rcx), %rcx
movq %rax, (%rcx,%rbp,8)
movq (%rbx,%r13,8), %rax
movq 0x98(%rax), %rax
movq (%rax,%rbp,8), %rbp
movq (%r12,%r14,8), %rsi
addq $0xa, %rsi
movq %rbp, %rdi
callq 0x2070
leaq 0x6(%rbp), %rdi
movq 0x18(%r12,%r14,8), %rsi
addq $0xa, %rsi
callq 0x2070
leaq 0xc(%rbp), %rdi
movq (%r12,%r14,8), %rsi
addq $0x4, %rsi
callq 0x2070
leaq 0x12(%rbp), %rdi
movq 0x18(%r12,%r14,8), %rsi
addq $0x4, %rsi
callq 0x2070
movb %r15b, 0x1a(%rbp)
movq (%rbx,%r13,8), %rax
incl 0x28(%rax)
leaq 0x5c5a(%rip), %r15      # 0x1ae38
leaq 0x18(%rsp), %rbp
incq %r14
movq (%rbx,%r13,8), %rdi
movslq (%rdi), %rax
addq $-0x4, %rax
cmpq %rax, %r14
jl 0x14dec
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq