#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 sqrt(double);
double *lunit(double *v, double *r) {
  double len = 0;
  short i;
  for (i = 0; i < 3; i++)
    len += v[i] * v[i];
  len = sqrt(len);
  if (len)
    for (i = 0; i < 3; i++)
      r[i] = v[i] / len;
  else
    r[0] = r[1] = r[2] = 0;
  return (r);
}


x86 assembly (clang, -O0):
<lunit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movw   $0x0,-0x1a(%rbp)
movswl -0x1a(%rbp),%eax
cmp    $0x3,%eax
jge    117a <lunit+0x6a>
mov    -0x8(%rbp),%rax
movswq -0x1a(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movswq -0x1a(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
jmp    112e <lunit+0x1e>
movsd  -0x18(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a6 <lunit+0x96>
jp     11a6 <lunit+0x96>
jmp    11f0 <lunit+0xe0>
movw   $0x0,-0x1a(%rbp)
movswl -0x1a(%rbp),%eax
cmp    $0x3,%eax
jge    11eb <lunit+0xdb>
mov    -0x8(%rbp),%rax
movswq -0x1a(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movswq -0x1a(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
jmp    11ac <lunit+0x9c>
jmp    1213 <lunit+0x103>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lunit>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
mulsd  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1150 <lunit+0x40>
sqrtsd %xmm0,%xmm0
jmp    1159 <lunit+0x49>
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    1161 <lunit+0x51>
jnp    118e <lunit+0x7e>
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)
jmp    119f <lunit+0x8f>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%r14)
movq   $0x0,0x10(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double* @lunit(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca i16
store double* %0, double** %3
store double* %1, double** %4
store double 0.000000e+00, double* %5
store i16 0, i16* %6
br label %7
7: ; preds = %24, %2
%8 = load i16, i16* %6
%9 = sext i16 %8 to i32
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load double*, double** %3
%13 = load i16, i16* %6
%14 = sext i16 %13 to i64
%15 = getelementptr inbounds double, double* %12, i64 %14
%16 = load double, double* %15
%17 = load double*, double** %3
%18 = load i16, i16* %6
%19 = sext i16 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = load double, double* %5
%23 = call double @llvm.fmuladd.f64(double %16, double %21, double %22)
store double %23, double* %5
br label %24
24: ; preds = %11
%25 = load i16, i16* %6
%26 = add i16 %25, 1
store i16 %26, i16* %6
br label %7
27: ; preds = %7
%28 = load double, double* %5
%29 = call double @sqrt(double %28)
store double %29, double* %5
%30 = load double, double* %5
%31 = fcmp une double %30, 0.000000e+00
br i1 %31, label %32, label %53
32: ; preds = %27
store i16 0, i16* %6
br label %33
33: ; preds = %49, %32
%34 = load i16, i16* %6
%35 = sext i16 %34 to i32
%36 = icmp slt i32 %35, 3
br i1 %36, label %37, label %52
37: ; preds = %33
%38 = load double*, double** %3
%39 = load i16, i16* %6
%40 = sext i16 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double, double* %5
%44 = fdiv double %42, %43
%45 = load double*, double** %4
%46 = load i16, i16* %6
%47 = sext i16 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
store double %44, double* %48
br label %49
49: ; preds = %37
%50 = load i16, i16* %6
%51 = add i16 %50, 1
store i16 %51, i16* %6
br label %33
52: ; preds = %33
br label %60
53: ; preds = %27
%54 = load double*, double** %4
%55 = getelementptr inbounds double, double* %54, i64 2
store double 0.000000e+00, double* %55
%56 = load double*, double** %4
%57 = getelementptr inbounds double, double* %56, i64 1
store double 0.000000e+00, double* %57
%58 = load double*, double** %4
%59 = getelementptr inbounds double, double* %58, i64 0
store double 0.000000e+00, double* %59
br label %60
60: ; preds = %53, %52
%61 = load double*, double** %4
ret double* %61
}

LLVM IR (-O2):
define double* @lunit(double* nocapture %0, double* returned writeonly %1) {
%3 = load double, double* %0
%4 = tail call double @llvm.fmuladd.f64(double %3, double %3, double 0.000000e+00)
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %4)
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %7)
%11 = tail call double @sqrt(double %10)
%12 = fcmp une double %11, 0.000000e+00
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load double, double* %0
%15 = fdiv double %14, %11
store double %15, double* %1
%16 = load double, double* %5
%17 = fdiv double %16, %11
%18 = getelementptr inbounds double, double* %1, i64 1
store double %17, double* %18
%19 = load double, double* %8
%20 = fdiv double %19, %11
%21 = getelementptr inbounds double, double* %1, i64 2
store double %20, double* %21
br label %24
22: ; preds = %2
%23 = bitcast double* %1 to i8*
br label %24
24: ; preds = %13, %22
ret double* %1
}