#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 */
scalar_t__ malloc(int);
float sqrt(float);
float *RBR_vector_set_dist(float *V1, float R) {
  int i;
  float *V2;
  float r;
  V2 = (float *)malloc(3 * sizeof(float));
  r = sqrt(V1[0] * V1[0] + V1[1] * V1[1] + V1[2] * V1[2]);
  for (i = 0; i < 3; ++i)
    V2[i] = (R / r) * V1[i];
  return V2;
}


x86 assembly (clang, -O0):
<RBR_vector_set_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    $0xc,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0x1c(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    11d0 <RBR_vector_set_dist+0xb0>
movss  -0xc(%rbp),%xmm0
divss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1194 <RBR_vector_set_dist+0x74>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RBR_vector_set_dist>:
push   %r14
push   %rbx
push   %rax
movss  %xmm0,0x4(%rsp)
mov    %rdi,%rbx
mov    $0xc,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm0
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0x8(%rbx),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     116a <RBR_vector_set_dist+0x4a>
sqrtss %xmm0,%xmm0
jmp    116f <RBR_vector_set_dist+0x4f>
call   1040 <sqrt@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)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define float* @RBR_vector_set_dist(float* %0, float %1) {
%3 = alloca float*
%4 = alloca float
%5 = alloca i32
%6 = alloca float*
%7 = alloca float
store float* %0, float** %3
store float %1, float* %4
%8 = call i64 @malloc(i32 12)
%9 = inttoptr i64 %8 to float*
store float* %9, float** %6
%10 = load float*, float** %3
%11 = getelementptr inbounds float, float* %10, i64 0
%12 = load float, float* %11
%13 = load float*, float** %3
%14 = getelementptr inbounds float, float* %13, i64 0
%15 = load float, float* %14
%16 = load float*, float** %3
%17 = getelementptr inbounds float, float* %16, i64 1
%18 = load float, float* %17
%19 = load float*, float** %3
%20 = getelementptr inbounds float, float* %19, i64 1
%21 = load float, float* %20
%22 = fmul float %18, %21
%23 = call float @llvm.fmuladd.f32(float %12, float %15, float %22)
%24 = load float*, float** %3
%25 = getelementptr inbounds float, float* %24, i64 2
%26 = load float, float* %25
%27 = load float*, float** %3
%28 = getelementptr inbounds float, float* %27, i64 2
%29 = load float, float* %28
%30 = call float @llvm.fmuladd.f32(float %26, float %29, float %23)
%31 = call float @sqrt(float %30)
store float %31, float* %7
store i32 0, i32* %5
br label %32
32: ; preds = %49, %2
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 3
br i1 %34, label %35, label %52
35: ; preds = %32
%36 = load float, float* %4
%37 = load float, float* %7
%38 = fdiv float %36, %37
%39 = load float*, float** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds float, float* %39, i64 %41
%43 = load float, float* %42
%44 = fmul float %38, %43
%45 = load float*, float** %6
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float, float* %45, i64 %47
store float %44, float* %48
br label %49
49: ; preds = %35
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %32
52: ; preds = %32
%53 = load float*, float** %6
ret float* %53
}

LLVM IR (-O2):
define float* @RBR_vector_set_dist(float* nocapture %0, float %1) {
%3 = tail call i64 @malloc(i32 12)
%4 = inttoptr i64 %3 to float*
%5 = load float, float* %0
%6 = getelementptr inbounds float, float* %0, i64 1
%7 = load float, float* %6
%8 = fmul float %7, %7
%9 = tail call float @llvm.fmuladd.f32(float %5, float %5, float %8)
%10 = getelementptr inbounds float, float* %0, i64 2
%11 = load float, float* %10
%12 = tail call float @llvm.fmuladd.f32(float %11, float %11, float %9)
%13 = tail call float @sqrt(float %12)
%14 = fdiv float %1, %13
%15 = load float, float* %0
%16 = fmul float %14, %15
store float %16, float* %4
%17 = load float, float* %6
%18 = fmul float %14, %17
%19 = getelementptr inbounds float, float* %4, i64 1
store float %18, float* %19
%20 = load float, float* %10
%21 = fmul float %14, %20
%22 = getelementptr inbounds float, float* %4, i64 2
store float %21, float* %22
ret float* %4
}