#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);
void normalize(float v[3]) {
  float d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  if (d == 0.0) {
    v[0] = 1.0;
    v[1] = 0.0;
    v[2] = 0.0;
    return;
  }
  v[0] /= d;
  v[1] /= d;
  v[2] /= d;
}


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 <sqrt@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b3 <normalize+0xa3>
jp     11b3 <normalize+0xa3>
mov    -0x8(%rbp),%rax
movss  0xe6e(%rip),%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)
jmp    11f6 <normalize+0xe6>
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x4(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  %xmm1,%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     1144 <normalize+0x34>
sqrtss %xmm0,%xmm0
jmp    114c <normalize+0x3c>
call   1030 <sqrt@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    115f <normalize+0x4f>
jp     115f <normalize+0x4f>
movq   $0x3f800000,(%rbx)
xorps  %xmm1,%xmm1
jmp    1182 <normalize+0x72>
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm2
divss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
divss  %xmm0,%xmm2
movss  %xmm2,0x4(%rbx)
movss  0x8(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%rbx)
pop    %rbx
ret

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