#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);
float VectorNormalize(float *vx, float *vy, float *vz) {
  float A, B, C;
  float modf;
  float mod2;
  float mod;
  A = *vx;
  B = *vy;
  C = *vz;
  mod2 = A * A + B * B + C * C;
  if (mod2 > 0.0001f) {
    mod = sqrtf(mod2);
    modf = 1.0f / mod;
    *vx = A * modf;
    *vy = B * modf;
    *vz = C * modf;
  } else {
    mod = 0.0;
    *vx = 0.0;
    *vy = 0.0;
    *vz = 1.0;
  }
  return mod;
}


x86 assembly (clang, -O0):
<VectorNormalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
movss  -0x20(%rbp),%xmm0
mulss  -0x20(%rbp),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
movss  -0x24(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
movss  0xe75(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11f0 <VectorNormalize+0xe0>
movss  -0x2c(%rbp),%xmm0
call   1030 <sqrtf@plt>
movss  %xmm0,-0x30(%rbp)
movss  0xe59(%rip),%xmm0
divss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x1c(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x20(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x24(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
jmp    121e <VectorNormalize+0x10e>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movss  0xdea(%rip),%xmm0
movss  %xmm0,(%rax)
movss  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VectorNormalize>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movss  (%rdi),%xmm4
movss  (%rsi),%xmm3
movss  (%rdx),%xmm2
movaps %xmm3,%xmm0
mulss  %xmm3,%xmm0
movaps %xmm4,%xmm1
mulss  %xmm4,%xmm1
addss  %xmm0,%xmm1
movaps %xmm2,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xeae(%rip),%xmm0
jbe    1162 <VectorNormalize+0x52>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     117c <VectorNormalize+0x6c>
sqrtss %xmm0,%xmm0
jmp    11a5 <VectorNormalize+0x95>
movl   $0x0,(%rbx)
movl   $0x0,(%r15)
xorps  %xmm0,%xmm0
movss  0xe8a(%rip),%xmm2
jmp    11c6 <VectorNormalize+0xb6>
movss  %xmm2,0xc(%rsp)
movss  %xmm3,0x8(%rsp)
movss  %xmm4,0x4(%rsp)
call   1030 <sqrtf@plt>
movss  0x4(%rsp),%xmm4
movss  0x8(%rsp),%xmm3
movss  0xc(%rsp),%xmm2
movss  0xe57(%rip),%xmm1
divss  %xmm0,%xmm1
mulss  %xmm1,%xmm4
movss  %xmm4,(%rbx)
mulss  %xmm1,%xmm3
movss  %xmm3,(%r15)
mulss  %xmm1,%xmm2
movss  %xmm2,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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