#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 */
scalar_t__ pow(double, int);
double sqrt(scalar_t__);
void unit_vector(double a[3]) {
  double mod;
  mod = sqrt(pow(a[0], 2) + pow(a[1], 2) + pow(a[2], 2));
  if (mod > 0.0) {
    a[0] /= mod;
    a[1] /= mod;
    a[2] /= mod;
  }
}


x86 assembly (clang, -O0):
<unit_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    -0x18(%rbp),%rdi
add    %rax,%rdi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11dc <unit_vector+0xbc>
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unit_vector>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movsd  (%rdi),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %rax,%rbx
movsd  0x8(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
add    %rax,%rbx
movsd  0x10(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   1040 <sqrt@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1196 <unit_vector+0x76>
movupd (%r14),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movupd %xmm1,(%r14)
movsd  0x10(%r14),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @unit_vector(double* %0) {
%2 = alloca double*
%3 = alloca double
store double* %0, double** %2
%4 = load double*, double** %2
%5 = getelementptr inbounds double, double* %4, i64 0
%6 = load double, double* %5
%7 = call i64 @pow(double %6, i32 2)
%8 = load double*, double** %2
%9 = getelementptr inbounds double, double* %8, i64 1
%10 = load double, double* %9
%11 = call i64 @pow(double %10, i32 2)
%12 = add nsw i64 %7, %11
%13 = load double*, double** %2
%14 = getelementptr inbounds double, double* %13, i64 2
%15 = load double, double* %14
%16 = call i64 @pow(double %15, i32 2)
%17 = add nsw i64 %12, %16
%18 = call double @sqrt(i64 %17)
store double %18, double* %3
%19 = load double, double* %3
%20 = fcmp ogt double %19, 0.000000e+00
br i1 %20, label %21, label %37
21: ; preds = %1
%22 = load double, double* %3
%23 = load double*, double** %2
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = fdiv double %25, %22
store double %26, double* %24
%27 = load double, double* %3
%28 = load double*, double** %2
%29 = getelementptr inbounds double, double* %28, i64 1
%30 = load double, double* %29
%31 = fdiv double %30, %27
store double %31, double* %29
%32 = load double, double* %3
%33 = load double*, double** %2
%34 = getelementptr inbounds double, double* %33, i64 2
%35 = load double, double* %34
%36 = fdiv double %35, %32
store double %36, double* %34
br label %37
37: ; preds = %21, %1
ret void
}

LLVM IR (-O2):
define void @unit_vector(double* nocapture %0) {
%2 = load double, double* %0
%3 = tail call i64 @pow(double %2, i32 2)
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = tail call i64 @pow(double %5, i32 2)
%7 = add nsw i64 %6, %3
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = tail call i64 @pow(double %9, i32 2)
%11 = add nsw i64 %7, %10
%12 = tail call double @sqrt(i64 %11)
%13 = fcmp ogt double %12, 0.000000e+00
br i1 %13, label %14, label %23
14: ; preds = %1
%15 = bitcast double* %0 to <2 x double>*
%16 = load <2 x double>, <2 x double>* %15
%17 = insertelement <2 x double> poison, double %12, i64 0
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
%19 = fdiv <2 x double> %16, %18
%20 = bitcast double* %0 to <2 x double>*
store <2 x double> %19, <2 x double>* %20
%21 = load double, double* %8
%22 = fdiv double %21, %12
store double %22, double* %8
br label %23
23: ; preds = %14, %1
ret void
}