#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 cos(float const);
float sin(float const);
void quat_of_eulers(double *quat, double phi, double theta, double psi) {
  const float phi2 = phi / 2.0;
  const float theta2 = theta / 2.0;
  const float psi2 = psi / 2.0;
  const float sinphi2 = sin(phi2);
  const float cosphi2 = cos(phi2);
  const float sintheta2 = sin(theta2);
  const float costheta2 = cos(theta2);
  const float sinpsi2 = sin(psi2);
  const float cospsi2 = cos(psi2);
  quat[0] = cosphi2 * costheta2 * cospsi2 + sinphi2 * sintheta2 * sinpsi2;
  quat[1] = -cosphi2 * sintheta2 * sinpsi2 + sinphi2 * costheta2 * cospsi2;
  quat[2] = cosphi2 * sintheta2 * cospsi2 + sinphi2 * costheta2 * sinpsi2;
  quat[3] = cosphi2 * costheta2 * sinpsi2 - sinphi2 * sintheta2 * cospsi2;
}


x86 assembly (clang, -O0):
<quat_of_eulers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xeb8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe9e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe84(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x24(%rbp),%xmm0
call   1040 <cos@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x28(%rbp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x28(%rbp),%xmm0
call   1040 <cos@plt>
movss  %xmm0,-0x3c(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,-0x40(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1040 <cos@plt>
movss  %xmm0,-0x44(%rbp)
movss  -0x34(%rbp),%xmm0
mulss  -0x3c(%rbp),%xmm0
movss  -0x44(%rbp),%xmm2
movss  -0x30(%rbp),%xmm1
mulss  -0x38(%rbp),%xmm1
mulss  -0x40(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movss  -0x34(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  -0x38(%rbp),%xmm0
movss  -0x40(%rbp),%xmm2
movss  -0x30(%rbp),%xmm1
mulss  -0x3c(%rbp),%xmm1
mulss  -0x44(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movss  -0x34(%rbp),%xmm0
mulss  -0x38(%rbp),%xmm0
movss  -0x44(%rbp),%xmm2
movss  -0x30(%rbp),%xmm1
mulss  -0x3c(%rbp),%xmm1
mulss  -0x40(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movss  -0x34(%rbp),%xmm0
mulss  -0x3c(%rbp),%xmm0
movss  -0x40(%rbp),%xmm2
movss  -0x30(%rbp),%xmm1
mulss  -0x38(%rbp),%xmm1
mulss  -0x44(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat_of_eulers>:
push   %rbx
sub    $0x60,%rsp
movsd  0xed3(%rip),%xmm3
mulsd  %xmm3,%xmm0
cvtsd2ss %xmm0,%xmm4
movss  %xmm4,0x20(%rsp)
mulsd  %xmm3,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x10(%rsp)
mov    %rdi,%rbx
mulsd  %xmm3,%xmm2
xorps  %xmm0,%xmm0
cvtsd2ss %xmm2,%xmm0
movss  %xmm0,0xc(%rsp)
movaps %xmm4,%xmm0
call   1030 <sin@plt>
movaps %xmm0,0x50(%rsp)
movss  0x20(%rsp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,0x20(%rsp)
movss  0x10(%rsp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,0x40(%rsp)
movss  0x10(%rsp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,0x30(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <cos@plt>
movaps 0xe51(%rip),%xmm1
movaps 0x20(%rsp),%xmm5
movaps %xmm5,%xmm2
xorps  %xmm1,%xmm2
movaps %xmm5,%xmm3
movaps 0x40(%rsp),%xmm6
unpcklps %xmm6,%xmm3
movaps %xmm6,%xmm4
movaps %xmm6,%xmm8
movaps 0x30(%rsp),%xmm7
unpcklps %xmm7,%xmm4
unpcklps %xmm2,%xmm7
mulps  %xmm3,%xmm7
movaps 0x50(%rsp),%xmm6
shufps $0x0,%xmm6,%xmm6
mulps  %xmm4,%xmm6
movaps 0x10(%rsp),%xmm4
movaps %xmm4,%xmm2
unpcklps %xmm0,%xmm2
mulps  %xmm6,%xmm2
movaps %xmm0,%xmm3
unpcklps %xmm4,%xmm3
movaps %xmm4,%xmm9
movaps %xmm7,%xmm4
mulps  %xmm3,%xmm4
addps  %xmm2,%xmm4
cvtps2pd %xmm4,%xmm2
movups %xmm2,(%rbx)
mulss  %xmm8,%xmm5
xorps  %xmm6,%xmm1
shufps $0xd4,%xmm6,%xmm0
shufps $0x52,%xmm6,%xmm0
movaps %xmm9,%xmm2
unpcklps %xmm1,%xmm2
mulps  %xmm0,%xmm2
movaps %xmm5,%xmm0
unpcklps %xmm7,%xmm0
mulps  %xmm3,%xmm0
addps  %xmm2,%xmm0
cvtps2pd %xmm0,%xmm0
movups %xmm0,0x10(%rbx)
add    $0x60,%rsp
pop    %rbx
ret

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

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