#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*/ fprintf(int /*<<< orphan*/, char *, double);
int /*<<< orphan*/ stderr;
double vector_mag(double *);
int unit_vector(double v[], double n[]) {
  double mag;
  mag = vector_mag(v);
  if (mag <= 1e-6) {
    fprintf(stderr, "\nunit_mag: ERROR, vector has mag = %.5g <= 1e-6\n", mag);
    return (-1);
  }
  n[0] = v[0] / mag;
  n[1] = v[1] / mag;
  n[2] = v[2] / mag;
  return (0);
}


x86 assembly (clang, -O0):
<unit_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <vector_mag@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xeba(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     1177 <unit_vector+0x57>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
movsd  -0x20(%rbp),%xmm0
lea    0xea2(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <unit_vector+0xa1>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unit_vector>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <vector_mag@plt>
movsd  0xec9(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    116c <unit_vector+0x4c>
movsd  (%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
movsd  0x8(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%r14)
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%r14)
xor    %eax,%eax
jmp    1186 <unit_vector+0x66>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"\0Aunit_mag: ERROR, vector has mag = %.5g <= 1e-6\0A\00"
define i32 @unit_vector(double* %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double*
%6 = alloca double
store double* %0, double** %4
store double* %1, double** %5
%7 = load double*, double** %4
%8 = call double @vector_mag(double* %7)
store double %8, double* %6
%9 = load double, double* %6
%10 = fcmp ole double %9, 0x3EB0C6F7A0B5ED8D
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load double, double* %6
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), double %13)
store i32 -1, i32* %3
br label %37
15: ; preds = %2
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
%19 = load double, double* %6
%20 = fdiv double %18, %19
%21 = load double*, double** %5
%22 = getelementptr inbounds double, double* %21, i64 0
store double %20, double* %22
%23 = load double*, double** %4
%24 = getelementptr inbounds double, double* %23, i64 1
%25 = load double, double* %24
%26 = load double, double* %6
%27 = fdiv double %25, %26
%28 = load double*, double** %5
%29 = getelementptr inbounds double, double* %28, i64 1
store double %27, double* %29
%30 = load double*, double** %4
%31 = getelementptr inbounds double, double* %30, i64 2
%32 = load double, double* %31
%33 = load double, double* %6
%34 = fdiv double %32, %33
%35 = load double*, double** %5
%36 = getelementptr inbounds double, double* %35, i64 2
store double %34, double* %36
store i32 0, i32* %3
br label %37
37: ; preds = %15, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"\0Aunit_mag: ERROR, vector has mag = %.5g <= 1e-6\0A\00"
define i32 @unit_vector(double* %0, double* nocapture writeonly %1) {
%3 = tail call double @vector_mag(double* %0)
%4 = fcmp ugt double %3, 0x3EB0C6F7A0B5ED8D
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), double %3)
br label %19
8: ; preds = %2
%9 = load double, double* %0
%10 = fdiv double %9, %3
store double %10, double* %1
%11 = getelementptr inbounds double, double* %0, i64 1
%12 = load double, double* %11
%13 = fdiv double %12, %3
%14 = getelementptr inbounds double, double* %1, i64 1
store double %13, double* %14
%15 = getelementptr inbounds double, double* %0, i64 2
%16 = load double, double* %15
%17 = fdiv double %16, %3
%18 = getelementptr inbounds double, double* %1, i64 2
store double %17, double* %18
br label %19
19: ; preds = %8, %5
%20 = phi i32 [ -1, %5 ], [ 0, %8 ]
ret i32 %20
}