// File: /workspace/github_cpp_makefile_star2_O1/atfrank[P]PCASA/lib/Analyze.cpp
// Function: Analyze::dihedral(Coor const&, Coor const&, Coor const&, Coor const&)
double Analyze::dihedral (const Coor& t, const Coor& u, const Coor& v, const Coor& w) {
  double dihedral;
  Coor dx, dy, dz, p1, p2, p3;
  double np1, np2, dp1, dp2, ts;

  dx=t-u;
  dy=u-v;
  dz=w-v; //This is correct!

  p1=dx.cross(dy);

  np1=p1.norm();
  p1=p1/np1;

  p2=dz.cross(dy);
  np2=p2.norm();
  p2=p2/np2;

  dp1=p1.dot(p2); //Dot product

  ts=1.0-dp1*dp1;
  ts=(ts<0.0)?0.0:sqrt(ts);
  dihedral=PI/2.0-atan2(dp1,ts);

  p3=p1.cross(p2);

  dp2=p3.dot(dy); //Dot product

  if (dp2 > 0.0){
    dihedral=-dihedral;
  }

  return dihedral/PI*180.0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, (%rsp)
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r13
leaq 0x40(%rsp), %rdi
callq 0x3a27c
leaq 0x28(%rsp), %rdi
callq 0x3a27c
leaq 0xa0(%rsp), %rdi
callq 0x3a27c
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x3a27c
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x3a27c
leaq 0x58(%rsp), %rdi
callq 0x3a27c
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3a360
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x3a2ae
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x3a360
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3a2ae
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq (%rsp), %rsi
movq %rbp, %rdx
callq 0x3a360
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x3a2ae
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
movq %r13, %rdx
callq 0x3a552
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3a2ae
movq %rbx, %rdi
callq 0x3a598
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3a4c4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3a2ae
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x3a552
movq %r14, %rdi
movq %r15, %rsi
callq 0x3a2ae
movq %r14, %rdi
callq 0x3a598
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x3a4c4
movq %r14, %rdi
movq %r15, %rsi
callq 0x3a2ae
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3a52c
movapd %xmm0, %xmm2
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x2e40f(%rip), %xmm0    # 0x3c450
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0xe071
ucomisd %xmm1, %xmm0
jb 0xe05e
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0xe071
movsd %xmm2, (%rsp)
callq 0x4260
movsd (%rsp), %xmm2
movapd %xmm0, %xmm1
movsd 0x3e328f(%rip), %xmm0   # 0x3f1308
mulsd 0x2e3d7(%rip), %xmm0    # 0x3c458
movapd %xmm0, (%rsp)
movapd %xmm2, %xmm0
callq 0x4060
movapd (%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
leaq 0x10(%rsp), %rbx
leaq 0x88(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movq %rbx, %rdi
callq 0x3a552
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3a2ae
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x3a52c
movapd 0x2e3a4(%rip), %xmm1    # 0x3c480
movapd (%rsp), %xmm3
xorpd %xmm3, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
divsd 0x3e3206(%rip), %xmm2   # 0x3f1308
mulsd 0x2e33e(%rip), %xmm2    # 0x3c448
movapd %xmm2, %xmm0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq