#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 */
double M_PI;
float cosf(float);
float sinf(float);
void quat_fromEuler(float *dst, float x, float y, float z) {
  float halfToRad = 0.5 * M_PI / 180.0;
  x *= halfToRad;
  y *= halfToRad;
  z *= halfToRad;
  float sx = sinf(x);
  float cx = cosf(x);
  float sy = sinf(y);
  float cy = cosf(y);
  float sz = sinf(z);
  float cz = cosf(z);
  dst[0] = sx * cy * cz - cx * sy * sz;
  dst[1] = cx * sy * cz + sx * cy * sz;
  dst[2] = cx * cy * sz - sx * sy * cz;
  dst[3] = cx * cy * cz + sx * sy * sz;
}


x86 assembly (clang, -O0):
<quat_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)
movsd  0xec5(%rip),%xmm0
mov    0x2e9e(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xeaa(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x10(%rbp),%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <sinf@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x14(%rbp),%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x1c(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  -0x30(%rbp),%xmm2
movss  -0x20(%rbp),%xmm1
mulss  -0x24(%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  -0x20(%rbp),%xmm0
mulss  -0x24(%rbp),%xmm0
movss  -0x30(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  -0x28(%rbp),%xmm1
mulss  -0x2c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x20(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  -0x24(%rbp),%xmm1
mulss  -0x30(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x20(%rbp),%xmm0
mulss  -0x28(%rbp),%xmm0
movss  -0x30(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
mulss  -0x24(%rbp),%xmm1
mulss  -0x2c(%rbp),%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):
<quat_fromEuler>:
push   %rbx
sub    $0x60,%rsp
mov    0x2ebc(%rip),%rax
movsd  (%rax),%xmm3
mulsd  0xec8(%rip),%xmm3
divsd  0xec8(%rip),%xmm3
cvtsd2ss %xmm3,%xmm3
mov    %rdi,%rbx
mulss  %xmm3,%xmm0
movss  %xmm0,0x20(%rsp)
mulss  %xmm3,%xmm1
movss  %xmm1,0x10(%rsp)
mulss  %xmm2,%xmm3
movss  %xmm3,0xc(%rsp)
call   1030 <sinf@plt>
movaps %xmm0,0x50(%rsp)
movss  0x20(%rsp),%xmm0
call   1040 <cosf@plt>
movaps %xmm0,0x20(%rsp)
movss  0x10(%rsp),%xmm0
call   1030 <sinf@plt>
movaps %xmm0,0x40(%rsp)
movss  0x10(%rsp),%xmm0
call   1040 <cosf@plt>
movaps %xmm0,0x30(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <sinf@plt>
movaps %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <cosf@plt>
movaps 0x50(%rsp),%xmm2
movaps %xmm2,%xmm1
movaps 0x30(%rsp),%xmm5
mulss  %xmm5,%xmm1
movaps 0x20(%rsp),%xmm3
shufps $0x0,%xmm3,%xmm3
movaps 0x40(%rsp),%xmm4
mulss  %xmm4,%xmm2
movaps %xmm2,%xmm7
unpcklps %xmm5,%xmm4
mulps  %xmm3,%xmm4
movaps 0xe23(%rip),%xmm2
movaps %xmm4,%xmm3
movaps %xmm4,%xmm8
xorps  %xmm2,%xmm3
xorps  %xmm7,%xmm2
movaps 0x10(%rsp),%xmm6
movaps %xmm6,%xmm4
unpcklps %xmm1,%xmm4
movaps %xmm0,%xmm5
unpcklps %xmm7,%xmm5
movlhps %xmm5,%xmm4
unpcklps %xmm6,%xmm2
unpcklps %xmm6,%xmm3
movlhps %xmm2,%xmm3
mulps  %xmm4,%xmm3
movlhps %xmm8,%xmm1
shufps $0x58,%xmm8,%xmm1
unpcklps %xmm6,%xmm0
shufps $0x10,%xmm0,%xmm0
mulps  %xmm1,%xmm0
addps  %xmm3,%xmm0
movups %xmm0,(%rbx)
add    $0x60,%rsp
pop    %rbx
ret

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

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