#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 */
int /*<<< orphan*/ add(double *, double *, double *, int);
int /*<<< orphan*/ mult(double *, double *, int, int);
int norm(double *, int);
int /*<<< orphan*/ proj(double *, double *, double *, int);
int /*<<< orphan*/ sub(double *, double *, double *, int);
double triangle_area(double *, double *, double *, int);
double tetrahedron_volume_old(double x[], double y[], double z[], double w[],
                              int n) {
  double u[n], v[n], v_proj[n];
  sub(u, y, x, n);
  sub(v, z, x, n);
  proj(v_proj, v, u, n);
  sub(v, v, v_proj, n);
  mult(u, u, 1 / norm(u, n), n);
  mult(v, v, 1 / norm(v, n), n);
  double w2[n], wu[n], wv[n], w_proj[n];
  sub(w2, w, x, n);
  proj(wu, w2, u, n);
  proj(wv, w2, v, n);
  add(w_proj, wu, wv, n);
  sub(w2, w2, w_proj, n);
  double h = norm(w2, n);
  double A = triangle_area(x, y, z, n);
  return h * A / 3.0;
}


x86 assembly (clang, -O0):
<tetrahedron_volume_old>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xa8(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xb8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1080 <sub@plt>
mov    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1080 <sub@plt>
mov    -0xb8(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    -0xa0(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   1070 <proj@plt>
mov    -0xb8(%rbp),%rdx
mov    -0xa0(%rbp),%rsi
mov    -0x24(%rbp),%ecx
mov    %rsi,%rdi
call   1080 <sub@plt>
mov    -0xa8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <norm@plt>
mov    -0xa8(%rbp),%rsi
mov    %eax,%ecx
xor    %edx,%edx
mov    %edx,-0xb0(%rbp)
mov    $0x1,%eax
mov    %eax,-0xac(%rbp)
idiv   %ecx
mov    %eax,%edx
mov    -0x24(%rbp),%ecx
mov    %rsi,%rdi
call   1060 <mult@plt>
mov    -0xa0(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <norm@plt>
mov    -0xb0(%rbp),%edx
mov    -0xa0(%rbp),%rsi
mov    %eax,%ecx
mov    -0xac(%rbp),%eax
idiv   %ecx
mov    %eax,%edx
mov    -0x24(%rbp),%ecx
mov    %rsi,%rdi
call   1060 <mult@plt>
mov    -0x24(%rbp),%eax
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x24(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x24(%rbp),%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1080 <sub@plt>
mov    -0xa8(%rbp),%rdx
mov    -0x98(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   1070 <proj@plt>
mov    -0xa0(%rbp),%rdx
mov    -0x90(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x24(%rbp),%ecx
call   1070 <proj@plt>
mov    -0x98(%rbp),%rsi
mov    -0x90(%rbp),%rdx
mov    -0x88(%rbp),%rdi
mov    -0x24(%rbp),%ecx
call   1030 <add@plt>
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rsi
mov    -0x24(%rbp),%ecx
mov    %rsi,%rdi
call   1080 <sub@plt>
mov    -0x80(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <norm@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <triangle_area@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
movsd  0xc07(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tetrahedron_volume_old>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%r14d
mov    %rcx,-0x30(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x60(%rbp)
mov    %rdi,%r12
mov    %rdi,-0x38(%rbp)
mov    %r8d,%eax
mov    %rsp,%r15
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%r15
mov    %r15,%rsp
mov    %rsp,%r13
sub    %rdx,%r13
mov    %rdx,-0x58(%rbp)
mov    %r13,%rsp
mov    %rsp,%rbx
sub    %rdx,%rbx
mov    %rbx,%rsp
mov    %r15,%rdi
mov    %r12,%rdx
mov    %r8d,%ecx
call   1080 <sub@plt>
mov    %r13,%rdi
mov    -0x40(%rbp),%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1080 <sub@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1070 <proj@plt>
mov    %r13,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1080 <sub@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <norm@plt>
lea    0x1(%rax),%ecx
xor    %ebx,%ebx
cmp    $0x3,%ecx
cmovae %ebx,%eax
mov    %r15,-0x50(%rbp)
mov    %r15,%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %r14d,%ecx
call   1060 <mult@plt>
mov    %r13,%rdi
mov    %r14d,%esi
call   1050 <norm@plt>
lea    0x1(%rax),%ecx
cmp    $0x3,%ecx
cmovb  %eax,%ebx
mov    %r13,-0x48(%rbp)
mov    %r13,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %r14d,%ebx
mov    %r14d,%ecx
call   1060 <mult@plt>
mov    %rsp,%r15
mov    -0x58(%rbp),%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    %r15,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    %ebx,%ecx
call   1080 <sub@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    -0x50(%rbp),%rdx
mov    %ebx,%ecx
call   1070 <proj@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    -0x48(%rbp),%rdx
mov    %ebx,%ecx
call   1070 <proj@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %ebx,%ecx
call   1030 <add@plt>
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1080 <sub@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <norm@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    %ebx,%ecx
call   1040 <triangle_area@plt>
mulsd  -0x30(%rbp),%xmm0
divsd  0xd05(%rip),%xmm0
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @tetrahedron_volume_old(double* %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca double
%20 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
%21 = load i32, i32* %10
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %11
%24 = alloca double, i64 %22
store i64 %22, i64* %12
%25 = load i32, i32* %10
%26 = zext i32 %25 to i64
%27 = alloca double, i64 %26
store i64 %26, i64* %13
%28 = load i32, i32* %10
%29 = zext i32 %28 to i64
%30 = alloca double, i64 %29
store i64 %29, i64* %14
%31 = load double*, double** %7
%32 = load double*, double** %6
%33 = load i32, i32* %10
%34 = call i32 @sub(double* %24, double* %31, double* %32, i32 %33)
%35 = load double*, double** %8
%36 = load double*, double** %6
%37 = load i32, i32* %10
%38 = call i32 @sub(double* %27, double* %35, double* %36, i32 %37)
%39 = load i32, i32* %10
%40 = call i32 @proj(double* %30, double* %27, double* %24, i32 %39)
%41 = load i32, i32* %10
%42 = call i32 @sub(double* %27, double* %27, double* %30, i32 %41)
%43 = load i32, i32* %10
%44 = call i32 @norm(double* %24, i32 %43)
%45 = sdiv i32 1, %44
%46 = load i32, i32* %10
%47 = call i32 @mult(double* %24, double* %24, i32 %45, i32 %46)
%48 = load i32, i32* %10
%49 = call i32 @norm(double* %27, i32 %48)
%50 = sdiv i32 1, %49
%51 = load i32, i32* %10
%52 = call i32 @mult(double* %27, double* %27, i32 %50, i32 %51)
%53 = load i32, i32* %10
%54 = zext i32 %53 to i64
%55 = alloca double, i64 %54
store i64 %54, i64* %15
%56 = load i32, i32* %10
%57 = zext i32 %56 to i64
%58 = alloca double, i64 %57
store i64 %57, i64* %16
%59 = load i32, i32* %10
%60 = zext i32 %59 to i64
%61 = alloca double, i64 %60
store i64 %60, i64* %17
%62 = load i32, i32* %10
%63 = zext i32 %62 to i64
%64 = alloca double, i64 %63
store i64 %63, i64* %18
%65 = load double*, double** %9
%66 = load double*, double** %6
%67 = load i32, i32* %10
%68 = call i32 @sub(double* %55, double* %65, double* %66, i32 %67)
%69 = load i32, i32* %10
%70 = call i32 @proj(double* %58, double* %55, double* %24, i32 %69)
%71 = load i32, i32* %10
%72 = call i32 @proj(double* %61, double* %55, double* %27, i32 %71)
%73 = load i32, i32* %10
%74 = call i32 @add(double* %64, double* %58, double* %61, i32 %73)
%75 = load i32, i32* %10
%76 = call i32 @sub(double* %55, double* %55, double* %64, i32 %75)
%77 = load i32, i32* %10
%78 = call i32 @norm(double* %55, i32 %77)
%79 = sitofp i32 %78 to double
store double %79, double* %19
%80 = load double*, double** %6
%81 = load double*, double** %7
%82 = load double*, double** %8
%83 = load i32, i32* %10
%84 = call double @triangle_area(double* %80, double* %81, double* %82, i32 %83)
store double %84, double* %20
%85 = load double, double* %19
%86 = load double, double* %20
%87 = fmul double %85, %86
%88 = fdiv double %87, 3.000000e+00
%89 = load i8*, i8** %11
ret double %88
}

LLVM IR (-O2):
define double @tetrahedron_volume_old(double* %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = zext i32 %4 to i64
%7 = alloca double, i64 %6
%8 = alloca double, i64 %6
%9 = alloca double, i64 %6
%10 = call i32 @sub(double* %7, double* %1, double* %0, i32 %4)
%11 = call i32 @sub(double* %8, double* %2, double* %0, i32 %4)
%12 = call i32 @proj(double* %9, double* %8, double* %7, i32 %4)
%13 = call i32 @sub(double* %8, double* %8, double* %9, i32 %4)
%14 = call i32 @norm(double* %7, i32 %4)
%15 = add i32 %14, 1
%16 = icmp ult i32 %15, 3
%17 = select i1 %16, i32 %14, i32 0
%18 = call i32 @mult(double* %7, double* %7, i32 %17, i32 %4)
%19 = call i32 @norm(double* %8, i32 %4)
%20 = add i32 %19, 1
%21 = icmp ult i32 %20, 3
%22 = select i1 %21, i32 %19, i32 0
%23 = call i32 @mult(double* %8, double* %8, i32 %22, i32 %4)
%24 = alloca double, i64 %6
%25 = alloca double, i64 %6
%26 = alloca double, i64 %6
%27 = alloca double, i64 %6
%28 = call i32 @sub(double* %24, double* %3, double* %0, i32 %4)
%29 = call i32 @proj(double* %25, double* %24, double* %7, i32 %4)
%30 = call i32 @proj(double* %26, double* %24, double* %8, i32 %4)
%31 = call i32 @add(double* %27, double* %25, double* %26, i32 %4)
%32 = call i32 @sub(double* %24, double* %24, double* %27, i32 %4)
%33 = call i32 @norm(double* %24, i32 %4)
%34 = sitofp i32 %33 to double
%35 = call double @triangle_area(double* %0, double* %1, double* %2, i32 %4)
%36 = fmul double %35, %34
%37 = fdiv double %36, 3.000000e+00
ret double %37
}