#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 const);
double sin(double const);
void rpy_to_quat(const double rpy[3], double quat[4]) {
  double c_r = cos(rpy[0] / 2);
  double c_p = cos(rpy[1] / 2);
  double c_y = cos(rpy[2] / 2);
  double s_r = sin(rpy[0] / 2);
  double s_p = sin(rpy[1] / 2);
  double s_y = sin(rpy[2] / 2);
  quat[0] = c_r * c_p * c_y + s_r * s_p * s_y;
  quat[1] = s_r * c_p * c_y - c_r * s_p * s_y;
  quat[2] = c_r * s_p * c_y + s_r * c_p * s_y;
  quat[3] = c_r * c_p * s_y - s_r * s_p * c_y;
}


x86 assembly (clang, -O0):
<rpy_to_quat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xec0(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  0xea1(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe64(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  0xe45(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  0xe26(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x18(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpy_to_quat>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
mulsd  0xec7(%rip),%xmm0
call   1040 <cos@plt>
movapd %xmm0,0x30(%rsp)
movsd  0x8(%rbx),%xmm0
mulsd  0xeaf(%rip),%xmm0
call   1040 <cos@plt>
movapd %xmm0,0x20(%rsp)
movsd  0x10(%rbx),%xmm0
mulsd  0xe97(%rip),%xmm0
call   1040 <cos@plt>
movapd %xmm0,0x40(%rsp)
movsd  (%rbx),%xmm0
mulsd  0xe80(%rip),%xmm0
call   1030 <sin@plt>
movapd %xmm0,0x10(%rsp)
movsd  0x8(%rbx),%xmm0
mulsd  0xe68(%rip),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe55(%rip),%xmm0
mulsd  0x10(%rbx),%xmm0
call   1030 <sin@plt>
movapd 0x20(%rsp),%xmm2
unpcklpd %xmm2,%xmm2
movapd 0x30(%rsp),%xmm4
movapd %xmm4,%xmm1
movapd 0x10(%rsp),%xmm7
unpcklpd %xmm7,%xmm1
movsd  0x8(%rsp),%xmm3
mulsd  %xmm3,%xmm7
mulpd  %xmm2,%xmm1
mulsd  %xmm3,%xmm4
movapd 0xe23(%rip),%xmm2
movapd %xmm4,%xmm3
movapd %xmm4,%xmm5
xorpd  %xmm2,%xmm3
movapd %xmm7,%xmm4
unpcklpd %xmm3,%xmm4
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
mulpd  %xmm4,%xmm3
movapd 0x40(%rsp),%xmm6
movapd %xmm6,%xmm4
unpcklpd %xmm6,%xmm4
mulpd  %xmm1,%xmm4
addpd  %xmm3,%xmm4
movupd %xmm4,(%r14)
xorpd  %xmm2,%xmm7
unpcklpd %xmm1,%xmm5
movapd %xmm6,%xmm2
shufpd $0x1,%xmm6,%xmm1
unpcklpd %xmm0,%xmm2
unpcklpd %xmm7,%xmm0
mulpd  %xmm1,%xmm0
mulpd  %xmm5,%xmm2
addpd  %xmm0,%xmm2
movupd %xmm2,0x10(%r14)
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

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

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