float normalize(vorig, vnorm)
float vorig[3], vnorm[3];
{
  int k;
  float x;
  x = vector_length(vorig);
  if (x < 0.0001)
    return (0.0);
  for (k = 0; k < 3; k++)
    vnorm[k] = vorig[k] / x;
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <vector_length@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xebb(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    115c <normalize+0x4c>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    119a <normalize+0x8a>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    119a <normalize+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
divss  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1163 <normalize+0x53>
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <vector_length@plt>
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xecf(%rip),%xmm2
ucomisd %xmm1,%xmm2
ja     1162 <normalize+0x52>
movss  (%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x4(%r14)
movss  0x8(%rbx),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x8(%r14)
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define float @normalize(float* %0, float* %1) {
%3 = alloca float
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32
%7 = alloca float
store float* %0, float** %4
store float* %1, float** %5
%8 = load float*, float** %4
%9 = call i32 (float*, ...) bitcast (i32 (...)* @vector_length to i32 (float*, ...)*)(float* %8)
%10 = sitofp i32 %9 to float
store float %10, float* %7
%11 = load float, float* %7
%12 = fpext float %11 to double
%13 = fcmp olt double %12, 1.000000e-04
br i1 %13, label %14, label %15
14: ; preds = %2
store float 0.000000e+00, float* %3
br label %34
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %31, %15
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %34
19: ; preds = %16
%20 = load float*, float** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds float, float* %20, i64 %22
%24 = load float, float* %23
%25 = load float, float* %7
%26 = fdiv float %24, %25
%27 = load float*, float** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %27, i64 %29
store float %26, float* %30
br label %31
31: ; preds = %19
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %16
34: ; preds = %14, %16
%35 = load float, float* %3
ret float %35
}

LLVM IR (-O2):
define float @normalize(float* %0, float* nocapture writeonly %1) {
%3 = tail call i32 (float*, ...) bitcast (i32 (...)* @vector_length to i32 (float*, ...)*)(float* %0)
%4 = sitofp i32 %3 to float
%5 = fpext float %4 to double
%6 = fcmp olt double %5, 1.000000e-04
br i1 %6, label %18, label %7
7: ; preds = %2
%8 = load float, float* %0
%9 = fdiv float %8, %4
store float %9, float* %1
%10 = getelementptr inbounds float, float* %0, i64 1
%11 = load float, float* %10
%12 = fdiv float %11, %4
%13 = getelementptr inbounds float, float* %1, i64 1
store float %12, float* %13
%14 = getelementptr inbounds float, float* %0, i64 2
%15 = load float, float* %14
%16 = fdiv float %15, %4
%17 = getelementptr inbounds float, float* %1, i64 2
store float %16, float* %17
br label %18
18: ; preds = %7, %2
ret float 0.000000e+00
}