#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);
double bot_vector_dot_3d(double const *, double const *);
double bot_vector_magnitude_3d(double const *);
double bot_vector_angle_3d(const double v1[3], const double v2[3]) {
  double mag1 = bot_vector_magnitude_3d(v1);
  double mag2 = bot_vector_magnitude_3d(v2);
  double dot = bot_vector_dot_3d(v1, v2);
  double costheta = dot / (mag1 * mag2);
  if (costheta > 1)
    return 0;
  return acos(costheta);
}


x86 assembly (clang, -O0):
<bot_vector_angle_3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <bot_vector_magnitude_3d@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <bot_vector_magnitude_3d@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <bot_vector_dot_3d@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe6d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11aa <bot_vector_angle_3d+0x7a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b9 <bot_vector_angle_3d+0x89>
movsd  -0x38(%rbp),%xmm0
call   1040 <acos@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_vector_angle_3d>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <bot_vector_magnitude_3d@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
call   1030 <bot_vector_magnitude_3d@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <bot_vector_dot_3d@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
divsd  %xmm1,%xmm0
ucomisd 0xe87(%rip),%xmm0
jbe    1187 <bot_vector_angle_3d+0x57>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1040 <acos@plt>

LLVM IR (-O0):
define double @bot_vector_angle_3d(double* %0, double* %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca double*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double* %0, double** %4
store double* %1, double** %5
%10 = load double*, double** %4
%11 = call double @bot_vector_magnitude_3d(double* %10)
store double %11, double* %6
%12 = load double*, double** %5
%13 = call double @bot_vector_magnitude_3d(double* %12)
store double %13, double* %7
%14 = load double*, double** %4
%15 = load double*, double** %5
%16 = call double @bot_vector_dot_3d(double* %14, double* %15)
store double %16, double* %8
%17 = load double, double* %8
%18 = load double, double* %6
%19 = load double, double* %7
%20 = fmul double %18, %19
%21 = fdiv double %17, %20
store double %21, double* %9
%22 = load double, double* %9
%23 = fcmp ogt double %22, 1.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %2
store double 0.000000e+00, double* %3
br label %28
25: ; preds = %2
%26 = load double, double* %9
%27 = call double @acos(double %26)
store double %27, double* %3
br label %28
28: ; preds = %25, %24
%29 = load double, double* %3
ret double %29
}

LLVM IR (-O2):
define double @bot_vector_angle_3d(double* %0, double* %1) {
%3 = tail call double @bot_vector_magnitude_3d(double* %0)
%4 = tail call double @bot_vector_magnitude_3d(double* %1)
%5 = tail call double @bot_vector_dot_3d(double* %0, double* %1)
%6 = fmul double %3, %4
%7 = fdiv double %5, %6
%8 = fcmp ogt double %7, 1.000000e+00
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call double @acos(double %7)
br label %11
11: ; preds = %2, %9
%12 = phi double [ %10, %9 ], [ 0.000000e+00, %2 ]
ret double %12
}