#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 HeadingFromQuaternion(float const *);
float asin(double);
float atan2(double, double);
void EulerAnglesFromQuaternion(const float quat[4], float *phi, float *theta,
                               float *psi) {
  *phi = atan2(2.0 * (quat[0] * quat[1] + quat[2] * quat[3]),
               1.0 - 2.0 * (quat[1] * quat[1] + quat[2] * quat[2]));
  *theta = asin(2.0 * (quat[0] * quat[2] - quat[1] * quat[3]));
  *psi = HeadingFromQuaternion(quat);
}


x86 assembly (clang, -O0):
<EulerAnglesFromQuaternion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulss  0xc(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe81(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm3
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mov    -0x8(%rbp),%rax
mulss  0x8(%rax),%xmm2
mulss  %xmm3,%xmm1
addss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm2
addsd  %xmm2,%xmm2
movsd  0xe49(%rip),%xmm1
subsd  %xmm2,%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulss  0xc(%rax),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdec(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <asin@plt>
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <HeadingFromQuaternion@plt>
mov    -0x20(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EulerAnglesFromQuaternion>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
movss  0x4(%rdi),%xmm1
movss  0x8(%rdi),%xmm2
movss  0xc(%rdi),%xmm0
mulss  %xmm2,%xmm0
movss  (%rdi),%xmm3
mulss  %xmm1,%xmm3
addss  %xmm0,%xmm3
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
addsd  %xmm0,%xmm0
mulss  %xmm2,%xmm2
mulss  %xmm1,%xmm1
addss  %xmm2,%xmm1
xorps  %xmm2,%xmm2
cvtss2sd %xmm1,%xmm2
addsd  %xmm2,%xmm2
movsd  0xe73(%rip),%xmm1
subsd  %xmm2,%xmm1
call   1030 <atan2@plt>
movss  %xmm0,(%r12)
movss  (%rbx),%xmm0
movss  0xc(%rbx),%xmm1
mulss  0x4(%rbx),%xmm1
mulss  0x8(%rbx),%xmm0
subss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
call   1040 <asin@plt>
movss  %xmm0,(%r15)
mov    %rbx,%rdi
call   1050 <HeadingFromQuaternion@plt>
movss  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @EulerAnglesFromQuaternion(float* %0, float* %1, float* %2, float* %3) {
%5 = alloca float*
%6 = alloca float*
%7 = alloca float*
%8 = alloca float*
store float* %0, float** %5
store float* %1, float** %6
store float* %2, float** %7
store float* %3, float** %8
%9 = load float*, float** %5
%10 = getelementptr inbounds float, float* %9, i64 0
%11 = load float, float* %10
%12 = load float*, float** %5
%13 = getelementptr inbounds float, float* %12, i64 1
%14 = load float, float* %13
%15 = load float*, float** %5
%16 = getelementptr inbounds float, float* %15, i64 2
%17 = load float, float* %16
%18 = load float*, float** %5
%19 = getelementptr inbounds float, float* %18, i64 3
%20 = load float, float* %19
%21 = fmul float %17, %20
%22 = call float @llvm.fmuladd.f32(float %11, float %14, float %21)
%23 = fpext float %22 to double
%24 = fmul double 2.000000e+00, %23
%25 = load float*, float** %5
%26 = getelementptr inbounds float, float* %25, i64 1
%27 = load float, float* %26
%28 = load float*, float** %5
%29 = getelementptr inbounds float, float* %28, i64 1
%30 = load float, float* %29
%31 = load float*, float** %5
%32 = getelementptr inbounds float, float* %31, i64 2
%33 = load float, float* %32
%34 = load float*, float** %5
%35 = getelementptr inbounds float, float* %34, i64 2
%36 = load float, float* %35
%37 = fmul float %33, %36
%38 = call float @llvm.fmuladd.f32(float %27, float %30, float %37)
%39 = fpext float %38 to double
%40 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %39, double 1.000000e+00)
%41 = call float @atan2(double %24, double %40)
%42 = load float*, float** %6
store float %41, float* %42
%43 = load float*, float** %5
%44 = getelementptr inbounds float, float* %43, i64 0
%45 = load float, float* %44
%46 = load float*, float** %5
%47 = getelementptr inbounds float, float* %46, i64 2
%48 = load float, float* %47
%49 = load float*, float** %5
%50 = getelementptr inbounds float, float* %49, i64 1
%51 = load float, float* %50
%52 = load float*, float** %5
%53 = getelementptr inbounds float, float* %52, i64 3
%54 = load float, float* %53
%55 = fmul float %51, %54
%56 = fneg float %55
%57 = call float @llvm.fmuladd.f32(float %45, float %48, float %56)
%58 = fpext float %57 to double
%59 = fmul double 2.000000e+00, %58
%60 = call float @asin(double %59)
%61 = load float*, float** %7
store float %60, float* %61
%62 = load float*, float** %5
%63 = call float @HeadingFromQuaternion(float* %62)
%64 = load float*, float** %8
store float %63, float* %64
ret void
}

LLVM IR (-O2):
define void @EulerAnglesFromQuaternion(float* %0, float* nocapture writeonly %1, float* nocapture writeonly %2, float* nocapture writeonly %3) {
%5 = load float, float* %0
%6 = getelementptr inbounds float, float* %0, i64 1
%7 = load float, float* %6
%8 = getelementptr inbounds float, float* %0, i64 2
%9 = load float, float* %8
%10 = getelementptr inbounds float, float* %0, i64 3
%11 = load float, float* %10
%12 = fmul float %9, %11
%13 = tail call float @llvm.fmuladd.f32(float %5, float %7, float %12)
%14 = fpext float %13 to double
%15 = fmul double %14, 2.000000e+00
%16 = fmul float %9, %9
%17 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %16)
%18 = fpext float %17 to double
%19 = tail call double @llvm.fmuladd.f64(double %18, double -2.000000e+00, double 1.000000e+00)
%20 = tail call float @atan2(double %15, double %19)
store float %20, float* %1
%21 = load float, float* %0
%22 = load float, float* %8
%23 = load float, float* %6
%24 = load float, float* %10
%25 = fneg float %23
%26 = fmul float %24, %25
%27 = tail call float @llvm.fmuladd.f32(float %21, float %22, float %26)
%28 = fpext float %27 to double
%29 = fmul double %28, 2.000000e+00
%30 = tail call float @asin(double %29)
store float %30, float* %2
%31 = tail call float @HeadingFromQuaternion(float* %0)
store float %31, float* %3
ret void
}