#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double **dmatrix(int, int, int, int);
int /*<<< orphan*/ free_dmatrix(double **, int, int, int, int);
double vec_ang(double *, double *, double *);
double veclen(double *);
double torsion(double **d) {
  double ang_deg, dij;
  double **vec3;
  long i, j;
  vec3 = dmatrix(1, 3, 1, 3);
  for (i = 1; i <= 3; i++) {
    for (j = 1; j <= 3; j++)
      if (i == 1)
        vec3[i][j] = d[i][j] - d[i + 1][j];
      else
        vec3[i][j] = d[i + 1][j] - d[i][j];
    dij = veclen(vec3[i]);
    if (dij > 2.5) {
      free_dmatrix(vec3, 1, 3, 1, 3);
      return -9999.99;
    }
  }
  ang_deg = vec_ang(vec3[1], vec3[3], vec3[2]);
  free_dmatrix(vec3, 1, 3, 1, 3);
  return ang_deg;
}


x86 assembly (clang, -O0):
<torsion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1,%edx
mov    $0x3,%ecx
mov    %edx,%edi
mov    %ecx,%esi
call   1040 <dmatrix@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
cmpq   $0x3,-0x30(%rbp)
jg     129d <torsion+0x15d>
movq   $0x1,-0x38(%rbp)
cmpq   $0x3,-0x38(%rbp)
jg     122f <torsion+0xef>
cmpq   $0x1,-0x30(%rbp)
jne    11d9 <torsion+0x99>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    0x8(%rax,%rcx,8),%rax
mov    -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1219 <torsion+0xd9>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    0x8(%rax,%rcx,8),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x38(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    121e <torsion+0xde>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    117e <torsion+0x3e>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <veclen@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdae(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1287 <torsion+0x147>
mov    -0x28(%rbp),%rdi
mov    $0x1,%ecx
mov    $0x3,%r8d
mov    %ecx,%esi
mov    %r8d,%edx
call   1060 <free_dmatrix@plt>
movsd  0xd8b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e2 <torsion+0x1a2>
jmp    128c <torsion+0x14c>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    116b <torsion+0x2b>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rdx
call   1030 <vec_ang@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%ecx
mov    $0x3,%r8d
mov    %ecx,%esi
mov    %r8d,%edx
call   1060 <free_dmatrix@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<torsion>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    $0x1,%edi
mov    $0x3,%esi
mov    $0x1,%edx
mov    $0x3,%ecx
call   1040 <dmatrix@plt>
mov    %rax,%r14
mov    $0x2,%ebx
nopl   (%rax)
cmp    $0x2,%rbx
jne    11d0 <torsion+0x90>
mov    0x8(%r15),%rax
mov    0x10(%r15),%rcx
movsd  0x8(%rax),%xmm0
subsd  0x8(%rcx),%xmm0
mov    0x8(%r14),%rax
movsd  %xmm0,0x8(%rax)
mov    0x8(%r15),%rax
mov    0x10(%r15),%rcx
movsd  0x10(%rax),%xmm0
subsd  0x10(%rcx),%xmm0
mov    0x8(%r14),%rax
movsd  %xmm0,0x10(%rax)
mov    0x8(%r15),%rax
mov    0x10(%r15),%rcx
movsd  0x18(%rax),%xmm0
subsd  0x18(%rcx),%xmm0
mov    0x8(%r14),%rax
movsd  %xmm0,0x18(%rax)
mov    -0x8(%r14,%rbx,8),%rdi
jmp    1227 <torsion+0xe7>
xchg   %ax,%ax
mov    -0x8(%r15,%rbx,8),%rax
mov    (%r15,%rbx,8),%rcx
movsd  0x8(%rcx),%xmm0
subsd  0x8(%rax),%xmm0
mov    -0x8(%r14,%rbx,8),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%r15,%rbx,8),%rax
mov    (%r15,%rbx,8),%rcx
movsd  0x10(%rcx),%xmm0
subsd  0x10(%rax),%xmm0
mov    -0x8(%r14,%rbx,8),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%r15,%rbx,8),%rax
mov    (%r15,%rbx,8),%rcx
movsd  0x18(%rcx),%xmm0
subsd  0x18(%rax),%xmm0
mov    -0x8(%r14,%rbx,8),%rdi
movsd  %xmm0,0x18(%rdi)
call   1050 <veclen@plt>
ucomisd 0xdd4(%rip),%xmm0
ja     1257 <torsion+0x117>
add    $0x1,%rbx
cmp    $0x5,%rbx
jne    1170 <torsion+0x30>
mov    0x18(%r14),%rsi
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rdx
call   1030 <vec_ang@plt>
jmp    125f <torsion+0x11f>
movsd  0xda1(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    $0x1,%ecx
mov    $0x3,%r8d
call   1060 <free_dmatrix@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @torsion(double** %0) {
%2 = alloca double
%3 = alloca double**
%4 = alloca double
%5 = alloca double
%6 = alloca double**
%7 = alloca i64
%8 = alloca i64
store double** %0, double*** %3
%9 = call double** @dmatrix(i32 1, i32 3, i32 1, i32 3)
store double** %9, double*** %6
store i64 1, i64* %7
br label %10
10: ; preds = %82, %1
%11 = load i64, i64* %7
%12 = icmp sle i64 %11, 3
br i1 %12, label %13, label %85
13: ; preds = %10
store i64 1, i64* %8
br label %14
14: ; preds = %67, %13
%15 = load i64, i64* %8
%16 = icmp sle i64 %15, 3
br i1 %16, label %17, label %70
17: ; preds = %14
%18 = load i64, i64* %7
%19 = icmp eq i64 %18, 1
br i1 %19, label %20, label %43
20: ; preds = %17
%21 = load double**, double*** %3
%22 = load i64, i64* %7
%23 = getelementptr inbounds double*, double** %21, i64 %22
%24 = load double*, double** %23
%25 = load i64, i64* %8
%26 = getelementptr inbounds double, double* %24, i64 %25
%27 = load double, double* %26
%28 = load double**, double*** %3
%29 = load i64, i64* %7
%30 = add nsw i64 %29, 1
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = load i64, i64* %8
%34 = getelementptr inbounds double, double* %32, i64 %33
%35 = load double, double* %34
%36 = fsub double %27, %35
%37 = load double**, double*** %6
%38 = load i64, i64* %7
%39 = getelementptr inbounds double*, double** %37, i64 %38
%40 = load double*, double** %39
%41 = load i64, i64* %8
%42 = getelementptr inbounds double, double* %40, i64 %41
store double %36, double* %42
br label %66
43: ; preds = %17
%44 = load double**, double*** %3
%45 = load i64, i64* %7
%46 = add nsw i64 %45, 1
%47 = getelementptr inbounds double*, double** %44, i64 %46
%48 = load double*, double** %47
%49 = load i64, i64* %8
%50 = getelementptr inbounds double, double* %48, i64 %49
%51 = load double, double* %50
%52 = load double**, double*** %3
%53 = load i64, i64* %7
%54 = getelementptr inbounds double*, double** %52, i64 %53
%55 = load double*, double** %54
%56 = load i64, i64* %8
%57 = getelementptr inbounds double, double* %55, i64 %56
%58 = load double, double* %57
%59 = fsub double %51, %58
%60 = load double**, double*** %6
%61 = load i64, i64* %7
%62 = getelementptr inbounds double*, double** %60, i64 %61
%63 = load double*, double** %62
%64 = load i64, i64* %8
%65 = getelementptr inbounds double, double* %63, i64 %64
store double %59, double* %65
br label %66
66: ; preds = %43, %20
br label %67
67: ; preds = %66
%68 = load i64, i64* %8
%69 = add nsw i64 %68, 1
store i64 %69, i64* %8
br label %14
70: ; preds = %14
%71 = load double**, double*** %6
%72 = load i64, i64* %7
%73 = getelementptr inbounds double*, double** %71, i64 %72
%74 = load double*, double** %73
%75 = call double @veclen(double* %74)
store double %75, double* %5
%76 = load double, double* %5
%77 = fcmp ogt double %76, 2.500000e+00
br i1 %77, label %78, label %81
78: ; preds = %70
%79 = load double**, double*** %6
%80 = call i32 @free_dmatrix(double** %79, i32 1, i32 3, i32 1, i32 3)
store double 0xC0C387FEB851EB85, double* %2
br label %99
81: ; preds = %70
br label %82
82: ; preds = %81
%83 = load i64, i64* %7
%84 = add nsw i64 %83, 1
store i64 %84, i64* %7
br label %10
85: ; preds = %10
%86 = load double**, double*** %6
%87 = getelementptr inbounds double*, double** %86, i64 1
%88 = load double*, double** %87
%89 = load double**, double*** %6
%90 = getelementptr inbounds double*, double** %89, i64 3
%91 = load double*, double** %90
%92 = load double**, double*** %6
%93 = getelementptr inbounds double*, double** %92, i64 2
%94 = load double*, double** %93
%95 = call double @vec_ang(double* %88, double* %91, double* %94)
store double %95, double* %4
%96 = load double**, double*** %6
%97 = call i32 @free_dmatrix(double** %96, i32 1, i32 3, i32 1, i32 3)
%98 = load double, double* %4
store double %98, double* %2
br label %99
99: ; preds = %85, %78
%100 = load double, double* %2
ret double %100
}

LLVM IR (-O2):
define double @torsion(double** nocapture %0) {
%2 = tail call double** @dmatrix(i32 1, i32 3, i32 1, i32 3)
%3 = getelementptr inbounds double*, double** %0, i64 1
%4 = getelementptr inbounds double*, double** %0, i64 2
%5 = getelementptr inbounds double*, double** %2, i64 1
br label %8
6: ; preds = %72
%7 = icmp eq i64 %11, 4
br i1 %7, label %76, label %8
8: ; preds = %1, %6
%9 = phi i64 [ 1, %1 ], [ %11, %6 ]
%10 = icmp eq i64 %9, 1
%11 = add nuw nsw i64 %9, 1
%12 = getelementptr inbounds double*, double** %0, i64 %11
%13 = getelementptr inbounds double*, double** %0, i64 %9
%14 = getelementptr inbounds double*, double** %2, i64 %9
br i1 %10, label %43, label %15
15: ; preds = %8
%16 = load double*, double** %12
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
%19 = load double*, double** %13
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = fsub double %18, %21
%23 = load double*, double** %14
%24 = getelementptr inbounds double, double* %23, i64 1
store double %22, double* %24
%25 = load double*, double** %12
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = load double*, double** %13
%29 = getelementptr inbounds double, double* %28, i64 2
%30 = load double, double* %29
%31 = fsub double %27, %30
%32 = load double*, double** %14
%33 = getelementptr inbounds double, double* %32, i64 2
store double %31, double* %33
%34 = load double*, double** %12
%35 = getelementptr inbounds double, double* %34, i64 3
%36 = load double, double* %35
%37 = load double*, double** %13
%38 = getelementptr inbounds double, double* %37, i64 3
%39 = load double, double* %38
%40 = fsub double %36, %39
%41 = load double*, double** %14
%42 = getelementptr inbounds double, double* %41, i64 3
store double %40, double* %42
br label %72
43: ; preds = %8
%44 = load double*, double** %3
%45 = getelementptr inbounds double, double* %44, i64 1
%46 = load double, double* %45
%47 = load double*, double** %4
%48 = getelementptr inbounds double, double* %47, i64 1
%49 = load double, double* %48
%50 = fsub double %46, %49
%51 = load double*, double** %5
%52 = getelementptr inbounds double, double* %51, i64 1
store double %50, double* %52
%53 = load double*, double** %3
%54 = getelementptr inbounds double, double* %53, i64 2
%55 = load double, double* %54
%56 = load double*, double** %4
%57 = getelementptr inbounds double, double* %56, i64 2
%58 = load double, double* %57
%59 = fsub double %55, %58
%60 = load double*, double** %5
%61 = getelementptr inbounds double, double* %60, i64 2
store double %59, double* %61
%62 = load double*, double** %3
%63 = getelementptr inbounds double, double* %62, i64 3
%64 = load double, double* %63
%65 = load double*, double** %4
%66 = getelementptr inbounds double, double* %65, i64 3
%67 = load double, double* %66
%68 = fsub double %64, %67
%69 = load double*, double** %5
%70 = getelementptr inbounds double, double* %69, i64 3
store double %68, double* %70
%71 = load double*, double** %14
br label %72
72: ; preds = %43, %15
%73 = phi double* [ %71, %43 ], [ %41, %15 ]
%74 = tail call double @veclen(double* %73)
%75 = fcmp ogt double %74, 2.500000e+00
br i1 %75, label %83, label %6
76: ; preds = %6
%77 = load double*, double** %5
%78 = getelementptr inbounds double*, double** %2, i64 3
%79 = load double*, double** %78
%80 = getelementptr inbounds double*, double** %2, i64 2
%81 = load double*, double** %80
%82 = tail call double @vec_ang(double* %77, double* %79, double* %81)
br label %83
83: ; preds = %72, %76
%84 = phi double [ %82, %76 ], [ 0xC0C387FEB851EB85, %72 ]
%85 = tail call i32 @free_dmatrix(double** %2, i32 1, i32 3, i32 1, i32 3)
ret double %84
}