#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 bot_roll_pitch_yaw_to_quat(const double rpy[3], double q[4]) {
  double roll = rpy[0], pitch = rpy[1], yaw = rpy[2];
  double halfroll = roll / 2;
  double halfpitch = pitch / 2;
  double halfyaw = yaw / 2;
  double sin_r2 = sin(halfroll);
  double sin_p2 = sin(halfpitch);
  double sin_y2 = sin(halfyaw);
  double cos_r2 = cos(halfroll);
  double cos_p2 = cos(halfpitch);
  double cos_y2 = cos(halfyaw);
  q[0] = cos_r2 * cos_p2 * cos_y2 + sin_r2 * sin_p2 * sin_y2;
  q[1] = sin_r2 * cos_p2 * cos_y2 - cos_r2 * sin_p2 * sin_y2;
  q[2] = cos_r2 * sin_p2 * cos_y2 + sin_r2 * cos_p2 * sin_y2;
  q[3] = cos_r2 * cos_p2 * sin_y2 - sin_r2 * sin_p2 * cos_y2;
}


x86 assembly (clang, -O0):
<bot_roll_pitch_yaw_to_quat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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)
movsd  -0x18(%rbp),%xmm0
movsd  0xe9a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe84(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x58(%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  -0x60(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x70(%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    $0x70,%rsp
pop    %rbp
ret

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

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

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