#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 */
scalar_t__ cos(double);
scalar_t__ sin(double);
void doubles_rpy_to_quat(const double rpy[3], double quat[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 = (double)sin(halfroll);
  double sin_p2 = (double)sin(halfpitch);
  double sin_y2 = (double)sin(halfyaw);
  double cos_r2 = (double)cos(halfroll);
  double cos_p2 = (double)cos(halfpitch);
  double cos_y2 = (double)cos(halfyaw);
  quat[0] = cos_r2 * cos_p2 * cos_y2 + sin_r2 * sin_p2 * sin_y2;
  quat[1] = sin_r2 * cos_p2 * cos_y2 - cos_r2 * sin_p2 * sin_y2;
  quat[2] = cos_r2 * sin_p2 * cos_y2 + sin_r2 * cos_p2 * sin_y2;
  quat[3] = cos_r2 * cos_p2 * sin_y2 - sin_r2 * sin_p2 * cos_y2;
}


x86 assembly (clang, -O0):
<doubles_rpy_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>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <sin@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <sin@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <cos@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <cos@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
cvtsi2sd %rax,%xmm0
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):
<doubles_rpy_to_quat>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
movsd  0xed0(%rip),%xmm2
movsd  (%rdi),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rdi),%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,(%rsp)
mulsd  0x10(%rdi),%xmm2
movsd  %xmm2,0x10(%rsp)
call   1030 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  (%rsp),%xmm0
call   1030 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <cos@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  0x8(%rsp),%xmm8
movapd %xmm8,%xmm0
movsd  (%rsp),%xmm9
mulsd  %xmm9,%xmm0
movsd  0x28(%rsp),%xmm5
movapd %xmm5,%xmm2
movsd  0x20(%rsp),%xmm6
mulsd  %xmm6,%xmm2
movapd %xmm2,%xmm3
movsd  0x18(%rsp),%xmm7
mulsd  %xmm7,%xmm3
movapd %xmm0,%xmm4
mulsd  %xmm1,%xmm4
addsd  %xmm3,%xmm4
movsd  %xmm4,(%rbx)
mulsd  %xmm9,%xmm5
mulsd  %xmm8,%xmm6
movapd %xmm7,%xmm3
mulsd  %xmm6,%xmm3
movapd %xmm5,%xmm4
mulsd  %xmm1,%xmm4
subsd  %xmm3,%xmm4
movsd  %xmm4,0x8(%rbx)
mulsd  %xmm7,%xmm5
mulsd  %xmm1,%xmm6
addsd  %xmm5,%xmm6
movsd  %xmm6,0x10(%rbx)
mulsd  %xmm1,%xmm2
mulsd  %xmm7,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rbx)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @doubles_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
%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 i64 @sin(double %32)
%34 = sitofp i64 %33 to double
store double %34, double* %11
%35 = load double, double* %9
%36 = call i64 @sin(double %35)
%37 = sitofp i64 %36 to double
store double %37, double* %12
%38 = load double, double* %10
%39 = call i64 @sin(double %38)
%40 = sitofp i64 %39 to double
store double %40, double* %13
%41 = load double, double* %8
%42 = call i64 @cos(double %41)
%43 = sitofp i64 %42 to double
store double %43, double* %14
%44 = load double, double* %9
%45 = call i64 @cos(double %44)
%46 = sitofp i64 %45 to double
store double %46, double* %15
%47 = load double, double* %10
%48 = call i64 @cos(double %47)
%49 = sitofp i64 %48 to double
store double %49, double* %16
%50 = load double, double* %14
%51 = load double, double* %15
%52 = fmul double %50, %51
%53 = load double, double* %16
%54 = load double, double* %11
%55 = load double, double* %12
%56 = fmul double %54, %55
%57 = load double, double* %13
%58 = fmul double %56, %57
%59 = call double @llvm.fmuladd.f64(double %52, double %53, double %58)
%60 = load double*, double** %4
%61 = getelementptr inbounds double, double* %60, i64 0
store double %59, double* %61
%62 = load double, double* %11
%63 = load double, double* %15
%64 = fmul double %62, %63
%65 = load double, double* %16
%66 = load double, double* %14
%67 = load double, double* %12
%68 = fmul double %66, %67
%69 = load double, double* %13
%70 = fmul double %68, %69
%71 = fneg double %70
%72 = call double @llvm.fmuladd.f64(double %64, double %65, double %71)
%73 = load double*, double** %4
%74 = getelementptr inbounds double, double* %73, i64 1
store double %72, double* %74
%75 = load double, double* %14
%76 = load double, double* %12
%77 = fmul double %75, %76
%78 = load double, double* %16
%79 = load double, double* %11
%80 = load double, double* %15
%81 = fmul double %79, %80
%82 = load double, double* %13
%83 = fmul double %81, %82
%84 = call double @llvm.fmuladd.f64(double %77, double %78, double %83)
%85 = load double*, double** %4
%86 = getelementptr inbounds double, double* %85, i64 2
store double %84, double* %86
%87 = load double, double* %14
%88 = load double, double* %15
%89 = fmul double %87, %88
%90 = load double, double* %13
%91 = load double, double* %11
%92 = load double, double* %12
%93 = fmul double %91, %92
%94 = load double, double* %16
%95 = fmul double %93, %94
%96 = fneg double %95
%97 = call double @llvm.fmuladd.f64(double %89, double %90, double %96)
%98 = load double*, double** %4
%99 = getelementptr inbounds double, double* %98, i64 3
store double %97, double* %99
ret void
}

LLVM IR (-O2):
define void @doubles_rpy_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 i64 @sin(double %8)
%12 = sitofp i64 %11 to double
%13 = tail call i64 @sin(double %9)
%14 = sitofp i64 %13 to double
%15 = tail call i64 @sin(double %10)
%16 = sitofp i64 %15 to double
%17 = tail call i64 @cos(double %8)
%18 = sitofp i64 %17 to double
%19 = tail call i64 @cos(double %9)
%20 = sitofp i64 %19 to double
%21 = tail call i64 @cos(double %10)
%22 = sitofp i64 %21 to double
%23 = fmul double %18, %20
%24 = fmul double %12, %14
%25 = fmul double %24, %16
%26 = tail call double @llvm.fmuladd.f64(double %23, double %22, double %25)
store double %26, double* %1
%27 = fmul double %12, %20
%28 = fmul double %14, %18
%29 = fneg double %28
%30 = fmul double %16, %29
%31 = tail call double @llvm.fmuladd.f64(double %27, double %22, double %30)
%32 = getelementptr inbounds double, double* %1, i64 1
store double %31, double* %32
%33 = fmul double %27, %16
%34 = tail call double @llvm.fmuladd.f64(double %28, double %22, double %33)
%35 = getelementptr inbounds double, double* %1, i64 2
store double %34, double* %35
%36 = fneg double %24
%37 = fmul double %36, %22
%38 = tail call double @llvm.fmuladd.f64(double %23, double %16, double %37)
%39 = getelementptr inbounds double, double* %1, i64 3
store double %38, double* %39
ret void
}