// File: /workspace/github_c_makefile_star2_O0/josch[P]stride/geometry.c
// Function: Torsion
float Torsion(float *Coord1, float *Coord2, float *Coord3, float *Coord4)
{
  double Comp[3][3], ScalarProd, TripleScalarProd, AbsTorsAng;
  double Perp_123[3], Perp_234[3], Len_Perp_123, Len_Perp_234;
  int i, j, k;

  /* Find the components of the three bond vectors */
  for( i=0; i<3; i++ ) {
    Comp[0][i] = (double)(Coord2[i]-Coord1[i]);
    Comp[1][i] = (double)(Coord3[i]-Coord2[i]);
    Comp[2][i] = (double)(Coord4[i]-Coord3[i]);
  }

  /* Calculate vectors perpendicular to the planes 123 and 234 */
  Len_Perp_123 = 0.0; Len_Perp_234 = 0.0;
  for( i=0; i<3; i++ ) {
    j = (i+1)%3;
    k = (j+1)%3;
    Perp_123[i] = Comp[0][j]*Comp[1][k] - Comp[0][k]*Comp[1][j];
    Perp_234[i] = Comp[1][j]*Comp[2][k] - Comp[1][k]*Comp[2][j];
    Len_Perp_123 += Perp_123[i]*Perp_123[i];
    Len_Perp_234 += Perp_234[i]*Perp_234[i];
  }
  
  Len_Perp_123 = sqrt(Len_Perp_123);
  Len_Perp_234 = sqrt(Len_Perp_234);

  /* Normalize the vectors perpendicular to 123 and 234 */
  for( i=0; i<3; i++ ) {
    Perp_123[i] /= Len_Perp_123;
    Perp_234[i] /= Len_Perp_234;
  }

  /* Find the scalar product of the unit normals */
  ScalarProd = 0.0;
  for( i=0; i<3; i++ ) 
    ScalarProd += Perp_123[i]*Perp_234[i];

  /* Find the absolute value of the torsion angle */
  if( ScalarProd > 0.0 && fabs(ScalarProd - 1.0) < Eps ) 
    ScalarProd -= Eps;
  else
  if( ScalarProd < 0.0 && fabs(ScalarProd + 1.0) < Eps ) 
    ScalarProd += Eps;
  AbsTorsAng = RADDEG*acos(ScalarProd);

  /* Find the triple scalar product of the three bond vectors */
  TripleScalarProd = 0.0;
  for( i=0; i<3; i++ ) 
    TripleScalarProd += Comp[0][i]*Perp_234[i];

  /* Torsion angle has the sign of the triple scalar product */
  return( (TripleScalarProd > 0.0) ? (float)AbsTorsAng : (float)(-AbsTorsAng) );

}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
movq %rcx, 0xb8(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x3, 0xc(%rsp)
jge 0x4699
movq 0xc8(%rsp), %rax
movslq 0xc(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0xd0(%rsp), %rax
movslq 0xc(%rsp), %rcx
subss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0xc(%rsp), %rax
movsd %xmm0, 0x70(%rsp,%rax,8)
movq 0xc0(%rsp), %rax
movslq 0xc(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0xc8(%rsp), %rax
movslq 0xc(%rsp), %rcx
subss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0xc(%rsp), %rax
movsd %xmm0, 0x88(%rsp,%rax,8)
movq 0xb8(%rsp), %rax
movslq 0xc(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0xc0(%rsp), %rax
movslq 0xc(%rsp), %rcx
subss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0xc(%rsp), %rax
movsd %xmm0, 0xa0(%rsp,%rax,8)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x45df
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x3, 0xc(%rsp)
jge 0x4806
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, 0x8(%rsp)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, 0x4(%rsp)
movslq 0x8(%rsp), %rax
movsd 0x70(%rsp,%rax,8), %xmm0
movslq 0x4(%rsp), %rax
movsd 0x88(%rsp,%rax,8), %xmm2
movslq 0x4(%rsp), %rax
movsd 0x70(%rsp,%rax,8), %xmm1
movslq 0x8(%rsp), %rax
mulsd 0x88(%rsp,%rax,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movslq 0xc(%rsp), %rax
movsd %xmm0, 0x40(%rsp,%rax,8)
movslq 0x8(%rsp), %rax
movsd 0x88(%rsp,%rax,8), %xmm0
movslq 0x4(%rsp), %rax
movsd 0xa0(%rsp,%rax,8), %xmm2
movslq 0x4(%rsp), %rax
movsd 0x88(%rsp,%rax,8), %xmm1
movslq 0x8(%rsp), %rax
mulsd 0xa0(%rsp,%rax,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movslq 0xc(%rsp), %rax
movsd %xmm0, 0x20(%rsp,%rax,8)
movslq 0xc(%rsp), %rax
movsd 0x40(%rsp,%rax,8), %xmm0
movslq 0xc(%rsp), %rax
movsd 0x40(%rsp,%rax,8), %xmm2
movsd 0x18(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movslq 0xc(%rsp), %rax
movsd 0x20(%rsp,%rax,8), %xmm0
movslq 0xc(%rsp), %rax
movsd 0x20(%rsp,%rax,8), %xmm2
movsd 0x10(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x46b3
movsd 0x18(%rsp), %xmm0
callq 0x2220
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x2220
movsd %xmm0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x3, 0xc(%rsp)
jge 0x487a
movsd 0x18(%rsp), %xmm1
movslq 0xc(%rsp), %rax
movsd 0x40(%rsp,%rax,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp,%rax,8)
movsd 0x10(%rsp), %xmm1
movslq 0xc(%rsp), %rax
movsd 0x20(%rsp,%rax,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp,%rax,8)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x4830
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x3, 0xc(%rsp)
jge 0x48c9
movslq 0xc(%rsp), %rax
movsd 0x40(%rsp,%rax,8), %xmm0
movslq 0xc(%rsp), %rax
movsd 0x20(%rsp,%rax,8), %xmm2
movsd 0x68(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x488b
movsd 0x68(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x491d
movsd 0x68(%rsp), %xmm1
movsd 0x26f12(%rip), %xmm0    # 0x2b7f8
subsd %xmm0, %xmm1
movaps 0x26f5f(%rip), %xmm0    # 0x2b850
pand %xmm0, %xmm1
movsd 0x26ef3(%rip), %xmm0    # 0x2b7f0
ucomisd %xmm1, %xmm0
jbe 0x491d
movsd 0x68(%rsp), %xmm0
movsd 0x26edf(%rip), %xmm1    # 0x2b7f0
subsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0x4965
xorps %xmm0, %xmm0
ucomisd 0x68(%rsp), %xmm0
jbe 0x4963
movsd 0x26ec8(%rip), %xmm1    # 0x2b7f8
addsd 0x68(%rsp), %xmm1
movaps 0x26f13(%rip), %xmm0    # 0x2b850
pand %xmm0, %xmm1
movsd 0x26ea7(%rip), %xmm0    # 0x2b7f0
ucomisd %xmm1, %xmm0
jbe 0x4963
movsd 0x26e99(%rip), %xmm0    # 0x2b7f0
addsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0x4965
movsd 0x68(%rsp), %xmm0
callq 0x2100
movaps %xmm0, %xmm1
movsd 0x26e85(%rip), %xmm0    # 0x2b800
mulsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x3, 0xc(%rsp)
jge 0x49d4
movslq 0xc(%rsp), %rax
movsd 0x70(%rsp,%rax,8), %xmm0
movslq 0xc(%rsp), %rax
movsd 0x20(%rsp,%rax,8), %xmm2
movsd 0x60(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x4996
movsd 0x60(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x49f4
movsd 0x58(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
jmp 0x4a1a
movsd 0x58(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
movss (%rsp), %xmm0
addq $0xd8, %rsp
retq
nopw (%rax,%rax)