#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 */
scalar_t__ sqrt(float);
float rsVec_normalize(float *v) {
  float length;
  length = (float)sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  if (length == 0.0f) {
    v[1] = 1.0f;
    return (0.0f);
  }
  v[0] /= length;
  v[1] /= length;
  v[2] /= length;
  return length;
}


x86 assembly (clang, -O0):
<rsVec_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%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>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11a4 <rsVec_normalize+0x94>
jp     11a4 <rsVec_normalize+0x94>
mov    -0x10(%rbp),%rax
movss  0xe6e(%rip),%xmm0
movss  %xmm0,0x4(%rax)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11f1 <rsVec_normalize+0xe1>
movss  -0x14(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
movss  -0x14(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x4(%rax)
movss  -0x14(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x8(%rax)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsVec_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
call   1030 <sqrt@plt>
test   %rax,%rax
je     1172 <rsVec_normalize+0x62>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
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
movl   $0x3f800000,0x4(%rbx)
xorps  %xmm0,%xmm0
pop    %rbx
ret

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

LLVM IR (-O2):
define float @rsVec_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 i64 @sqrt(float %9)
%11 = sitofp i64 %10 to float
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store float 1.000000e+00, float* %3
br label %21
14: ; preds = %1
%15 = load float, float* %0
%16 = fdiv float %15, %11
store float %16, float* %0
%17 = load float, float* %3
%18 = fdiv float %17, %11
store float %18, float* %3
%19 = load float, float* %7
%20 = fdiv float %19, %11
store float %20, float* %7
br label %21
21: ; preds = %14, %13
%22 = phi float [ 0.000000e+00, %13 ], [ %11, %14 ]
ret float %22
}