#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);
int /*<<< orphan*/ rc_normalize_quaternion_array(float *);
double sin(double);
void rc_tb_to_quaternion_array(float tb[3], float q[4]) {
  double tbt[3];
  tbt[0] = tb[0] / 2.0;
  tbt[1] = tb[1] / 2.0;
  tbt[2] = tb[2] / 2.0;
  double cosX2 = cos(tbt[0]);
  double sinX2 = sin(tbt[0]);
  double cosY2 = cos(tbt[1]);
  double sinY2 = sin(tbt[1]);
  double cosZ2 = cos(tbt[2]);
  double sinZ2 = sin(tbt[2]);
  q[0] = cosX2 * cosY2 * cosZ2 + sinX2 * sinY2 * sinZ2;
  q[1] = sinX2 * cosY2 * cosZ2 - cosX2 * sinY2 * sinZ2;
  q[2] = cosX2 * sinY2 * cosZ2 + sinX2 * cosY2 * sinZ2;
  q[3] = cosX2 * cosY2 * sinZ2 - sinX2 * sinY2 * cosZ2;
  rc_normalize_quaternion_array(q);
  return;
}


x86 assembly (clang, -O0):
<rc_tb_to_quaternion_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeac(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe70(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x4(%rax)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0x8(%rax)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x40(%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
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movss  %xmm0,0xc(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <rc_normalize_quaternion_array@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_tb_to_quaternion_array>:
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
cvtss2sd %xmm0,%xmm0
movsd  0xeb3(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x20(%rsp)
cvtss2sd %xmm1,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  0x8(%rdi),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1050 <cos@plt>
movapd %xmm0,0x50(%rsp)
movsd  0x20(%rsp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,0x40(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movapd 0x20(%rsp),%xmm2
movapd %xmm2,%xmm7
movapd 0x30(%rsp),%xmm5
mulsd  %xmm5,%xmm7
movapd 0x40(%rsp),%xmm3
mulsd  %xmm3,%xmm2
movapd %xmm2,%xmm6
movapd 0x50(%rsp),%xmm1
unpcklpd %xmm1,%xmm1
unpcklpd %xmm3,%xmm5
mulpd  %xmm1,%xmm5
movapd 0xe06(%rip),%xmm2
movapd %xmm5,%xmm3
xorpd  %xmm2,%xmm3
xorpd  %xmm7,%xmm2
unpcklpd %xmm0,%xmm7
movapd %xmm5,%xmm4
movapd %xmm5,%xmm8
shufpd $0x1,%xmm6,%xmm4
movapd 0x10(%rsp),%xmm1
unpcklpd %xmm1,%xmm6
movapd %xmm0,%xmm5
unpcklpd %xmm3,%xmm5
mulpd  %xmm7,%xmm5
movapd %xmm1,%xmm3
unpcklpd %xmm0,%xmm3
unpcklpd %xmm2,%xmm0
mulpd  %xmm6,%xmm0
unpcklpd %xmm1,%xmm1
mulpd  %xmm4,%xmm1
addpd  %xmm5,%xmm1
mulpd  %xmm8,%xmm3
addpd  %xmm0,%xmm3
cvtpd2ps %xmm3,%xmm0
cvtpd2ps %xmm1,%xmm1
unpcklpd %xmm0,%xmm1
movupd %xmm1,(%rbx)
mov    %rbx,%rdi
add    $0x60,%rsp
pop    %rbx
jmp    1030 <rc_normalize_quaternion_array@plt>

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

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