#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);
int atan(double const);
int fabs(double);
int pow(double const, int);
void quat_to_rpy(const double quat[4], double rpy[3]) {
  const double qr = quat[0];
  const double qx = quat[1];
  const double qy = quat[2];
  const double qz = quat[3];
  double disc = qr * qy - qx * qz;
  if (fabs(disc + 0.5) < 1E-8) {
    rpy[0] = 2 * atan(qx / qr);
    rpy[1] = -3.141592653589793238462643383279502884196 / 2;
    rpy[2] = 0;
  } else if (fabs(disc - 0.5) < 1E-8) {
    rpy[0] = -2 * atan(qx / qr);
    rpy[1] = 3.141592653589793238462643383279502884196 / 2;
    rpy[2] = 0;
  } else {
    rpy[0] =
        atan(2 * (qr * qz + qx * qy) / (1 - 2 * (pow(qy, 2) + pow(qz, 2))));
    rpy[1] = asin(2 * disc);
    rpy[2] =
        atan(2 * (qr * qx + qy * qz) / (1 - 2 * (pow(qx, 2) + pow(qy, 2))));
  }
}


x86 assembly (clang, -O0):
<quat_to_rpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe41(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe23(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1227 <quat_to_rpy+0xe7>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <atan@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0xe0f(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
jmp    13b1 <quat_to_rpy+0x271>
movsd  -0x38(%rbp),%xmm0
movsd  0xdd4(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdb7(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1296 <quat_to_rpy+0x156>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <atan@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0xd98(%rip),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
jmp    13ac <quat_to_rpy+0x26c>
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd56(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
mov    %eax,-0x54(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
mov    -0x54(%rbp),%ecx
movsd  -0x50(%rbp),%xmm0
add    %eax,%ecx
shl    $0x1,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1040 <atan@plt>
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xcf7(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <asin@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xcbc(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
mov    %eax,-0x44(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
mov    -0x44(%rbp),%ecx
movsd  -0x40(%rbp),%xmm0
add    %eax,%ecx
shl    $0x1,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1040 <atan@plt>
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
jmp    13b1 <quat_to_rpy+0x271>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quat_to_rpy>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
movsd  (%rdi),%xmm3
movsd  0x8(%rdi),%xmm2
movsd  0x10(%rdi),%xmm1
movsd  0x18(%rdi),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
mulsd  %xmm2,%xmm0
movsd  %xmm3,(%rsp)
movapd %xmm3,%xmm2
movsd  %xmm1,0x18(%rsp)
mulsd  %xmm1,%xmm2
subsd  %xmm0,%xmm2
movsd  0xe73(%rip),%xmm0
movsd  %xmm2,0x20(%rsp)
addsd  %xmm2,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    12b8 <quat_to_rpy+0x178>
movsd  0xe5c(%rip),%xmm0
addsd  0x20(%rsp),%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    12e1 <quat_to_rpy+0x1a1>
movsd  0x8(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm2
mulsd  0x10(%rsp),%xmm2
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm2
movsd  %xmm2,0x28(%rsp)
mov    $0x2,%edi
call   1060 <pow@plt>
mov    %eax,%ebp
movsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
add    %ebp,%eax
add    %eax,%eax
mov    $0x1,%r14d
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
movsd  0x28(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1040 <atan@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rbx)
movsd  0x20(%rsp),%xmm0
addsd  %xmm0,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <asin@plt>
movsd  %xmm0,0x8(%rbx)
movsd  0x10(%rsp),%xmm2
mulsd  0x18(%rsp),%xmm2
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
mov    $0x2,%edi
call   1060 <pow@plt>
mov    %eax,%ebp
movsd  0x18(%rsp),%xmm0
mov    $0x2,%edi
call   1060 <pow@plt>
add    %ebp,%eax
add    %eax,%eax
sub    %eax,%r14d
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1040 <atan@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
jmp    1312 <quat_to_rpy+0x1d2>
movsd  0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
call   1040 <atan@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rbx)
movabs $0xbff921fb54442d18,%rax
21 f9 bf
jmp    130a <quat_to_rpy+0x1ca>
movsd  0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
call   1040 <atan@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rbx)
movabs $0x3ff921fb54442d18,%rax
21 f9 3f
mov    %rax,0x8(%rbx)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rbx)
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @quat_to_rpy(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
store double* %0, double** %3
store double* %1, double** %4
%10 = load double*, double** %3
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
store double %12, double* %5
%13 = load double*, double** %3
%14 = getelementptr inbounds double, double* %13, i64 1
%15 = load double, double* %14
store double %15, double* %6
%16 = load double*, double** %3
%17 = getelementptr inbounds double, double* %16, i64 2
%18 = load double, double* %17
store double %18, double* %7
%19 = load double*, double** %3
%20 = getelementptr inbounds double, double* %19, i64 3
%21 = load double, double* %20
store double %21, double* %8
%22 = load double, double* %5
%23 = load double, double* %7
%24 = load double, double* %6
%25 = load double, double* %8
%26 = fmul double %24, %25
%27 = fneg double %26
%28 = call double @llvm.fmuladd.f64(double %22, double %23, double %27)
store double %28, double* %9
%29 = load double, double* %9
%30 = fadd double %29, 5.000000e-01
%31 = call i32 @fabs(double %30)
%32 = sitofp i32 %31 to double
%33 = fcmp olt double %32, 1.000000e-08
br i1 %33, label %34, label %47
34: ; preds = %2
%35 = load double, double* %6
%36 = load double, double* %5
%37 = fdiv double %35, %36
%38 = call i32 @atan(double %37)
%39 = mul nsw i32 2, %38
%40 = sitofp i32 %39 to double
%41 = load double*, double** %4
%42 = getelementptr inbounds double, double* %41, i64 0
store double %40, double* %42
%43 = load double*, double** %4
%44 = getelementptr inbounds double, double* %43, i64 1
store double 0xBFF921FB54442D18, double* %44
%45 = load double*, double** %4
%46 = getelementptr inbounds double, double* %45, i64 2
store double 0.000000e+00, double* %46
br label %114
47: ; preds = %2
%48 = load double, double* %9
%49 = fsub double %48, 5.000000e-01
%50 = call i32 @fabs(double %49)
%51 = sitofp i32 %50 to double
%52 = fcmp olt double %51, 1.000000e-08
br i1 %52, label %53, label %66
53: ; preds = %47
%54 = load double, double* %6
%55 = load double, double* %5
%56 = fdiv double %54, %55
%57 = call i32 @atan(double %56)
%58 = mul nsw i32 -2, %57
%59 = sitofp i32 %58 to double
%60 = load double*, double** %4
%61 = getelementptr inbounds double, double* %60, i64 0
store double %59, double* %61
%62 = load double*, double** %4
%63 = getelementptr inbounds double, double* %62, i64 1
store double 0x3FF921FB54442D18, double* %63
%64 = load double*, double** %4
%65 = getelementptr inbounds double, double* %64, i64 2
store double 0.000000e+00, double* %65
br label %113
66: ; preds = %47
%67 = load double, double* %5
%68 = load double, double* %8
%69 = load double, double* %6
%70 = load double, double* %7
%71 = fmul double %69, %70
%72 = call double @llvm.fmuladd.f64(double %67, double %68, double %71)
%73 = fmul double 2.000000e+00, %72
%74 = load double, double* %7
%75 = call i32 @pow(double %74, i32 2)
%76 = load double, double* %8
%77 = call i32 @pow(double %76, i32 2)
%78 = add nsw i32 %75, %77
%79 = mul nsw i32 2, %78
%80 = sub nsw i32 1, %79
%81 = sitofp i32 %80 to double
%82 = fdiv double %73, %81
%83 = call i32 @atan(double %82)
%84 = sitofp i32 %83 to double
%85 = load double*, double** %4
%86 = getelementptr inbounds double, double* %85, i64 0
store double %84, double* %86
%87 = load double, double* %9
%88 = fmul double 2.000000e+00, %87
%89 = fptosi double %88 to i32
%90 = call double @asin(i32 %89)
%91 = load double*, double** %4
%92 = getelementptr inbounds double, double* %91, i64 1
store double %90, double* %92
%93 = load double, double* %5
%94 = load double, double* %6
%95 = load double, double* %7
%96 = load double, double* %8
%97 = fmul double %95, %96
%98 = call double @llvm.fmuladd.f64(double %93, double %94, double %97)
%99 = fmul double 2.000000e+00, %98
%100 = load double, double* %6
%101 = call i32 @pow(double %100, i32 2)
%102 = load double, double* %7
%103 = call i32 @pow(double %102, i32 2)
%104 = add nsw i32 %101, %103
%105 = mul nsw i32 2, %104
%106 = sub nsw i32 1, %105
%107 = sitofp i32 %106 to double
%108 = fdiv double %99, %107
%109 = call i32 @atan(double %108)
%110 = sitofp i32 %109 to double
%111 = load double*, double** %4
%112 = getelementptr inbounds double, double* %111, i64 2
store double %110, double* %112
br label %113
113: ; preds = %66, %53
br label %114
114: ; preds = %113, %34
ret void
}

LLVM IR (-O2):
define void @quat_to_rpy(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 %5
%11 = fmul double %9, %10
%12 = tail call double @llvm.fmuladd.f64(double %3, double %7, double %11)
%13 = fadd double %12, 5.000000e-01
%14 = tail call i32 @fabs(double %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = fdiv double %5, %3
%18 = tail call i32 @atan(double %17)
%19 = shl nsw i32 %18, 1
%20 = sitofp i32 %19 to double
store double %20, double* %1
%21 = getelementptr inbounds double, double* %1, i64 1
store double 0xBFF921FB54442D18, double* %21
br label %61
22: ; preds = %2
%23 = fadd double %12, -5.000000e-01
%24 = tail call i32 @fabs(double %23)
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = fdiv double %5, %3
%28 = tail call i32 @atan(double %27)
%29 = mul nsw i32 %28, -2
%30 = sitofp i32 %29 to double
store double %30, double* %1
%31 = getelementptr inbounds double, double* %1, i64 1
store double 0x3FF921FB54442D18, double* %31
br label %61
32: ; preds = %22
%33 = fmul double %5, %7
%34 = tail call double @llvm.fmuladd.f64(double %3, double %9, double %33)
%35 = fmul double %34, 2.000000e+00
%36 = tail call i32 @pow(double %7, i32 2)
%37 = tail call i32 @pow(double %9, i32 2)
%38 = add nsw i32 %37, %36
%39 = mul i32 %38, -2
%40 = or i32 %39, 1
%41 = sitofp i32 %40 to double
%42 = fdiv double %35, %41
%43 = tail call i32 @atan(double %42)
%44 = sitofp i32 %43 to double
store double %44, double* %1
%45 = fmul double %12, 2.000000e+00
%46 = fptosi double %45 to i32
%47 = tail call double @asin(i32 %46)
%48 = getelementptr inbounds double, double* %1, i64 1
store double %47, double* %48
%49 = fmul double %7, %9
%50 = tail call double @llvm.fmuladd.f64(double %3, double %5, double %49)
%51 = fmul double %50, 2.000000e+00
%52 = tail call i32 @pow(double %5, i32 2)
%53 = tail call i32 @pow(double %7, i32 2)
%54 = add nsw i32 %53, %52
%55 = mul i32 %54, -2
%56 = or i32 %55, 1
%57 = sitofp i32 %56 to double
%58 = fdiv double %51, %57
%59 = tail call i32 @atan(double %58)
%60 = sitofp i32 %59 to double
br label %61
61: ; preds = %26, %32, %16
%62 = phi double [ 0.000000e+00, %26 ], [ %60, %32 ], [ 0.000000e+00, %16 ]
%63 = getelementptr inbounds double, double* %1, i64 2
store double %62, double* %63
ret void
}