#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 dot_product(float *, float *);
float squared_length(float *);
void projection(float *u, float *v, float *r) {
  float costheta = dot_product(u, v) / squared_length(v);
  r[0] = v[0] * costheta;
  r[1] = v[1] * costheta;
  r[2] = v[2] * costheta;
}


x86 assembly (clang, -O0):
<projection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <dot_product@plt>
movss  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <squared_length@plt>
movaps %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mulss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movss  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<projection>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <dot_product@plt>
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
call   1040 <squared_length@plt>
movss  0x4(%rsp),%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 @projection(float* %0, float* %1, float* %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca float*
%7 = alloca float
store float* %0, float** %4
store float* %1, float** %5
store float* %2, float** %6
%8 = load float*, float** %4
%9 = load float*, float** %5
%10 = call float @dot_product(float* %8, float* %9)
%11 = load float*, float** %5
%12 = call float @squared_length(float* %11)
%13 = fdiv float %10, %12
store float %13, float* %7
%14 = load float*, float** %5
%15 = getelementptr inbounds float, float* %14, i64 0
%16 = load float, float* %15
%17 = load float, float* %7
%18 = fmul float %16, %17
%19 = load float*, float** %6
%20 = getelementptr inbounds float, float* %19, i64 0
store float %18, float* %20
%21 = load float*, float** %5
%22 = getelementptr inbounds float, float* %21, i64 1
%23 = load float, float* %22
%24 = load float, float* %7
%25 = fmul float %23, %24
%26 = load float*, float** %6
%27 = getelementptr inbounds float, float* %26, i64 1
store float %25, float* %27
%28 = load float*, float** %5
%29 = getelementptr inbounds float, float* %28, i64 2
%30 = load float, float* %29
%31 = load float, float* %7
%32 = fmul float %30, %31
%33 = load float*, float** %6
%34 = getelementptr inbounds float, float* %33, i64 2
store float %32, float* %34
ret void
}

LLVM IR (-O2):
define void @projection(float* %0, float* %1, float* nocapture writeonly %2) {
%4 = tail call float @dot_product(float* %0, float* %1)
%5 = tail call float @squared_length(float* %1)
%6 = fdiv float %4, %5
%7 = load float, float* %1
%8 = fmul float %7, %6
store float %8, float* %2
%9 = getelementptr inbounds float, float* %1, i64 1
%10 = load float, float* %9
%11 = fmul float %6, %10
%12 = getelementptr inbounds float, float* %2, i64 1
store float %11, float* %12
%13 = getelementptr inbounds float, float* %1, i64 2
%14 = load float, float* %13
%15 = fmul float %6, %14
%16 = getelementptr inbounds float, float* %2, i64 2
store float %15, float* %16
ret void
}