#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 asin(int);
double atan2(int, double);
void quat2euler(double q[4], double euler[3]) {
  double q0 = q[0];
  double q1 = q[1];
  double q2 = q[2];
  double q3 = q[3];
  double theta = asin(-2 * (q1 * q3 - q0 * q2));
  double phi =
      atan2(2 * (q2 * q3 + q0 * q1), (q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3));
  double psi =
      atan2(2 * (q1 * q2 + q0 * q3), (q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3));
  euler[0] = phi;
  euler[1] = theta;
  euler[2] = psi;
}


x86 assembly (clang, -O0):
<quat2euler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe66(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <asin@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe28(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd84(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat2euler>:
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
movsd  (%rdi),%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x8(%rdi),%xmm3
movsd  %xmm3,0x8(%rsp)
movsd  0x10(%rdi),%xmm0
movapd %xmm0,0x40(%rsp)
movsd  0x18(%rdi),%xmm2
movsd  %xmm2,0x10(%rsp)
mulsd  %xmm1,%xmm0
movapd %xmm3,%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe95(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1040 <asin@plt>
movsd  %xmm0,0x38(%rsp)
movsd  0x18(%rsp),%xmm2
movapd %xmm2,%xmm0
movsd  0x8(%rsp),%xmm3
mulsd  %xmm3,%xmm0
movapd 0x40(%rsp),%xmm5
movapd %xmm5,%xmm1
movsd  0x10(%rsp),%xmm4
mulsd  %xmm4,%xmm1
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm1
cvttsd2si %xmm1,%edi
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
movsd  %xmm1,0x28(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x30(%rsp)
subsd  %xmm1,%xmm0
movapd 0xe3a(%rip),%xmm2
xorpd  %xmm5,%xmm2
mulsd  %xmm5,%xmm2
movapd %xmm2,0x50(%rsp)
addsd  %xmm2,%xmm0
movapd %xmm4,%xmm1
mulsd  %xmm4,%xmm1
movsd  %xmm1,0x20(%rsp)
addsd  %xmm1,%xmm0
call   1030 <atan2@plt>
movsd  0x18(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  0x40(%rsp),%xmm1
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm1
cvttsd2si %xmm1,%edi
movsd  %xmm0,0x8(%rsp)
movsd  0x30(%rsp),%xmm0
addsd  0x28(%rsp),%xmm0
addsd  0x50(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
call   1030 <atan2@plt>
movsd  0x8(%rsp),%xmm1
movsd  %xmm1,(%rbx)
movsd  0x38(%rsp),%xmm1
movsd  %xmm1,0x8(%rbx)
movsd  %xmm0,0x10(%rbx)
add    $0x60,%rsp
pop    %rbx
ret

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

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