#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);
int eu2qu(double *eu, double *q, int p) {
  double phi1, phi, phi2, dphi1phi2, sphi1phi2, cphi, sphi, sign = 0.0;
  double epsijk;
  epsijk = (double)p;
  phi1 = eu[0] / 2.0;
  phi = eu[1] / 2.0;
  phi2 = eu[2] / 2.0;
  dphi1phi2 = phi1 - phi2;
  sphi1phi2 = phi1 + phi2;
  cphi = cos(phi);
  sphi = -1.0 * sin(phi);
  q[0] = cphi * cos(sphi1phi2) + 0.0;
  sign = ((q[0] >= 0.0) ? 1.0 : -1.0);
  q[0] *= sign;
  q[1] = epsijk * sign * sphi * cos(dphi1phi2) + 0.0;
  q[2] = epsijk * sign * sphi * sin(dphi1phi2) + 0.0;
  q[3] = -1.0 * epsijk * sign * cphi * sin(sphi1phi2) + 0.0;
  return 1;
}


x86 assembly (clang, -O0):
<eu2qu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xeb8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  0xe9e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  0xe84(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  0xe29(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
movsd  0xde9(%rip),%xmm3
movsd  0xdd9(%rip),%xmm2
xorps  %xmm0,%xmm0
cmplesd %xmm1,%xmm0
movaps %xmm0,%xmm1
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  0xd30(%rip),%xmm0
mulsd  -0x60(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x18(%rax)
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eu2qu>:
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
cvtsi2sd %edx,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xec6(%rip),%xmm1
movsd  (%rdi),%xmm3
mulsd  %xmm1,%xmm3
movsd  0x8(%rdi),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0x10(%rdi),%xmm1
movapd %xmm3,%xmm2
subsd  %xmm1,%xmm2
movsd  %xmm2,0x28(%rsp)
addsd  %xmm3,%xmm1
movsd  %xmm1,0x38(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
xorps  0xe85(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  0x38(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0x30(%rsp),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
setae  %al
lea    0xe67(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
movsd  0x28(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0xe09(%rip),%xmm0
movsd  %xmm0,0x8(%rbx)
movsd  0x28(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0xdeb(%rip),%xmm0
movsd  %xmm0,0x10(%rbx)
movsd  0x8(%rsp),%xmm0
mulsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x38(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rbx)
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @eu2qu(double* nocapture %0, double* nocapture writeonly %1, i32 %2) {
%4 = sitofp i32 %2 to double
%5 = load double, double* %0
%6 = fmul double %5, 5.000000e-01
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = fmul double %8, 5.000000e-01
%10 = getelementptr inbounds double, double* %0, i64 2
%11 = load double, double* %10
%12 = fmul double %11, 5.000000e-01
%13 = fsub double %6, %12
%14 = fadd double %6, %12
%15 = tail call double @cos(double %9)
%16 = tail call double @sin(double %9)
%17 = fneg double %16
%18 = tail call double @cos(double %14)
%19 = tail call double @llvm.fmuladd.f64(double %15, double %18, double 0.000000e+00)
%20 = fcmp oge double %19, 0.000000e+00
%21 = select i1 %20, double 1.000000e+00, double -1.000000e+00
%22 = fmul double %19, %21
store double %22, double* %1
%23 = fmul double %21, %4
%24 = fmul double %23, %17
%25 = tail call double @cos(double %13)
%26 = tail call double @llvm.fmuladd.f64(double %24, double %25, double 0.000000e+00)
%27 = getelementptr inbounds double, double* %1, i64 1
store double %26, double* %27
%28 = tail call double @sin(double %13)
%29 = tail call double @llvm.fmuladd.f64(double %24, double %28, double 0.000000e+00)
%30 = getelementptr inbounds double, double* %1, i64 2
store double %29, double* %30
%31 = fneg double %4
%32 = fmul double %21, %31
%33 = fmul double %15, %32
%34 = tail call double @sin(double %14)
%35 = tail call double @llvm.fmuladd.f64(double %33, double %34, double 0.000000e+00)
%36 = getelementptr inbounds double, double* %1, i64 3
store double %35, double* %36
ret i32 1
}