#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 */
float sqrtf(float);
void Normalize(float *v) {
  const float length = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  if (length > 1e-04f) {
    const float invLength = 1.0f / length;
    v[0] *= invLength;
    v[1] *= invLength;
    v[2] *= invLength;
  } else {
    v[0] = 0;
    v[1] = 0;
    v[2] = 0;
  }
}


x86 assembly (clang, -O0):
<Normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrtf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe89(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11ce <Normalize+0xbe>
movss  0xe7c(%rip),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,(%rax)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
movss  %xmm0,0x4(%rax)
movss  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x8(%rax),%xmm0
movss  %xmm0,0x8(%rax)
jmp    11f1 <Normalize+0xe1>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Normalize>:
push   %rbx
mov    %rdi,%rbx
movss  (%rdi),%xmm1
movss  0x4(%rdi),%xmm0
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0x8(%rdi),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1157 <Normalize+0x47>
sqrtss %xmm0,%xmm0
ucomiss 0xeb7(%rip),%xmm0
ja     1165 <Normalize+0x55>
movq   $0x0,(%rbx)
xorps  %xmm1,%xmm1
jmp    1190 <Normalize+0x80>
call   1030 <sqrtf@plt>
ucomiss 0xe9d(%rip),%xmm0
jbe    114b <Normalize+0x3b>
movss  0xe97(%rip),%xmm1
divss  %xmm0,%xmm1
movss  (%rbx),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,(%rbx)
movss  0x4(%rbx),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,0x4(%rbx)
mulss  0x8(%rbx),%xmm1
movss  %xmm1,0x8(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @Normalize(float* %0) {
%2 = alloca float*
%3 = alloca float
%4 = alloca float
store float* %0, float** %2
%5 = load float*, float** %2
%6 = getelementptr inbounds float, float* %5, i64 0
%7 = load float, float* %6
%8 = load float*, float** %2
%9 = getelementptr inbounds float, float* %8, i64 0
%10 = load float, float* %9
%11 = load float*, float** %2
%12 = getelementptr inbounds float, float* %11, i64 1
%13 = load float, float* %12
%14 = load float*, float** %2
%15 = getelementptr inbounds float, float* %14, i64 1
%16 = load float, float* %15
%17 = fmul float %13, %16
%18 = call float @llvm.fmuladd.f32(float %7, float %10, float %17)
%19 = load float*, float** %2
%20 = getelementptr inbounds float, float* %19, i64 2
%21 = load float, float* %20
%22 = load float*, float** %2
%23 = getelementptr inbounds float, float* %22, i64 2
%24 = load float, float* %23
%25 = call float @llvm.fmuladd.f32(float %21, float %24, float %18)
%26 = call float @sqrtf(float %25)
store float %26, float* %3
%27 = load float, float* %3
%28 = fcmp ogt float %27, 0x3F1A36E2E0000000
br i1 %28, label %29, label %47
29: ; preds = %1
%30 = load float, float* %3
%31 = fdiv float 1.000000e+00, %30
store float %31, float* %4
%32 = load float, float* %4
%33 = load float*, float** %2
%34 = getelementptr inbounds float, float* %33, i64 0
%35 = load float, float* %34
%36 = fmul float %35, %32
store float %36, float* %34
%37 = load float, float* %4
%38 = load float*, float** %2
%39 = getelementptr inbounds float, float* %38, i64 1
%40 = load float, float* %39
%41 = fmul float %40, %37
store float %41, float* %39
%42 = load float, float* %4
%43 = load float*, float** %2
%44 = getelementptr inbounds float, float* %43, i64 2
%45 = load float, float* %44
%46 = fmul float %45, %42
store float %46, float* %44
br label %54
47: ; preds = %1
%48 = load float*, float** %2
%49 = getelementptr inbounds float, float* %48, i64 0
store float 0.000000e+00, float* %49
%50 = load float*, float** %2
%51 = getelementptr inbounds float, float* %50, i64 1
store float 0.000000e+00, float* %51
%52 = load float*, float** %2
%53 = getelementptr inbounds float, float* %52, i64 2
store float 0.000000e+00, float* %53
br label %54
54: ; preds = %47, %29
ret void
}

LLVM IR (-O2):
define void @Normalize(float* nocapture %0) {
%2 = load float, float* %0
%3 = getelementptr inbounds float, float* %0, i64 1
%4 = load float, float* %3
%5 = fmul float %4, %4
%6 = tail call float @llvm.fmuladd.f32(float %2, float %2, float %5)
%7 = getelementptr inbounds float, float* %0, i64 2
%8 = load float, float* %7
%9 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %6)
%10 = tail call float @sqrtf(float %9)
%11 = fcmp ogt float %10, 0x3F1A36E2E0000000
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = fdiv float 1.000000e+00, %10
%14 = load float, float* %0
%15 = fmul float %13, %14
store float %15, float* %0
%16 = load float, float* %3
%17 = fmul float %13, %16
store float %17, float* %3
%18 = load float, float* %7
%19 = fmul float %13, %18
br label %21
20: ; preds = %1
store float 0.000000e+00, float* %0
store float 0.000000e+00, float* %3
br label %21
21: ; preds = %20, %12
%22 = phi float [ 0.000000e+00, %20 ], [ %19, %12 ]
store float %22, float* %7
ret void
}