#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 */
int sqrtf(float);
void vec3_normalize(float *dst) {
  float x = dst[0];
  float y = dst[1];
  float z = dst[2];
  float len = x * x + y * y + z * z;
  if (len > 0) {
    len = 1 / sqrtf(len);
    dst[0] = dst[0] * len;
    dst[1] = dst[1] * len;
    dst[2] = dst[2] * len;
  }
}


x86 assembly (clang, -O0):
<vec3_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm1
movss  -0xc(%rbp),%xmm2
movss  -0x10(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11e9 <vec3_normalize+0xd9>
movss  -0x18(%rbp),%xmm0
call   1030 <sqrtf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec3_normalize>:
push   %rbx
movss  (%rdi),%xmm1
movss  0x4(%rdi),%xmm2
movss  0x8(%rdi),%xmm0
mulss  %xmm2,%xmm2
mulss  %xmm1,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1179 <vec3_normalize+0x69>
mov    %rdi,%rbx
call   1030 <sqrtf@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2ss %edx,%xmm0
movss  (%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
movss  0x4(%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%rbx)
mulss  0x8(%rbx),%xmm0
movss  %xmm0,0x8(%rbx)
pop    %rbx
ret

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

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