#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 rpy2quat(double yaw, double pitch, double roll, double q[4]) {
  double angles[3];
  double cang[3];
  int i0;
  double b_cang;
  angles[0] = yaw;
  angles[1] = pitch;
  angles[2] = roll;
  for (i0 = 0; i0 < 3; i0++) {
    b_cang = cos(angles[i0] / 2.0);
    angles[i0] = sin(angles[i0] / 2.0);
    cang[i0] = b_cang;
  }
  q[0] = cang[0] * cang[1] * cang[2] + angles[0] * angles[1] * angles[2];
  q[1] = cang[0] * cang[1] * angles[2] - angles[0] * angles[1] * cang[2];
  q[2] = cang[0] * angles[1] * cang[2] + angles[0] * cang[1] * angles[2];
  q[3] = angles[0] * cang[1] * cang[2] - cang[0] * angles[1] * angles[2];
}


x86 assembly (clang, -O0):
<rpy2quat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x3,-0x64(%rbp)
jge    11cc <rpy2quat+0xac>
movslq -0x64(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
movsd  0xe84(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x70(%rbp)
movslq -0x64(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
movsd  0xe64(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movslq -0x64(%rbp),%rax
movsd  %xmm0,-0x40(%rbp,%rax,8)
movsd  -0x70(%rbp),%xmm0
movslq -0x64(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1160 <rpy2quat+0x40>
movsd  -0x60(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x18(%rax)
add    $0x70,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @rpy2quat(double %0, double %1, double %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca [3 x double]
%10 = alloca [3 x double]
%11 = alloca i32
%12 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double* %3, double** %8
%13 = load double, double* %5
%14 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
store double %13, double* %14
%15 = load double, double* %6
%16 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
store double %15, double* %16
%17 = load double, double* %7
%18 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
store double %17, double* %18
store i32 0, i32* %11
br label %19
19: ; preds = %42, %4
%20 = load i32, i32* %11
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %45
22: ; preds = %19
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %24
%26 = load double, double* %25
%27 = fdiv double %26, 2.000000e+00
%28 = call double @cos(double %27)
store double %28, double* %12
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %30
%32 = load double, double* %31
%33 = fdiv double %32, 2.000000e+00
%34 = call double @sin(double %33)
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 %36
store double %34, double* %37
%38 = load double, double* %12
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 %40
store double %38, double* %41
br label %42
42: ; preds = %22
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %19
45: ; preds = %19
%46 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%47 = load double, double* %46
%48 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 1
%49 = load double, double* %48
%50 = fmul double %47, %49
%51 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 2
%52 = load double, double* %51
%53 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%54 = load double, double* %53
%55 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%56 = load double, double* %55
%57 = fmul double %54, %56
%58 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%59 = load double, double* %58
%60 = fmul double %57, %59
%61 = call double @llvm.fmuladd.f64(double %50, double %52, double %60)
%62 = load double*, double** %8
%63 = getelementptr inbounds double, double* %62, i64 0
store double %61, double* %63
%64 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%65 = load double, double* %64
%66 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 1
%67 = load double, double* %66
%68 = fmul double %65, %67
%69 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%70 = load double, double* %69
%71 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%72 = load double, double* %71
%73 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%74 = load double, double* %73
%75 = fmul double %72, %74
%76 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 2
%77 = load double, double* %76
%78 = fmul double %75, %77
%79 = fneg double %78
%80 = call double @llvm.fmuladd.f64(double %68, double %70, double %79)
%81 = load double*, double** %8
%82 = getelementptr inbounds double, double* %81, i64 1
store double %80, double* %82
%83 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%84 = load double, double* %83
%85 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%86 = load double, double* %85
%87 = fmul double %84, %86
%88 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 2
%89 = load double, double* %88
%90 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%91 = load double, double* %90
%92 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 1
%93 = load double, double* %92
%94 = fmul double %91, %93
%95 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%96 = load double, double* %95
%97 = fmul double %94, %96
%98 = call double @llvm.fmuladd.f64(double %87, double %89, double %97)
%99 = load double*, double** %8
%100 = getelementptr inbounds double, double* %99, i64 2
store double %98, double* %100
%101 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%102 = load double, double* %101
%103 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 1
%104 = load double, double* %103
%105 = fmul double %102, %104
%106 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 2
%107 = load double, double* %106
%108 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%109 = load double, double* %108
%110 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%111 = load double, double* %110
%112 = fmul double %109, %111
%113 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%114 = load double, double* %113
%115 = fmul double %112, %114
%116 = fneg double %115
%117 = call double @llvm.fmuladd.f64(double %105, double %107, double %116)
%118 = load double*, double** %8
%119 = getelementptr inbounds double, double* %118, i64 3
store double %117, double* %119
ret void
}

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