// File: /workspace/github_cpp_makefile_star2_O3/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 0x39fd4
leaq 0x28(%rsp), %rdi
callq 0x39fd4
leaq 0xa0(%rsp), %rdi
callq 0x39fd4
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x39fd4
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x39fd4
leaq 0x58(%rsp), %rdi
callq 0x39fd4
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3a0b8
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x3a006
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x3a0b8
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3a006
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq (%rsp), %rsi
movq %rbp, %rdx
callq 0x3a0b8
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x3a006
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
movq %r13, %rdx
callq 0x3a2aa
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3a006
movq %rbx, %rdi
callq 0x3a2f0
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3a21c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3a006
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x3a2aa
movq %r14, %rdi
movq %r15, %rsi
callq 0x3a006
movq %r14, %rdi
callq 0x3a2f0
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x3a21c
movq %r14, %rdi
movq %r15, %rsi
callq 0x3a006
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3a284
movapd %xmm0, %xmm2
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x2d58f(%rip), %xmm0    # 0x3b450
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0xdef1
ucomisd %xmm1, %xmm0
jb 0xdede
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0xdef1
movsd %xmm2, (%rsp)
callq 0x4260
movsd (%rsp), %xmm2
movapd %xmm0, %xmm1
movsd 0x3e240f(%rip), %xmm0   # 0x3f0308
mulsd 0x2d557(%rip), %xmm0    # 0x3b458
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 0x3a2aa
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3a006
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x3a284
movapd 0x2d524(%rip), %xmm1    # 0x3b480
movapd (%rsp), %xmm3
xorpd %xmm3, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
divsd 0x3e2386(%rip), %xmm2   # 0x3f0308
mulsd 0x2d4be(%rip), %xmm2    # 0x3b448
movapd %xmm2, %xmm0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq