#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 M_PI;
int acos(double);
int /*<<< orphan*/ get_n_triangle(double *, double *, double *, double *);
double sqrt(double);
double angle_btw_triangles(double *P1, double *P2, double *P3, double *P4) {
  double phi;
  double u[3], v[3];
  double normal1[3], normal2[3];
  get_n_triangle(P1, P2, P3, normal1);
  get_n_triangle(P3, P2, P4, normal2);
  double tmp11;
  tmp11 = normal1[0] * normal2[0] + normal1[1] * normal2[1] +
          normal1[2] * normal2[2];
  tmp11 /= sqrt(normal1[0] * normal1[0] + normal1[1] * normal1[1] +
                normal1[2] * normal1[2]);
  tmp11 /= sqrt(normal2[0] * normal2[0] + normal2[1] * normal2[1] +
                normal2[2] * normal2[2]);
  if (tmp11 >= 1.)
    tmp11 = 0.0;
  else if (tmp11 <= -1.)
    tmp11 = M_PI;
  phi = M_PI - acos(tmp11);
  tmp11 = -(normal1[0] * P1[0] + normal1[1] * P1[1] + normal1[2] * P1[2]);
  if (normal1[0] * P4[0] + normal1[1] * P4[1] + normal1[2] * P4[2] + tmp11 < 0)
    phi = 2 * M_PI - phi;
  return (phi);
}


x86 assembly (clang, -O0):
<angle_btw_triangles>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x80(%rbp),%rcx
call   1030 <get_n_triangle@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
call   1030 <get_n_triangle@plt>
movsd  -0x80(%rbp),%xmm1
movsd  -0xa0(%rbp),%xmm2
ff
movsd  -0x78(%rbp),%xmm0
mulsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
movsd  -0x90(%rbp),%xmm2
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x80(%rbp),%xmm1
movsd  -0x80(%rbp),%xmm2
movsd  -0x78(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
movsd  -0xa0(%rbp),%xmm1
ff
movsd  -0xa0(%rbp),%xmm2
ff
movsd  -0x98(%rbp),%xmm0
ff
mulsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x90(%rbp),%xmm2
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
movsd  0xd93(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1287 <angle_btw_triangles+0x157>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
jmp    12b5 <angle_btw_triangles+0x185>
movsd  0xd79(%rip),%xmm0
ucomisd -0xa8(%rbp),%xmm0
ff
jb     12b0 <angle_btw_triangles+0x180>
mov    0x2d44(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
jmp    12b5 <angle_btw_triangles+0x185>
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
movsd  -0xa8(%rbp),%xmm0
ff
call   1040 <acos@plt>
mov    %eax,%ecx
mov    -0xac(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x80(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x78(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x78(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x70(%rbp),%xmm1
mov    -0x20(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
addsd  -0xa8(%rbp),%xmm1
ff
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    13a4 <angle_btw_triangles+0x274>
mov    0x2c57(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<angle_btw_triangles>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x30(%rsp),%rcx
call   1030 <get_n_triangle@plt>
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <get_n_triangle@plt>
movsd  0x30(%rsp),%xmm1
movsd  0x38(%rsp),%xmm2
movsd  0x18(%rsp),%xmm0
mulsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm0,%xmm3
movsd  0x40(%rsp),%xmm0
movsd  0x20(%rsp),%xmm4
mulsd  %xmm0,%xmm4
addsd  %xmm3,%xmm4
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     11c1 <angle_btw_triangles+0x91>
sqrtsd %xmm0,%xmm0
jmp    11d6 <angle_btw_triangles+0xa6>
movsd  %xmm4,0x8(%rsp)
call   1050 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  0x8(%rsp),%xmm4
divsd  %xmm0,%xmm4
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x20(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     120c <angle_btw_triangles+0xdc>
sqrtsd %xmm0,%xmm0
jmp    121d <angle_btw_triangles+0xed>
movsd  %xmm4,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm4
divsd  %xmm0,%xmm4
ucomisd 0xdd7(%rip),%xmm4
xorpd  %xmm0,%xmm0
jae    124f <angle_btw_triangles+0x11f>
movsd  0xdd1(%rip),%xmm0
ucomisd %xmm4,%xmm0
movapd %xmm4,%xmm0
jb     124f <angle_btw_triangles+0x11f>
mov    0x2da0(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdl (%rax),%xmm0
mov    0x2d92(%rip),%rbx
mov    (%rbx),%ebp
call   1040 <acos@plt>
sub    %eax,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0x30(%rsp),%xmm2
movsd  0x38(%rsp),%xmm3
movsd  0x40(%rsp),%xmm4
unpcklpd %xmm3,%xmm3
movsd  (%r15),%xmm5
movsd  0x8(%r15),%xmm6
movsd  0x10(%r15),%xmm0
movhpd 0x8(%r14),%xmm6
mulpd  %xmm3,%xmm6
unpcklpd %xmm2,%xmm2
movhpd (%r14),%xmm5
mulpd  %xmm2,%xmm5
addpd  %xmm6,%xmm5
unpcklpd %xmm4,%xmm4
movhpd 0x10(%r14),%xmm0
mulpd  %xmm4,%xmm0
addpd  %xmm5,%xmm0
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
subsd  %xmm2,%xmm0
mov    (%rbx),%eax
add    %eax,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
subsd  %xmm1,%xmm2
cmpltsd 0xd32(%rip),%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @angle_btw_triangles(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca [3 x double]
%11 = alloca [3 x double]
%12 = alloca [3 x double]
%13 = alloca [3 x double]
%14 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%15 = load double*, double** %5
%16 = load double*, double** %6
%17 = load double*, double** %7
%18 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%19 = call i32 @get_n_triangle(double* %15, double* %16, double* %17, double* %18)
%20 = load double*, double** %7
%21 = load double*, double** %6
%22 = load double*, double** %8
%23 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%24 = call i32 @get_n_triangle(double* %20, double* %21, double* %22, double* %23)
%25 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%26 = load double, double* %25
%27 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%28 = load double, double* %27
%29 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%30 = load double, double* %29
%31 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%32 = load double, double* %31
%33 = fmul double %30, %32
%34 = call double @llvm.fmuladd.f64(double %26, double %28, double %33)
%35 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%36 = load double, double* %35
%37 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 2
%38 = load double, double* %37
%39 = call double @llvm.fmuladd.f64(double %36, double %38, double %34)
store double %39, double* %14
%40 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%41 = load double, double* %40
%42 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%43 = load double, double* %42
%44 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%45 = load double, double* %44
%46 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%47 = load double, double* %46
%48 = fmul double %45, %47
%49 = call double @llvm.fmuladd.f64(double %41, double %43, double %48)
%50 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%51 = load double, double* %50
%52 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%53 = load double, double* %52
%54 = call double @llvm.fmuladd.f64(double %51, double %53, double %49)
%55 = call double @sqrt(double %54)
%56 = load double, double* %14
%57 = fdiv double %56, %55
store double %57, double* %14
%58 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%59 = load double, double* %58
%60 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%61 = load double, double* %60
%62 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%63 = load double, double* %62
%64 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%65 = load double, double* %64
%66 = fmul double %63, %65
%67 = call double @llvm.fmuladd.f64(double %59, double %61, double %66)
%68 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 2
%69 = load double, double* %68
%70 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 2
%71 = load double, double* %70
%72 = call double @llvm.fmuladd.f64(double %69, double %71, double %67)
%73 = call double @sqrt(double %72)
%74 = load double, double* %14
%75 = fdiv double %74, %73
store double %75, double* %14
%76 = load double, double* %14
%77 = fcmp oge double %76, 1.000000e+00
br i1 %77, label %78, label %79
78: ; preds = %4
store double 0.000000e+00, double* %14
br label %86
79: ; preds = %4
%80 = load double, double* %14
%81 = fcmp ole double %80, -1.000000e+00
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i32, i32* @M_PI
%84 = sitofp i32 %83 to double
store double %84, double* %14
br label %85
85: ; preds = %82, %79
br label %86
86: ; preds = %85, %78
%87 = load i32, i32* @M_PI
%88 = load double, double* %14
%89 = call i32 @acos(double %88)
%90 = sub nsw i32 %87, %89
%91 = sitofp i32 %90 to double
store double %91, double* %9
%92 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%93 = load double, double* %92
%94 = load double*, double** %5
%95 = getelementptr inbounds double, double* %94, i64 0
%96 = load double, double* %95
%97 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%98 = load double, double* %97
%99 = load double*, double** %5
%100 = getelementptr inbounds double, double* %99, i64 1
%101 = load double, double* %100
%102 = fmul double %98, %101
%103 = call double @llvm.fmuladd.f64(double %93, double %96, double %102)
%104 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%105 = load double, double* %104
%106 = load double*, double** %5
%107 = getelementptr inbounds double, double* %106, i64 2
%108 = load double, double* %107
%109 = call double @llvm.fmuladd.f64(double %105, double %108, double %103)
%110 = fneg double %109
store double %110, double* %14
%111 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%112 = load double, double* %111
%113 = load double*, double** %8
%114 = getelementptr inbounds double, double* %113, i64 0
%115 = load double, double* %114
%116 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%117 = load double, double* %116
%118 = load double*, double** %8
%119 = getelementptr inbounds double, double* %118, i64 1
%120 = load double, double* %119
%121 = fmul double %117, %120
%122 = call double @llvm.fmuladd.f64(double %112, double %115, double %121)
%123 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%124 = load double, double* %123
%125 = load double*, double** %8
%126 = getelementptr inbounds double, double* %125, i64 2
%127 = load double, double* %126
%128 = call double @llvm.fmuladd.f64(double %124, double %127, double %122)
%129 = load double, double* %14
%130 = fadd double %128, %129
%131 = fcmp olt double %130, 0.000000e+00
br i1 %131, label %132, label %138
132: ; preds = %86
%133 = load i32, i32* @M_PI
%134 = mul nsw i32 2, %133
%135 = sitofp i32 %134 to double
%136 = load double, double* %9
%137 = fsub double %135, %136
store double %137, double* %9
br label %138
138: ; preds = %132, %86
%139 = load double, double* %9
ret double %139
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @angle_btw_triangles(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = bitcast [3 x double]* %5 to i8*
%8 = bitcast [3 x double]* %6 to i8*
%9 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%10 = call i32 @get_n_triangle(double* %0, double* %1, double* %2, double* %9)
%11 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%12 = call i32 @get_n_triangle(double* %2, double* %1, double* %3, double* %11)
%13 = load double, double* %9
%14 = load double, double* %11
%15 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 1
%16 = load double, double* %15
%17 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
%18 = load double, double* %17
%19 = fmul double %16, %18
%20 = call double @llvm.fmuladd.f64(double %13, double %14, double %19)
%21 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
%22 = load double, double* %21
%23 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 2
%24 = load double, double* %23
%25 = call double @llvm.fmuladd.f64(double %22, double %24, double %20)
%26 = fmul double %16, %16
%27 = call double @llvm.fmuladd.f64(double %13, double %13, double %26)
%28 = call double @llvm.fmuladd.f64(double %22, double %22, double %27)
%29 = call double @sqrt(double %28)
%30 = fdiv double %25, %29
%31 = load double, double* %11
%32 = load double, double* %17
%33 = fmul double %32, %32
%34 = call double @llvm.fmuladd.f64(double %31, double %31, double %33)
%35 = load double, double* %23
%36 = call double @llvm.fmuladd.f64(double %35, double %35, double %34)
%37 = call double @sqrt(double %36)
%38 = fdiv double %30, %37
%39 = fcmp ult double %38, 1.000000e+00
br i1 %39, label %40, label %45
40: ; preds = %4
%41 = fcmp ugt double %38, -1.000000e+00
br i1 %41, label %45, label %42
42: ; preds = %40
%43 = load i32, i32* @M_PI
%44 = sitofp i32 %43 to double
br label %45
45: ; preds = %4, %40, %42
%46 = phi double [ %44, %42 ], [ %38, %40 ], [ 0.000000e+00, %4 ]
%47 = load i32, i32* @M_PI
%48 = call i32 @acos(double %46)
%49 = sub nsw i32 %47, %48
%50 = sitofp i32 %49 to double
%51 = load double, double* %9
%52 = load double, double* %0
%53 = load double, double* %15
%54 = getelementptr inbounds double, double* %0, i64 1
%55 = load double, double* %54
%56 = load double, double* %21
%57 = getelementptr inbounds double, double* %0, i64 2
%58 = load double, double* %57
%59 = load double, double* %3
%60 = getelementptr inbounds double, double* %3, i64 1
%61 = load double, double* %60
%62 = insertelement <2 x double> poison, double %53, i64 0
%63 = shufflevector <2 x double> %62, <2 x double> poison, <2 x i32> zeroinitializer
%64 = insertelement <2 x double> poison, double %61, i64 0
%65 = insertelement <2 x double> %64, double %55, i64 1
%66 = fmul <2 x double> %63, %65
%67 = insertelement <2 x double> poison, double %51, i64 0
%68 = shufflevector <2 x double> %67, <2 x double> poison, <2 x i32> zeroinitializer
%69 = insertelement <2 x double> poison, double %59, i64 0
%70 = insertelement <2 x double> %69, double %52, i64 1
%71 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %68, <2 x double> %70, <2 x double> %66)
%72 = getelementptr inbounds double, double* %3, i64 2
%73 = load double, double* %72
%74 = insertelement <2 x double> poison, double %56, i64 0
%75 = shufflevector <2 x double> %74, <2 x double> poison, <2 x i32> zeroinitializer
%76 = insertelement <2 x double> poison, double %73, i64 0
%77 = insertelement <2 x double> %76, double %58, i64 1
%78 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %75, <2 x double> %77, <2 x double> %71)
%79 = shufflevector <2 x double> %78, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%80 = fsub <2 x double> %78, %79
%81 = extractelement <2 x double> %80, i64 0
%82 = fcmp olt double %81, 0.000000e+00
%83 = load i32, i32* @M_PI
%84 = shl nsw i32 %83, 1
%85 = sitofp i32 %84 to double
%86 = fsub double %85, %50
%87 = select i1 %82, double %86, double %50
ret double %87
}