// File: /workspace/github_cpp_makefile_star2_O2/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 0x2bf34
leaq 0x28(%rsp), %rdi
callq 0x2bf34
leaq 0xa0(%rsp), %rdi
callq 0x2bf34
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x2bf34
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x2bf34
leaq 0x58(%rsp), %rdi
callq 0x2bf34
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2c014
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x2bf62
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2c014
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x2bf62
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq (%rsp), %rsi
movq %rbp, %rdx
callq 0x2c014
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x2bf62
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
movq %r13, %rdx
callq 0x2c206
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2bf62
movq %rbx, %rdi
callq 0x2c24c
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2c178
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2bf62
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2c206
movq %r14, %rdi
movq %r15, %rsi
callq 0x2bf62
movq %r14, %rdi
callq 0x2c24c
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2c178
movq %r14, %rdi
movq %r15, %rsi
callq 0x2bf62
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2c1e0
movapd %xmm0, %xmm2
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x23daf(%rip), %xmm0    # 0x2d450
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x96ce
ucomisd %xmm1, %xmm0
jb 0x96bb
sqrtsd %xmm0, %xmm1
jmp 0x96ce
movsd %xmm2, (%rsp)
callq 0x4280
movsd (%rsp), %xmm2
movapd %xmm0, %xmm1
movsd 0x3dbc5a(%rip), %xmm0   # 0x3e5330
mulsd 0x23d7a(%rip), %xmm0    # 0x2d458
movapd %xmm0, (%rsp)
movapd %xmm2, %xmm0
callq 0x4050
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 0x2c206
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2bf62
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x2c1e0
movapd 0x23d47(%rip), %xmm1    # 0x2d480
movapd (%rsp), %xmm3
xorpd %xmm3, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
divsd 0x3dbbd1(%rip), %xmm2   # 0x3e5330
mulsd 0x23ce1(%rip), %xmm2    # 0x2d448
movapd %xmm2, %xmm0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop