#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 acos(double);
int /*<<< orphan*/ printf(char *);
double v3_dotproduct(double *, double *);
double v3_norm(double *);
double v3_angle(double v1[3], double v2[3]) {
  double cosine;
  double angle;
  cosine = v3_dotproduct(v1, v2) / (v3_norm(v1) * v3_norm(v2));
  if (cosine < -1.)
    cosine = -1.;
  else if (cosine > 1.)
    cosine = 1.;
  angle = acos(cosine);
  if (angle < 0.) {
    printf("WARNING! \n");
  }
  if (angle > 3.14159265359) {
    angle = 2. * 3.14159265359 - angle;
  }
  return angle;
}


x86 assembly (clang, -O0):
<v3_angle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <v3_dotproduct@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <v3_norm@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <v3_norm@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe65(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11b8 <v3_angle+0x78>
movsd  0xe52(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e1 <v3_angle+0xa1>
movsd  -0x18(%rbp),%xmm0
movsd  0xe43(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11dc <v3_angle+0x9c>
movsd  0xe31(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e1 <v3_angle+0xa1>
movsd  -0x18(%rbp),%xmm0
call   1050 <acos@plt>
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    120a <v3_angle+0xca>
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  0xdf9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1233 <v3_angle+0xf3>
movsd  0xdef(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v3_angle>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <v3_dotproduct@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1040 <v3_norm@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
call   1040 <v3_norm@plt>
movsd  (%rsp),%xmm1
mulsd  0x10(%rsp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe7c(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     11a0 <v3_angle+0x60>
ucomisd 0xe76(%rip),%xmm1
movapd %xmm1,%xmm0
jbe    11a0 <v3_angle+0x60>
movsd  0xe68(%rip),%xmm0
call   1050 <acos@plt>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    11c9 <v3_angle+0x89>
lea    0xe66(%rip),%rdi
movapd %xmm2,(%rsp)
call   1030 <puts@plt>
movapd (%rsp),%xmm2
movsd  0xe3f(%rip),%xmm1
subsd  %xmm2,%xmm1
movsd  0xe3b(%rip),%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"WARNING! \0A\00"
define double @v3_angle(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
store double* %0, double** %3
store double* %1, double** %4
%7 = load double*, double** %3
%8 = load double*, double** %4
%9 = call double @v3_dotproduct(double* %7, double* %8)
%10 = load double*, double** %3
%11 = call double @v3_norm(double* %10)
%12 = load double*, double** %4
%13 = call double @v3_norm(double* %12)
%14 = fmul double %11, %13
%15 = fdiv double %9, %14
store double %15, double* %5
%16 = load double, double* %5
%17 = fcmp olt double %16, -1.000000e+00
br i1 %17, label %18, label %19
18: ; preds = %2
store double -1.000000e+00, double* %5
br label %24
19: ; preds = %2
%20 = load double, double* %5
%21 = fcmp ogt double %20, 1.000000e+00
br i1 %21, label %22, label %23
22: ; preds = %19
store double 1.000000e+00, double* %5
br label %23
23: ; preds = %22, %19
br label %24
24: ; preds = %23, %18
%25 = load double, double* %5
%26 = call double @acos(double %25)
store double %26, double* %6
%27 = load double, double* %6
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = load double, double* %6
%33 = fcmp ogt double %32, 0x400921FB54442EEA
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load double, double* %6
%36 = fsub double 0x401921FB54442EEA, %35
store double %36, double* %6
br label %37
37: ; preds = %34, %31
%38 = load double, double* %6
ret double %38
}

LLVM IR (-O2):
@str = [10 x i8] c"WARNING! \00"
define double @v3_angle(double* %0, double* %1) {
%3 = tail call double @v3_dotproduct(double* %0, double* %1)
%4 = tail call double @v3_norm(double* %0)
%5 = tail call double @v3_norm(double* %1)
%6 = fmul double %4, %5
%7 = fdiv double %3, %6
%8 = fcmp olt double %7, -1.000000e+00
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = fcmp ogt double %7, 1.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %9
br label %12
12: ; preds = %2, %9, %11
%13 = phi double [ 1.000000e+00, %11 ], [ %7, %9 ], [ -1.000000e+00, %2 ]
%14 = tail call double @acos(double %13)
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = fcmp ogt double %14, 0x400921FB54442EEA
%20 = fsub double 0x401921FB54442EEA, %14
%21 = select i1 %19, double %20, double %14
ret double %21
}