#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*/ quat(float *, float, float, float, scalar_t__);
int /*<<< orphan*/ quat_normalize(float *, float *);
scalar_t__ sqrtf(float);
int /*<<< orphan*/ vec3_cross(float *, float *, float *);
float vec3_dot(float *, float *);
float vec3_length_squared(float *);
float *quat_from_vec3(float *result, float *a, float *b) {
  float cross[3];
  float dot = vec3_dot(a, b);
  float a_length_sq = vec3_length_squared(a);
  float b_length_sq = vec3_length_squared(a);
  vec3_cross(cross, a, b);
  quat(result, cross[0], cross[1], cross[1],
       dot + sqrtf(a_length_sq * b_length_sq));
  quat_normalize(result, result);
  return result;
}


x86 assembly (clang, -O0):
<quat_from_vec3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <vec3_dot@plt>
movss  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <vec3_length_squared@plt>
movss  %xmm0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <vec3_length_squared@plt>
movss  %xmm0,-0x30(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <vec3_cross@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x2c(%rbp),%xmm0
mulss  -0x30(%rbp),%xmm0
call   1080 <sqrtf@plt>
movss  -0x4c(%rbp),%xmm3
mov    -0x48(%rbp),%rdi
movss  -0x3c(%rbp),%xmm0
movss  -0x38(%rbp),%xmm1
movss  -0x34(%rbp),%xmm2
cvtsi2ss %rax,%xmm4
addss  %xmm4,%xmm3
cvttss2si %xmm3,%rsi
call   1060 <quat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <quat_normalize@plt>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat_from_vec3>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1070 <vec3_dot@plt>
movss  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1040 <vec3_length_squared@plt>
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
call   1040 <vec3_length_squared@plt>
movss  %xmm0,(%rsp)
lea    0x14(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <vec3_cross@plt>
movss  0x14(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x18(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
movss  (%rsp),%xmm0
mulss  0xc(%rsp),%xmm0
call   1080 <sqrtf@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  0x10(%rsp),%xmm0
cvttss2si %xmm0,%rsi
mov    %r15,%rdi
movss  0x8(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
movaps %xmm1,%xmm2
call   1060 <quat@plt>
mov    %r15,%rdi
mov    %r15,%rsi
call   1030 <quat_normalize@plt>
mov    %r15,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define float* @quat_from_vec3(float* %0, float* %1, float* %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca float*
%7 = alloca [3 x float]
%8 = alloca float
%9 = alloca float
%10 = alloca float
store float* %0, float** %4
store float* %1, float** %5
store float* %2, float** %6
%11 = load float*, float** %5
%12 = load float*, float** %6
%13 = call float @vec3_dot(float* %11, float* %12)
store float %13, float* %8
%14 = load float*, float** %5
%15 = call float @vec3_length_squared(float* %14)
store float %15, float* %9
%16 = load float*, float** %5
%17 = call float @vec3_length_squared(float* %16)
store float %17, float* %10
%18 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%19 = load float*, float** %5
%20 = load float*, float** %6
%21 = call i32 @vec3_cross(float* %18, float* %19, float* %20)
%22 = load float*, float** %4
%23 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 0
%24 = load float, float* %23
%25 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 1
%26 = load float, float* %25
%27 = getelementptr inbounds [3 x float], [3 x float]* %7, i64 0, i64 1
%28 = load float, float* %27
%29 = load float, float* %8
%30 = load float, float* %9
%31 = load float, float* %10
%32 = fmul float %30, %31
%33 = call i64 @sqrtf(float %32)
%34 = sitofp i64 %33 to float
%35 = fadd float %29, %34
%36 = fptosi float %35 to i64
%37 = call i32 @quat(float* %22, float %24, float %26, float %28, i64 %36)
%38 = load float*, float** %4
%39 = load float*, float** %4
%40 = call i32 @quat_normalize(float* %38, float* %39)
%41 = load float*, float** %4
ret float* %41
}

LLVM IR (-O2):
define float* @quat_from_vec3(float* returned %0, float* %1, float* %2) {
%4 = alloca [3 x float]
%5 = bitcast [3 x float]* %4 to i8*
%6 = tail call float @vec3_dot(float* %1, float* %2)
%7 = tail call float @vec3_length_squared(float* %1)
%8 = tail call float @vec3_length_squared(float* %1)
%9 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 0
%10 = call i32 @vec3_cross(float* %9, float* %1, float* %2)
%11 = load float, float* %9
%12 = getelementptr inbounds [3 x float], [3 x float]* %4, i64 0, i64 1
%13 = load float, float* %12
%14 = fmul float %7, %8
%15 = call i64 @sqrtf(float %14)
%16 = sitofp i64 %15 to float
%17 = fadd float %6, %16
%18 = fptosi float %17 to i64
%19 = call i32 @quat(float* %0, float %11, float %13, float %13, i64 %18)
%20 = call i32 @quat_normalize(float* %0, float* %0)
ret float* %0
}