#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 vecLength(double *);
double *vecNormalise(double *v) {
  double length = vecLength(v);
  if (length > 0) {
    v[0] = v[0] / length;
    v[1] = v[1] / length;
    v[2] = v[2] / length;
  }
  return v;
}


x86 assembly (clang, -O0):
<vecNormalise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <vecLength@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    117f <vecNormalise+0x6f>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vecNormalise>:
push   %rbx
mov    %rdi,%rbx
call   1030 <vecLength@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1145 <vecNormalise+0x35>
movupd (%rbx),%xmm1
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
divpd  %xmm2,%xmm1
movupd %xmm1,(%rbx)
movsd  0x10(%rbx),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define double* @vecNormalise(double* returned %0) {
%2 = tail call double @vecLength(double* %0)
%3 = fcmp ogt double %2, 0.000000e+00
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = bitcast double* %0 to <2 x double>*
%6 = load <2 x double>, <2 x double>* %5
%7 = insertelement <2 x double> poison, double %2, i64 0
%8 = shufflevector <2 x double> %7, <2 x double> poison, <2 x i32> zeroinitializer
%9 = fdiv <2 x double> %6, %8
%10 = bitcast double* %0 to <2 x double>*
store <2 x double> %9, <2 x double>* %10
%11 = getelementptr inbounds double, double* %0, i64 2
%12 = load double, double* %11
%13 = fdiv double %12, %2
store double %13, double* %11
br label %14
14: ; preds = %4, %1
ret double* %0
}