#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 *malloc(int);
double norm(float *, int);
float *unit_vector_3d(float n1, float n2, float n3) {
  int i;
  int ndim = 3;
  float s;
  float *out;
  out = malloc(sizeof(float) * ndim);
  out[0] = n1;
  out[1] = n2;
  out[2] = n3;
  s = 1.0 / norm(out, ndim);
  for (i = 0; i < ndim; i++) {
    out[i] *= s;
  }
  return out;
}


x86 assembly (clang, -O0):
<unit_vector_3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movl   $0x3,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x8(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0xc(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movss  %xmm0,0x8(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <norm@plt>
movaps %xmm0,%xmm1
movsd  0xe6f(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d6 <unit_vector_3d+0xb6>
movss  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a5 <unit_vector_3d+0x85>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unit_vector_3d>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm2,0xc(%rsp)
movss  %xmm1,0x8(%rsp)
movss  %xmm0,0x4(%rsp)
mov    $0xc,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movss  0x4(%rsp),%xmm0
movss  %xmm0,(%rax)
movss  0x8(%rsp),%xmm0
movss  %xmm0,0x4(%rax)
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rax)
mov    %rax,%rdi
mov    $0x3,%esi
call   1030 <norm@plt>
movsd  0xe87(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  (%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
movss  0x4(%rbx),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%rbx)
mulss  0x8(%rbx),%xmm0
movss  %xmm0,0x8(%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define float* @unit_vector_3d(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca float*
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
store i32 3, i32* %8
%11 = load i32, i32* %8
%12 = sext i32 %11 to i64
%13 = mul i64 4, %12
%14 = trunc i64 %13 to i32
%15 = call float* @malloc(i32 %14)
store float* %15, float** %10
%16 = load float, float* %4
%17 = load float*, float** %10
%18 = getelementptr inbounds float, float* %17, i64 0
store float %16, float* %18
%19 = load float, float* %5
%20 = load float*, float** %10
%21 = getelementptr inbounds float, float* %20, i64 1
store float %19, float* %21
%22 = load float, float* %6
%23 = load float*, float** %10
%24 = getelementptr inbounds float, float* %23, i64 2
store float %22, float* %24
%25 = load float*, float** %10
%26 = load i32, i32* %8
%27 = call double @norm(float* %25, i32 %26)
%28 = fdiv double 1.000000e+00, %27
%29 = fptrunc double %28 to float
store float %29, float* %9
store i32 0, i32* %7
br label %30
30: ; preds = %42, %3
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load float, float* %9
%36 = load float*, float** %10
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds float, float* %36, i64 %38
%40 = load float, float* %39
%41 = fmul float %40, %35
store float %41, float* %39
br label %42
42: ; preds = %34
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %30
45: ; preds = %30
%46 = load float*, float** %10
ret float* %46
}

LLVM IR (-O2):
define float* @unit_vector_3d(float %0, float %1, float %2) {
%4 = tail call float* @malloc(i32 12)
store float %0, float* %4
%5 = getelementptr inbounds float, float* %4, i64 1
store float %1, float* %5
%6 = getelementptr inbounds float, float* %4, i64 2
store float %2, float* %6
%7 = tail call double @norm(float* %4, i32 3)
%8 = fdiv double 1.000000e+00, %7
%9 = fptrunc double %8 to float
%10 = load float, float* %4
%11 = fmul float %10, %9
store float %11, float* %4
%12 = load float, float* %5
%13 = fmul float %12, %9
store float %13, float* %5
%14 = load float, float* %6
%15 = fmul float %14, %9
store float %15, float* %6
ret float* %4
}