#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);
bool CalcNormalize2(float vec[3], float vec_o[3]) {
  float len = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
  if (len > (1.0e-3)) {
    vec_o[0] = vec[0] / len;
    vec_o[1] = vec[1] / len;
    vec_o[2] = vec[2] / len;
    return true;
  } else {
    vec_o[0] = 0.0;
    vec_o[1] = 0.0;
    vec_o[2] = 0.0;
    return false;
  }
}


x86 assembly (clang, -O0):
<CalcNormalize2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%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>
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe81(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d8 <CalcNormalize2+0xc8>
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x8(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1202 <CalcNormalize2+0xf2>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcNormalize2>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
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     114a <CalcNormalize2+0x3a>
sqrtss %xmm0,%xmm0
jmp    114f <CalcNormalize2+0x3f>
call   1030 <sqrt@plt>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
ucomisd 0xea2(%rip),%xmm1
jbe    118c <CalcNormalize2+0x7c>
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
mov    $0x1,%eax
jmp    1198 <CalcNormalize2+0x88>
movq   $0x0,(%r14)
xor    %eax,%eax
xorps  %xmm1,%xmm1
movss  %xmm1,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @CalcNormalize2(float* nocapture %0, float* nocapture writeonly %1) {
%3 = load float, float* %0
%4 = getelementptr inbounds float, float* %0, i64 1
%5 = load float, float* %4
%6 = fmul float %5, %5
%7 = tail call float @llvm.fmuladd.f32(float %3, float %3, float %6)
%8 = getelementptr inbounds float, float* %0, i64 2
%9 = load float, float* %8
%10 = tail call float @llvm.fmuladd.f32(float %9, float %9, float %7)
%11 = tail call float @sqrt(float %10)
%12 = fpext float %11 to double
%13 = fcmp ogt double %12, 1.000000e-03
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load float, float* %0
%16 = fdiv float %15, %11
store float %16, float* %1
%17 = load float, float* %4
%18 = fdiv float %17, %11
%19 = getelementptr inbounds float, float* %1, i64 1
store float %18, float* %19
%20 = load float, float* %8
%21 = fdiv float %20, %11
br label %24
22: ; preds = %2
store float 0.000000e+00, float* %1
%23 = getelementptr inbounds float, float* %1, i64 1
store float 0.000000e+00, float* %23
br label %24
24: ; preds = %22, %14
%25 = phi float [ %21, %14 ], [ 0.000000e+00, %22 ]
%26 = phi i32 [ 1, %14 ], [ 0, %22 ]
%27 = getelementptr inbounds float, float* %1, i64 2
store float %25, float* %27
ret i32 %26
}