#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 sqrtf(float const);
void normalize3d(float *out, const float *in) {
  float r = 1. / sqrtf(in[0] * in[0] + in[1] * in[1] + in[2] * in[2]);
  out[0] = in[0] * r;
  out[1] = in[1] * r;
  out[2] = in[2] * r;
}


x86 assembly (clang, -O0):
<normalize3d>:
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 <sqrtf@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe8b(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%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)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize3d>:
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 <sqrtf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xeb0(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  (%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%r14)
movss  0x4(%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%r14)
mulss  0x8(%rbx),%xmm0
movss  %xmm0,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @normalize3d(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 = 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 @sqrtf(float %26)
%28 = sitofp i32 %27 to double
%29 = fdiv double 1.000000e+00, %28
%30 = fptrunc double %29 to float
store float %30, float* %5
%31 = load float*, float** %4
%32 = getelementptr inbounds float, float* %31, i64 0
%33 = load float, float* %32
%34 = load float, float* %5
%35 = fmul float %33, %34
%36 = load float*, float** %3
%37 = getelementptr inbounds float, float* %36, i64 0
store float %35, float* %37
%38 = load float*, float** %4
%39 = getelementptr inbounds float, float* %38, i64 1
%40 = load float, float* %39
%41 = load float, float* %5
%42 = fmul float %40, %41
%43 = load float*, float** %3
%44 = getelementptr inbounds float, float* %43, i64 1
store float %42, float* %44
%45 = load float*, float** %4
%46 = getelementptr inbounds float, float* %45, i64 2
%47 = load float, float* %46
%48 = load float, float* %5
%49 = fmul float %47, %48
%50 = load float*, float** %3
%51 = getelementptr inbounds float, float* %50, i64 2
store float %49, float* %51
ret void
}

LLVM IR (-O2):
define void @normalize3d(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 @sqrtf(float %10)
%12 = sitofp i32 %11 to double
%13 = fdiv double 1.000000e+00, %12
%14 = fptrunc double %13 to float
%15 = load float, float* %1
%16 = fmul float %15, %14
store float %16, float* %0
%17 = load float, float* %4
%18 = fmul float %17, %14
%19 = getelementptr inbounds float, float* %0, i64 1
store float %18, float* %19
%20 = load float, float* %8
%21 = fmul float %20, %14
%22 = getelementptr inbounds float, float* %0, i64 2
store float %21, float* %22
ret void
}