#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 sqrt(float const);
float v_normalize(const float *v, float *out) {
  float length, ilength;
  length = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  if (length == 0) {
    { (out)[0] = (out)[1] = (out)[2] = 0; };
    return 0;
  }
  ilength = 1.0 / length;
  {
    (out)[0] = (v)[0] * (ilength);
    (out)[1] = (v)[1] * (ilength);
    (out)[2] = (v)[2] * (ilength);
  };
  return length;
}


x86 assembly (clang, -O0):
<v_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b5 <v_normalize+0xa5>
jp     11b5 <v_normalize+0xa5>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1220 <v_normalize+0x110>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe3a(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mulss  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mulss  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mulss  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v_normalize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
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     114a <v_normalize+0x3a>
sqrtss %xmm0,%xmm0
jmp    1152 <v_normalize+0x42>
call   1030 <sqrt@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1168 <v_normalize+0x58>
jp     1168 <v_normalize+0x58>
movq   $0x0,(%r14)
xorps  %xmm1,%xmm1
xorps  %xmm0,%xmm0
jmp    1195 <v_normalize+0x85>
movss  0xe90(%rip),%xmm1
divss  %xmm0,%xmm1
movss  (%rbx),%xmm2
mulss  %xmm1,%xmm2
movss  %xmm2,(%r14)
movss  0x4(%rbx),%xmm2
mulss  %xmm1,%xmm2
movss  %xmm2,0x4(%r14)
mulss  0x8(%rbx),%xmm1
movss  %xmm1,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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