#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 vectorlength(float *);
void normalizevector(float *result, float *vec) {
  float vectorlengthvalue;
  vectorlengthvalue = vectorlength(vec);
  if (vectorlengthvalue != 0.0f) {
    vectorlengthvalue = 1.0f / vectorlengthvalue;
    result[0] = vec[0] * vectorlengthvalue;
    result[1] = vec[1] * vectorlengthvalue;
    result[2] = vec[2] * vectorlengthvalue;
  } else {
    result[0] = 0.0f;
    result[1] = 0.0f;
    result[2] = 0.0f;
  }
}


x86 assembly (clang, -O0):
<normalizevector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <vectorlength@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    114a <normalizevector+0x3a>
jp     114a <normalizevector+0x3a>
jmp    11a4 <normalizevector+0x94>
movss  0xeae(%rip),%xmm0
divss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mulss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mulss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mulss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
jmp    11c7 <normalizevector+0xb7>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%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)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalizevector>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <vectorlength@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    112c <normalizevector+0x1c>
jnp    115b <normalizevector+0x4b>
movss  0xecc(%rip),%xmm1
divss  %xmm0,%xmm1
movss  (%rbx),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,(%r14)
movss  0x4(%rbx),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,0x4(%r14)
mulss  0x8(%rbx),%xmm1
jmp    1162 <normalizevector+0x52>
movq   $0x0,(%r14)
movss  %xmm1,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @normalizevector(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca float
store float* %0, float** %3
store float* %1, float** %4
%6 = load float*, float** %4
%7 = call float @vectorlength(float* %6)
store float %7, float* %5
%8 = load float, float* %5
%9 = fcmp une float %8, 0.000000e+00
br i1 %9, label %10, label %34
10: ; preds = %2
%11 = load float, float* %5
%12 = fdiv float 1.000000e+00, %11
store float %12, float* %5
%13 = load float*, float** %4
%14 = getelementptr inbounds float, float* %13, i64 0
%15 = load float, float* %14
%16 = load float, float* %5
%17 = fmul float %15, %16
%18 = load float*, float** %3
%19 = getelementptr inbounds float, float* %18, i64 0
store float %17, float* %19
%20 = load float*, float** %4
%21 = getelementptr inbounds float, float* %20, i64 1
%22 = load float, float* %21
%23 = load float, float* %5
%24 = fmul float %22, %23
%25 = load float*, float** %3
%26 = getelementptr inbounds float, float* %25, i64 1
store float %24, float* %26
%27 = load float*, float** %4
%28 = getelementptr inbounds float, float* %27, i64 2
%29 = load float, float* %28
%30 = load float, float* %5
%31 = fmul float %29, %30
%32 = load float*, float** %3
%33 = getelementptr inbounds float, float* %32, i64 2
store float %31, float* %33
br label %41
34: ; preds = %2
%35 = load float*, float** %3
%36 = getelementptr inbounds float, float* %35, i64 0
store float 0.000000e+00, float* %36
%37 = load float*, float** %3
%38 = getelementptr inbounds float, float* %37, i64 1
store float 0.000000e+00, float* %38
%39 = load float*, float** %3
%40 = getelementptr inbounds float, float* %39, i64 2
store float 0.000000e+00, float* %40
br label %41
41: ; preds = %34, %10
ret void
}

LLVM IR (-O2):
define void @normalizevector(float* nocapture writeonly %0, float* %1) {
%3 = tail call float @vectorlength(float* %1)
%4 = fcmp une float %3, 0.000000e+00
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = fdiv float 1.000000e+00, %3
%7 = load float, float* %1
%8 = fmul float %6, %7
store float %8, float* %0
%9 = getelementptr inbounds float, float* %1, i64 1
%10 = load float, float* %9
%11 = fmul float %6, %10
%12 = getelementptr inbounds float, float* %0, i64 1
store float %11, float* %12
%13 = getelementptr inbounds float, float* %1, i64 2
%14 = load float, float* %13
%15 = fmul float %6, %14
br label %18
16: ; preds = %2
store float 0.000000e+00, float* %0
%17 = getelementptr inbounds float, float* %0, i64 1
store float 0.000000e+00, float* %17
br label %18
18: ; preds = %16, %5
%19 = phi float [ %15, %5 ], [ 0.000000e+00, %16 ]
%20 = getelementptr inbounds float, float* %0, i64 2
store float %19, float* %20
ret void
}