#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 cosf(float);
float sinf(float);
void quaternion_fromEuler(float out[4], float pitch, float yaw, float roll) {
  float cp, cy, cr;
  float sp, sy, sr;
  cp = cosf(pitch / 2.0f);
  cy = cosf(roll / 2.0f);
  cr = cosf(yaw / 2.0f);
  sp = sinf(pitch / 2.0f);
  sy = sinf(-roll / 2.0f);
  sr = sinf(yaw / 2.0f);
  out[0] = sp * cy * cr - cp * sy * sr;
  out[1] = -cp * sy * cr - sp * cy * sr;
  out[2] = cp * cy * sr + sp * sy * cr;
  out[3] = cp * cy * cr - sp * sy * sr;
}


x86 assembly (clang, -O0):
<quaternion_fromEuler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xeb8(%rip),%xmm1
divss  %xmm1,%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe9d(%rip),%xmm1
divss  %xmm1,%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
movss  0xe82(%rip),%xmm1
divss  %xmm1,%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe67(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  0xe3f(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x10(%rbp),%xmm0
movss  0xe24(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x24(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  -0x28(%rbp),%xmm1
mulss  -0x2c(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x18(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  -0x28(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  -0x1c(%rbp),%xmm1
mulss  -0x2c(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x18(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  -0x28(%rbp),%xmm1
mulss  -0x20(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x18(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
movss  -0x24(%rbp),%xmm1
mulss  -0x28(%rbp),%xmm1
mulss  -0x2c(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quaternion_fromEuler>:
push   %rbx
sub    $0x60,%rsp
movss  %xmm2,0x10(%rsp)
movss  %xmm1,0xc(%rsp)
mov    %rdi,%rbx
mulss  0xec4(%rip),%xmm0
movss  %xmm0,0x20(%rsp)
call   1040 <cosf@plt>
movaps %xmm0,0x50(%rsp)
movss  0x10(%rsp),%xmm0
mulss  0xea6(%rip),%xmm0
call   1040 <cosf@plt>
movaps %xmm0,0x30(%rsp)
movss  0xc(%rsp),%xmm0
mulss  0xe8e(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
call   1040 <cosf@plt>
movaps %xmm0,0x40(%rsp)
movss  0x20(%rsp),%xmm0
call   1030 <sinf@plt>
movaps %xmm0,0x20(%rsp)
movss  0x10(%rsp),%xmm0
mulss  0xe64(%rip),%xmm0
call   1030 <sinf@plt>
movaps %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <sinf@plt>
movaps 0x30(%rsp),%xmm8
movaps %xmm8,%xmm1
movaps 0x20(%rsp),%xmm4
mulss  %xmm4,%xmm1
movaps 0xe41(%rip),%xmm2
movaps %xmm1,%xmm3
xorps  %xmm2,%xmm3
movaps 0x10(%rsp),%xmm6
mulss  %xmm6,%xmm4
movaps %xmm4,%xmm7
movaps 0x50(%rsp),%xmm5
unpcklps %xmm5,%xmm6
xorps  %xmm2,%xmm5
unpcklps %xmm8,%xmm5
mulps  %xmm6,%xmm5
xorps  %xmm4,%xmm2
movaps %xmm5,%xmm4
unpcklps %xmm0,%xmm4
movaps 0x40(%rsp),%xmm6
unpcklps %xmm0,%xmm6
movlhps %xmm6,%xmm4
unpcklps %xmm2,%xmm7
unpcklps %xmm3,%xmm0
movlhps %xmm7,%xmm0
mulps  %xmm4,%xmm0
movlhps %xmm5,%xmm1
shufps $0x58,%xmm5,%xmm1
movaps %xmm6,%xmm2
shufps $0x10,%xmm6,%xmm2
mulps  %xmm1,%xmm2
addps  %xmm0,%xmm2
movups %xmm2,(%rbx)
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @quaternion_fromEuler(float* %0, float %1, float %2, float %3) {
%5 = alloca float*
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
store float* %0, float** %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%15 = load float, float* %6
%16 = fdiv float %15, 2.000000e+00
%17 = call float @cosf(float %16)
store float %17, float* %9
%18 = load float, float* %8
%19 = fdiv float %18, 2.000000e+00
%20 = call float @cosf(float %19)
store float %20, float* %10
%21 = load float, float* %7
%22 = fdiv float %21, 2.000000e+00
%23 = call float @cosf(float %22)
store float %23, float* %11
%24 = load float, float* %6
%25 = fdiv float %24, 2.000000e+00
%26 = call float @sinf(float %25)
store float %26, float* %12
%27 = load float, float* %8
%28 = fneg float %27
%29 = fdiv float %28, 2.000000e+00
%30 = call float @sinf(float %29)
store float %30, float* %13
%31 = load float, float* %7
%32 = fdiv float %31, 2.000000e+00
%33 = call float @sinf(float %32)
store float %33, float* %14
%34 = load float, float* %12
%35 = load float, float* %10
%36 = fmul float %34, %35
%37 = load float, float* %11
%38 = load float, float* %9
%39 = load float, float* %13
%40 = fmul float %38, %39
%41 = load float, float* %14
%42 = fmul float %40, %41
%43 = fneg float %42
%44 = call float @llvm.fmuladd.f32(float %36, float %37, float %43)
%45 = load float*, float** %5
%46 = getelementptr inbounds float, float* %45, i64 0
store float %44, float* %46
%47 = load float, float* %9
%48 = fneg float %47
%49 = load float, float* %13
%50 = fmul float %48, %49
%51 = load float, float* %11
%52 = load float, float* %12
%53 = load float, float* %10
%54 = fmul float %52, %53
%55 = load float, float* %14
%56 = fmul float %54, %55
%57 = fneg float %56
%58 = call float @llvm.fmuladd.f32(float %50, float %51, float %57)
%59 = load float*, float** %5
%60 = getelementptr inbounds float, float* %59, i64 1
store float %58, float* %60
%61 = load float, float* %9
%62 = load float, float* %10
%63 = fmul float %61, %62
%64 = load float, float* %14
%65 = load float, float* %12
%66 = load float, float* %13
%67 = fmul float %65, %66
%68 = load float, float* %11
%69 = fmul float %67, %68
%70 = call float @llvm.fmuladd.f32(float %63, float %64, float %69)
%71 = load float*, float** %5
%72 = getelementptr inbounds float, float* %71, i64 2
store float %70, float* %72
%73 = load float, float* %9
%74 = load float, float* %10
%75 = fmul float %73, %74
%76 = load float, float* %11
%77 = load float, float* %12
%78 = load float, float* %13
%79 = fmul float %77, %78
%80 = load float, float* %14
%81 = fmul float %79, %80
%82 = fneg float %81
%83 = call float @llvm.fmuladd.f32(float %75, float %76, float %82)
%84 = load float*, float** %5
%85 = getelementptr inbounds float, float* %84, i64 3
store float %83, float* %85
ret void
}

LLVM IR (-O2):
define void @quaternion_fromEuler(float* nocapture writeonly %0, float %1, float %2, float %3) {
%5 = fmul float %1, 5.000000e-01
%6 = tail call float @cosf(float %5)
%7 = fmul float %3, 5.000000e-01
%8 = tail call float @cosf(float %7)
%9 = fmul float %2, 5.000000e-01
%10 = tail call float @cosf(float %9)
%11 = tail call float @sinf(float %5)
%12 = fmul float %3, -5.000000e-01
%13 = tail call float @sinf(float %12)
%14 = tail call float @sinf(float %9)
%15 = fmul float %8, %11
%16 = fneg float %6
%17 = fneg float %15
%18 = insertelement <2 x float> poison, float %13, i64 0
%19 = insertelement <2 x float> %18, float %6, i64 1
%20 = insertelement <2 x float> poison, float %16, i64 0
%21 = insertelement <2 x float> %20, float %8, i64 1
%22 = fmul <2 x float> %19, %21
%23 = shufflevector <2 x float> %22, <2 x float> poison, <4 x i32> <i32 undef, i32 1, i32 undef, i32 undef>
%24 = fmul float %11, %13
%25 = fneg float %24
%26 = extractelement <2 x float> %22, i64 0
%27 = insertelement <4 x float> poison, float %26, i64 0
%28 = insertelement <4 x float> %27, float %14, i64 1
%29 = insertelement <4 x float> %28, float %10, i64 2
%30 = insertelement <4 x float> %29, float %14, i64 3
%31 = insertelement <4 x float> poison, float %14, i64 0
%32 = insertelement <4 x float> %31, float %17, i64 1
%33 = insertelement <4 x float> %32, float %24, i64 2
%34 = insertelement <4 x float> %33, float %25, i64 3
%35 = fmul <4 x float> %30, %34
%36 = insertelement <4 x float> poison, float %15, i64 0
%37 = shufflevector <2 x float> %22, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
%38 = shufflevector <4 x float> %36, <4 x float> %37, <4 x i32> <i32 0, i32 4, i32 5, i32 undef>
%39 = shufflevector <4 x float> %38, <4 x float> %23, <4 x i32> <i32 0, i32 1, i32 2, i32 5>
%40 = insertelement <4 x float> poison, float %10, i64 0
%41 = insertelement <4 x float> %40, float %14, i64 1
%42 = shufflevector <4 x float> %41, <4 x float> poison, <4 x i32> <i32 0, i32 0, i32 1, i32 0>
%43 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %39, <4 x float> %42, <4 x float> %35)
%44 = bitcast float* %0 to <4 x float>*
store <4 x float> %43, <4 x float>* %44
ret void
}