#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 */
int sqrt(float const);
void normalizev(float *r, const float *v) {
  const double l = 1 / sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  r[0] = (float)(v[0] * l);
  r[1] = (float)(v[1] * l);
  r[2] = (float)(v[2] * l);
}


x86 assembly (clang, -O0):
<normalizev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-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>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x18(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x18(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x18(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalizev>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movss  (%rsi),%xmm1
movss  0x4(%rsi),%xmm0
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0x8(%rsi),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1030 <sqrt@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movss  (%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x4(%r14)
movss  0x8(%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @normalizev(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca double
store float* %0, float** %3
store float* %1, float** %4
%6 = load float*, float** %4
%7 = getelementptr inbounds float, float* %6, i64 0
%8 = load float, float* %7
%9 = load float*, float** %4
%10 = getelementptr inbounds float, float* %9, i64 0
%11 = load float, float* %10
%12 = load float*, float** %4
%13 = getelementptr inbounds float, float* %12, i64 1
%14 = load float, float* %13
%15 = load float*, float** %4
%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** %4
%21 = getelementptr inbounds float, float* %20, i64 2
%22 = load float, float* %21
%23 = load float*, float** %4
%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 i32 @sqrt(float %26)
%28 = sdiv i32 1, %27
%29 = sitofp i32 %28 to double
store double %29, double* %5
%30 = load float*, float** %4
%31 = getelementptr inbounds float, float* %30, i64 0
%32 = load float, float* %31
%33 = fpext float %32 to double
%34 = load double, double* %5
%35 = fmul double %33, %34
%36 = fptrunc double %35 to float
%37 = load float*, float** %3
%38 = getelementptr inbounds float, float* %37, i64 0
store float %36, float* %38
%39 = load float*, float** %4
%40 = getelementptr inbounds float, float* %39, i64 1
%41 = load float, float* %40
%42 = fpext float %41 to double
%43 = load double, double* %5
%44 = fmul double %42, %43
%45 = fptrunc double %44 to float
%46 = load float*, float** %3
%47 = getelementptr inbounds float, float* %46, i64 1
store float %45, float* %47
%48 = load float*, float** %4
%49 = getelementptr inbounds float, float* %48, i64 2
%50 = load float, float* %49
%51 = fpext float %50 to double
%52 = load double, double* %5
%53 = fmul double %51, %52
%54 = fptrunc double %53 to float
%55 = load float*, float** %3
%56 = getelementptr inbounds float, float* %55, i64 2
store float %54, float* %56
ret void
}

LLVM IR (-O2):
define void @normalizev(float* nocapture writeonly %0, float* nocapture %1) {
%3 = load float, float* %1
%4 = getelementptr inbounds float, float* %1, 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* %1, i64 2
%9 = load float, float* %8
%10 = tail call float @llvm.fmuladd.f32(float %9, float %9, float %7)
%11 = tail call i32 @sqrt(float %10)
%12 = add i32 %11, 1
%13 = icmp ult i32 %12, 3
%14 = select i1 %13, i32 %11, i32 0
%15 = sitofp i32 %14 to double
%16 = load float, float* %1
%17 = fpext float %16 to double
%18 = fmul double %17, %15
%19 = fptrunc double %18 to float
store float %19, float* %0
%20 = load float, float* %4
%21 = fpext float %20 to double
%22 = fmul double %21, %15
%23 = fptrunc double %22 to float
%24 = getelementptr inbounds float, float* %0, i64 1
store float %23, float* %24
%25 = load float, float* %8
%26 = fpext float %25 to double
%27 = fmul double %15, %26
%28 = fptrunc double %27 to float
%29 = getelementptr inbounds float, float* %0, i64 2
store float %28, float* %29
ret void
}