#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 finn_vec3_mag(float *);
void finn_vec3_normalize(float *result, float *vec) {
  float mag = finn_vec3_mag(vec);
  float inv = 1.0f / mag;
  result[0] = vec[0] * inv;
  result[1] = vec[1] * inv;
  result[2] = vec[2] * inv;
}


x86 assembly (clang, -O0):
<finn_vec3_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <finn_vec3_mag@plt>
movss  %xmm0,-0x14(%rbp)
movss  0xeca(%rip),%xmm0
divss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mulss  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finn_vec3_normalize>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <finn_vec3_mag@plt>
movss  0xed6(%rip),%xmm1
divss  %xmm0,%xmm1
movss  (%rbx),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,(%r14)
movss  0x4(%rbx),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,0x4(%r14)
mulss  0x8(%rbx),%xmm1
movss  %xmm1,0x8(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @finn_vec3_normalize(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca float
%6 = alloca float
store float* %0, float** %3
store float* %1, float** %4
%7 = load float*, float** %4
%8 = call float @finn_vec3_mag(float* %7)
store float %8, float* %5
%9 = load float, float* %5
%10 = fdiv float 1.000000e+00, %9
store float %10, float* %6
%11 = load float*, float** %4
%12 = getelementptr inbounds float, float* %11, i64 0
%13 = load float, float* %12
%14 = load float, float* %6
%15 = fmul float %13, %14
%16 = load float*, float** %3
%17 = getelementptr inbounds float, float* %16, i64 0
store float %15, float* %17
%18 = load float*, float** %4
%19 = getelementptr inbounds float, float* %18, i64 1
%20 = load float, float* %19
%21 = load float, float* %6
%22 = fmul float %20, %21
%23 = load float*, float** %3
%24 = getelementptr inbounds float, float* %23, i64 1
store float %22, float* %24
%25 = load float*, float** %4
%26 = getelementptr inbounds float, float* %25, i64 2
%27 = load float, float* %26
%28 = load float, float* %6
%29 = fmul float %27, %28
%30 = load float*, float** %3
%31 = getelementptr inbounds float, float* %30, i64 2
store float %29, float* %31
ret void
}

LLVM IR (-O2):
define void @finn_vec3_normalize(float* nocapture writeonly %0, float* %1) {
%3 = tail call float @finn_vec3_mag(float* %1)
%4 = fdiv float 1.000000e+00, %3
%5 = load float, float* %1
%6 = fmul float %5, %4
store float %6, float* %0
%7 = getelementptr inbounds float, float* %1, i64 1
%8 = load float, float* %7
%9 = fmul float %4, %8
%10 = getelementptr inbounds float, float* %0, i64 1
store float %9, float* %10
%11 = getelementptr inbounds float, float* %1, i64 2
%12 = load float, float* %11
%13 = fmul float %4, %12
%14 = getelementptr inbounds float, float* %0, i64 2
store float %13, float* %14
ret void
}