// File: 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:
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, 0x1b0(%rsp)
movq %rsi, 0x1a8(%rsp)
movq %rdx, 0x1a0(%rsp)
movq %rcx, 0x198(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x76060
leaq 0x160(%rsp), %rdi
callq 0x76060
leaq 0x148(%rsp), %rdi
callq 0x76060
leaq 0x130(%rsp), %rdi
callq 0x76060
leaq 0x118(%rsp), %rdi
callq 0x76060
leaq 0x100(%rsp), %rdi
callq 0x76060
movq 0x1b0(%rsp), %rsi
movq 0x1a8(%rsp), %rdx
leaq 0xc0(%rsp), %rdi
callq 0x762d0
leaq 0x178(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x76110
movq 0x1a8(%rsp), %rsi
movq 0x1a0(%rsp), %rdx
leaq 0xa8(%rsp), %rdi
callq 0x762d0
leaq 0x160(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x76110
movq 0x198(%rsp), %rsi
movq 0x1a0(%rsp), %rdx
leaq 0x90(%rsp), %rdi
callq 0x762d0
leaq 0x148(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x76110
leaq 0x78(%rsp), %rdi
leaq 0x178(%rsp), %rsi
leaq 0x160(%rsp), %rdx
callq 0x767a0
leaq 0x130(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x76110
leaq 0x130(%rsp), %rdi
callq 0x76890
movsd %xmm0, 0xf8(%rsp)
movsd 0xf8(%rsp), %xmm0
leaq 0x60(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x76630
leaq 0x130(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x76110
leaq 0x48(%rsp), %rdi
leaq 0x148(%rsp), %rsi
leaq 0x160(%rsp), %rdx
callq 0x767a0
leaq 0x118(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x76110
leaq 0x118(%rsp), %rdi
callq 0x76890
movsd %xmm0, 0xf0(%rsp)
movsd 0xf0(%rsp), %xmm0
leaq 0x30(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x76630
leaq 0x118(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x76110
leaq 0x130(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x76750
movsd %xmm0, 0xe8(%rsp)
movsd 0xe8(%rsp), %xmm0
movsd 0xe8(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm1, %xmm0
movsd 0x6b4f4(%rip), %xmm1    # 0x7b370
addsd %xmm1, %xmm0
movsd %xmm0, 0xd8(%rsp)
xorps %xmm0, %xmm0
ucomisd 0xd8(%rsp), %xmm0
jbe 0xfea2
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0xfeb6
movsd 0xd8(%rsp), %xmm0
callq 0x5300
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0x42b54b(%rip), %xmm0   # 0x43b418
movsd 0x6b4bb(%rip), %xmm1    # 0x7b390
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xe8(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
callq 0x5080
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x190(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x118(%rsp), %rdx
callq 0x767a0
leaq 0x100(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x76110
leaq 0x100(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x76750
movsd %xmm0, 0xe0(%rsp)
movsd 0xe0(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xff91
movsd 0x190(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x190(%rsp)
movsd 0x190(%rsp), %xmm0
divsd 0x42b476(%rip), %xmm0   # 0x43b418
movsd 0x6b3de(%rip), %xmm1    # 0x7b388
mulsd %xmm1, %xmm0
addq $0x1b8, %rsp            # imm = 0x1B8
retq
nopw %cs:(%rax,%rax)