#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 vec3d_dot(double *, double const *);
int /*<<< orphan*/ vec3d_rot(double *, double *, double *);
int /*<<< orphan*/ vec3d_sub(double *, double const *, double const *);
double polyhedron_vol(int N, const double tri[N][3][3]) {
  double sum = 0.;
  for (int i = 0; i < N; i++) {
    double a[3];
    double b[3];
    vec3d_sub(a, tri[i][0], tri[i][1]);
    vec3d_sub(b, tri[i][0], tri[i][2]);
    double n[3];
    vec3d_rot(n, a, b);
    double r = vec3d_dot(n, tri[i][0]);
    sum += r / 6.;
  }
  return sum;
}


x86 assembly (clang, -O0):
<polyhedron_vol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1210 <polyhedron_vol+0xe0>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
movslq -0x1c(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rdx
add    $0x18,%rdx
call   1040 <vec3d_sub@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
movslq -0x1c(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rdx
add    $0x30,%rdx
call   1040 <vec3d_sub@plt>
lea    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1030 <vec3d_rot@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rsi
call   1050 <vec3d_dot@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
movsd  0xe0c(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <polyhedron_vol+0x21>
movsd  -0x18(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polyhedron_vol>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
test   %edi,%edi
jle    11c7 <polyhedron_vol+0x97>
mov    %rsi,%rbx
mov    %edi,%r13d
xorpd  %xmm0,%xmm0
lea    0x50(%rsp),%r14
lea    0x30(%rsp),%r15
lea    0x10(%rsp),%r12
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
lea    0x18(%rbx),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <vec3d_sub@plt>
lea    0x30(%rbx),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <vec3d_sub@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <vec3d_rot@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <vec3d_dot@plt>
divsd  0xe5b(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x48,%rbx
add    $0xffffffffffffffff,%r13
jne    1160 <polyhedron_vol+0x30>
jmp    11cb <polyhedron_vol+0x9b>
xorpd  %xmm0,%xmm0
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @polyhedron_vol(i32 %0, [3 x [3 x double]]* %1) {
%3 = alloca i32
%4 = alloca [3 x [3 x double]]*
%5 = alloca double
%6 = alloca i32
%7 = alloca [3 x double]
%8 = alloca [3 x double]
%9 = alloca [3 x double]
%10 = alloca double
store i32 %0, i32* %3
store [3 x [3 x double]]* %1, [3 x [3 x double]]** %4
%11 = load i32, i32* %3
%12 = zext i32 %11 to i64
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %13
13: ; preds = %62, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %65
17: ; preds = %13
%18 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%19 = load [3 x [3 x double]]*, [3 x [3 x double]]** %4
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %19, i64 %21
%23 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %22, i64 0, i64 0
%24 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 0, i64 0
%25 = load [3 x [3 x double]]*, [3 x [3 x double]]** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %25, i64 %27
%29 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %28, i64 0, i64 1
%30 = getelementptr inbounds [3 x double], [3 x double]* %29, i64 0, i64 0
%31 = call i32 @vec3d_sub(double* %18, double* %24, double* %30)
%32 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%33 = load [3 x [3 x double]]*, [3 x [3 x double]]** %4
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %33, i64 %35
%37 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %36, i64 0, i64 0
%38 = getelementptr inbounds [3 x double], [3 x double]* %37, i64 0, i64 0
%39 = load [3 x [3 x double]]*, [3 x [3 x double]]** %4
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %39, i64 %41
%43 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %42, i64 0, i64 2
%44 = getelementptr inbounds [3 x double], [3 x double]* %43, i64 0, i64 0
%45 = call i32 @vec3d_sub(double* %32, double* %38, double* %44)
%46 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%47 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%48 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%49 = call i32 @vec3d_rot(double* %46, double* %47, double* %48)
%50 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%51 = load [3 x [3 x double]]*, [3 x [3 x double]]** %4
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %51, i64 %53
%55 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %54, i64 0, i64 0
%56 = getelementptr inbounds [3 x double], [3 x double]* %55, i64 0, i64 0
%57 = call double @vec3d_dot(double* %50, double* %56)
store double %57, double* %10
%58 = load double, double* %10
%59 = fdiv double %58, 6.000000e+00
%60 = load double, double* %5
%61 = fadd double %60, %59
store double %61, double* %5
br label %62
62: ; preds = %17
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %13
65: ; preds = %13
%66 = load double, double* %5
ret double %66
}

LLVM IR (-O2):
define double @polyhedron_vol(i32 %0, [3 x [3 x double]]* %1) {
%3 = alloca [3 x double]
%4 = alloca [3 x double]
%5 = alloca [3 x double]
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = bitcast [3 x double]* %3 to i8*
%9 = bitcast [3 x double]* %4 to i8*
%10 = getelementptr inbounds [3 x double], [3 x double]* %3, i64 0, i64 0
%11 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%12 = bitcast [3 x double]* %5 to i8*
%13 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%14 = zext i32 %0 to i64
br label %17
15: ; preds = %17, %2
%16 = phi double [ 0.000000e+00, %2 ], [ %28, %17 ]
ret double %16
17: ; preds = %7, %17
%18 = phi i64 [ 0, %7 ], [ %29, %17 ]
%19 = phi double [ 0.000000e+00, %7 ], [ %28, %17 ]
%20 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 %18, i64 0, i64 0
%21 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 %18, i64 1, i64 0
%22 = call i32 @vec3d_sub(double* %10, double* %20, double* %21)
%23 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %1, i64 %18, i64 2, i64 0
%24 = call i32 @vec3d_sub(double* %11, double* %20, double* %23)
%25 = call i32 @vec3d_rot(double* %13, double* %10, double* %11)
%26 = call double @vec3d_dot(double* %13, double* %20)
%27 = fdiv double %26, 6.000000e+00
%28 = fadd double %19, %27
%29 = add nuw nsw i64 %18, 1
%30 = icmp eq i64 %29, %14
br i1 %30, label %15, label %17
}