#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 vec_norm(float vin[3], float vout[3]) {
  float len;
  len = sqrt(vin[0] * vin[0] + vin[1] * vin[1] + vin[2] * vin[2]);
  if (len != 0.0) {
    vout[0] = vin[0] / len;
    vout[1] = vin[1] / len;
    vout[2] = vin[2] / len;
  } else {
    vout[0] = vout[1] = 0.0;
    vout[2] = 1.0;
  }
}


x86 assembly (clang, -O0):
<vec_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%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,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118f <vec_norm+0x7f>
jp     118f <vec_norm+0x7f>
jmp    11d7 <vec_norm+0xc7>
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  -0x14(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x8(%rax)
jmp    11ff <vec_norm+0xef>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0xe06(%rip),%xmm0
movss  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_norm>:
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 <vec_norm+0x3a>
sqrtss %xmm0,%xmm0
jmp    1152 <vec_norm+0x42>
call   1030 <sqrt@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1159 <vec_norm+0x49>
jnp    1180 <vec_norm+0x70>
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
jmp    118f <vec_norm+0x7f>
movq   $0x0,(%r14)
movss  0xe71(%rip),%xmm1
movss  %xmm1,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @vec_norm(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 = fcmp une float %11, 0.000000e+00
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load float, float* %0
%15 = fdiv float %14, %11
store float %15, float* %1
%16 = load float, float* %4
%17 = fdiv float %16, %11
%18 = getelementptr inbounds float, float* %1, i64 1
store float %17, float* %18
%19 = load float, float* %8
%20 = fdiv float %19, %11
br label %23
21: ; preds = %2
%22 = getelementptr inbounds float, float* %1, i64 1
store float 0.000000e+00, float* %22
store float 0.000000e+00, float* %1
br label %23
23: ; preds = %21, %13
%24 = phi float [ %20, %13 ], [ 1.000000e+00, %21 ]
%25 = getelementptr inbounds float, float* %1, i64 2
store float %24, float* %25
ret void
}