#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 cos(double);
double sin(double);
void euler2quat(double q[4], double phi, double theta, double psi) {
  double shphi0;
  double chphi0;
  double shtheta0;
  double chtheta0;
  double shpsi0;
  double chpsi0;
  shphi0 = phi / 2.0;
  shtheta0 = theta / 2.0;
  shpsi0 = psi / 2.0;
  shphi0 = sin(shphi0);
  chphi0 = cos(shphi0);
  shtheta0 = sin(shtheta0);
  chtheta0 = cos(shtheta0);
  shpsi0 = sin(shpsi0);
  chpsi0 = cos(shpsi0);
  q[0] = chphi0 * chtheta0 * chpsi0 + shphi0 * shtheta0 * shpsi0;
  q[1] = shphi0 * chtheta0 * chpsi0 - chphi0 * shtheta0 * shpsi0;
  q[2] = chphi0 * shtheta0 * chpsi0 + shphi0 * chtheta0 * shpsi0;
  q[3] = chphi0 * chtheta0 * shpsi0 - shphi0 * shtheta0 * chpsi0;
}


x86 assembly (clang, -O0):
<euler2quat>:
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
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler2quat>:
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
movsd  0xed0(%rip),%xmm3
mulsd  %xmm3,%xmm0
mulsd  %xmm3,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
call   1030 <sin@plt>
movapd %xmm0,0x40(%rsp)
call   1040 <cos@plt>
movapd %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
call   1040 <cos@plt>
movaps %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
movapd %xmm0,0x10(%rsp)
call   1040 <cos@plt>
movapd 0x30(%rsp),%xmm3
movapd %xmm3,%xmm1
movapd 0x40(%rsp),%xmm4
unpcklpd %xmm4,%xmm1
movsd  0x8(%rsp),%xmm5
mulsd  %xmm5,%xmm4
movapd 0x20(%rsp),%xmm2
unpcklpd %xmm2,%xmm2
mulpd  %xmm1,%xmm2
movapd %xmm2,%xmm6
mulsd  %xmm5,%xmm3
movapd 0xe45(%rip),%xmm1
movapd %xmm3,%xmm2
movapd %xmm3,%xmm5
xorpd  %xmm1,%xmm2
movapd %xmm4,%xmm3
unpcklpd %xmm2,%xmm3
movapd 0x10(%rsp),%xmm7
movapd %xmm7,%xmm2
unpcklpd %xmm7,%xmm2
mulpd  %xmm3,%xmm2
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
mulpd  %xmm6,%xmm3
addpd  %xmm2,%xmm3
movupd %xmm3,(%rbx)
xorpd  %xmm1,%xmm4
unpcklpd %xmm6,%xmm5
shufpd $0x1,%xmm0,%xmm6
movapd %xmm7,%xmm1
unpcklpd %xmm7,%xmm0
unpcklpd %xmm4,%xmm1
mulpd  %xmm6,%xmm1
mulpd  %xmm5,%xmm0
addpd  %xmm1,%xmm0
movupd %xmm0,0x10(%rbx)
add    $0x50,%rsp
pop    %rbx
ret

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

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