#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 /*<<< orphan*/ Quaternion2R(float *, float **);
float VectorMagnitude(float *);
float cosf(float);
float sinf(float);
void Rv2Rot(float Rv[3], float R[3][3]) {
  float q[4];
  float angle = VectorMagnitude(Rv);
  if (angle <= 0.00048828125f) {
    q[0] = 1.0f;
    q[1] = 0.5f * Rv[0];
    q[2] = 0.5f * Rv[1];
    q[3] = 0.5f * Rv[2];
  } else {
    q[0] = cosf(angle * 0.5f);
    float scale = sinf(angle * 0.5f) / angle;
    q[1] = scale * Rv[0];
    q[2] = scale * Rv[1];
    q[3] = scale * Rv[2];
  }
  Quaternion2R(q, R);
}


x86 assembly (clang, -O0):
<Rv2Rot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <VectorMagnitude@plt>
movss  %xmm0,-0x24(%rbp)
movss  0xe9a(%rip),%xmm0
ucomiss -0x24(%rbp),%xmm0
jb     11c3 <Rv2Rot+0x83>
movss  0xe90(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  0xe7b(%rip),%xmm0
mulss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movss  0xe66(%rip),%xmm0
mulss  0x4(%rax),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movss  0xe50(%rip),%xmm0
mulss  0x8(%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    122e <Rv2Rot+0xee>
movss  0xe39(%rip),%xmm0
mulss  -0x24(%rbp),%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x20(%rbp)
movss  0xe22(%rip),%xmm0
mulss  -0x24(%rbp),%xmm0
call   1030 <sinf@plt>
divss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  (%rax),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x8(%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <Quaternion2R@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Rv2Rot>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <VectorMagnitude@plt>
movaps %xmm0,%xmm1
movss  0xea3(%rip),%xmm0
ucomiss %xmm1,%xmm0
jae    11b1 <Rv2Rot+0x71>
movss  0xe9e(%rip),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,0x8(%rsp)
movss  %xmm1,0xc(%rsp)
call   1040 <cosf@plt>
movss  %xmm0,0x4(%rsp)
movss  0x8(%rsp),%xmm0
call   1030 <sinf@plt>
movss  0x4(%rsp),%xmm3
divss  0xc(%rsp),%xmm0
movsd  (%rbx),%xmm2
movaps %xmm0,%xmm1
shufps $0x0,%xmm0,%xmm1
mulps  %xmm2,%xmm1
movss  0x8(%rbx),%xmm2
jmp    11d1 <Rv2Rot+0x91>
movsd  (%rbx),%xmm1
mulps  0xe54(%rip),%xmm1
movss  0x8(%rbx),%xmm0
movss  0xe3b(%rip),%xmm3
movss  0xe37(%rip),%xmm2
mulss  %xmm0,%xmm2
movss  %xmm3,0x10(%rsp)
movss  %xmm1,0x14(%rsp)
shufps $0x55,%xmm1,%xmm1
movss  %xmm1,0x18(%rsp)
movss  %xmm2,0x1c(%rsp)
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1050 <Quaternion2R@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @Rv2Rot(float* %0, [3 x float]* %1) {
%3 = alloca float*
%4 = alloca [3 x float]*
%5 = alloca [4 x float]
%6 = alloca float
%7 = alloca float
store float* %0, float** %3
store [3 x float]* %1, [3 x float]** %4
%8 = load float*, float** %3
%9 = call float @VectorMagnitude(float* %8)
store float %9, float* %6
%10 = load float, float* %6
%11 = fcmp ole float %10, 0x3F40000000000000
br i1 %11, label %12, label %29
12: ; preds = %2
%13 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 0
store float 1.000000e+00, float* %13
%14 = load float*, float** %3
%15 = getelementptr inbounds float, float* %14, i64 0
%16 = load float, float* %15
%17 = fmul float 5.000000e-01, %16
%18 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 1
store float %17, float* %18
%19 = load float*, float** %3
%20 = getelementptr inbounds float, float* %19, i64 1
%21 = load float, float* %20
%22 = fmul float 5.000000e-01, %21
%23 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 2
store float %22, float* %23
%24 = load float*, float** %3
%25 = getelementptr inbounds float, float* %24, i64 2
%26 = load float, float* %25
%27 = fmul float 5.000000e-01, %26
%28 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 3
store float %27, float* %28
br label %57
29: ; preds = %2
%30 = load float, float* %6
%31 = fmul float %30, 5.000000e-01
%32 = call float @cosf(float %31)
%33 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 0
store float %32, float* %33
%34 = load float, float* %6
%35 = fmul float %34, 5.000000e-01
%36 = call float @sinf(float %35)
%37 = load float, float* %6
%38 = fdiv float %36, %37
store float %38, float* %7
%39 = load float, float* %7
%40 = load float*, float** %3
%41 = getelementptr inbounds float, float* %40, i64 0
%42 = load float, float* %41
%43 = fmul float %39, %42
%44 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 1
store float %43, float* %44
%45 = load float, float* %7
%46 = load float*, float** %3
%47 = getelementptr inbounds float, float* %46, i64 1
%48 = load float, float* %47
%49 = fmul float %45, %48
%50 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 2
store float %49, float* %50
%51 = load float, float* %7
%52 = load float*, float** %3
%53 = getelementptr inbounds float, float* %52, i64 2
%54 = load float, float* %53
%55 = fmul float %51, %54
%56 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 3
store float %55, float* %56
br label %57
57: ; preds = %29, %12
%58 = getelementptr inbounds [4 x float], [4 x float]* %5, i64 0, i64 0
%59 = load [3 x float]*, [3 x float]** %4
%60 = bitcast [3 x float]* %59 to float**
%61 = call i32 @Quaternion2R(float* %58, float** %60)
ret void
}

LLVM IR (-O2):
define void @Rv2Rot(float* %0, [3 x float]* %1) {
%3 = alloca [4 x float]
%4 = bitcast [4 x float]* %3 to i8*
%5 = tail call float @VectorMagnitude(float* %0)
%6 = fcmp ugt float %5, 0x3F40000000000000
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = bitcast float* %0 to <2 x float>*
%9 = load <2 x float>, <2 x float>* %8
%10 = fmul <2 x float> %9, <float 5.000000e-01, float 5.000000e-01>
%11 = getelementptr inbounds float, float* %0, i64 2
%12 = load float, float* %11
br label %25
13: ; preds = %2
%14 = fmul float %5, 5.000000e-01
%15 = tail call float @cosf(float %14)
%16 = tail call float @sinf(float %14)
%17 = fdiv float %16, %5
%18 = bitcast float* %0 to <2 x float>*
%19 = load <2 x float>, <2 x float>* %18
%20 = insertelement <2 x float> poison, float %17, i64 0
%21 = shufflevector <2 x float> %20, <2 x float> poison, <2 x i32> zeroinitializer
%22 = fmul <2 x float> %21, %19
%23 = getelementptr inbounds float, float* %0, i64 2
%24 = load float, float* %23
br label %25
25: ; preds = %13, %7
%26 = phi float [ %24, %13 ], [ 5.000000e-01, %7 ]
%27 = phi float [ %17, %13 ], [ %12, %7 ]
%28 = phi float [ %15, %13 ], [ 1.000000e+00, %7 ]
%29 = phi <2 x float> [ %22, %13 ], [ %10, %7 ]
%30 = fmul float %27, %26
%31 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 0
store float %28, float* %31
%32 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 1
%33 = extractelement <2 x float> %29, i64 0
store float %33, float* %32
%34 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 2
%35 = extractelement <2 x float> %29, i64 1
store float %35, float* %34
%36 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 3
store float %30, float* %36
%37 = bitcast [3 x float]* %1 to float**
%38 = call i32 @Quaternion2R(float* %31, float** %37)
ret void
}