#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 */
int /*<<< orphan*/ memcpy(double *, double const *, int);
void so3_quat2rot(const double q[4], double R[9]) {
  const double q0 = q[0], qx = q[1], qy = q[2], qz = q[3];
  const double q0q0 = q0 * q0;
  const double qxqx = qx * qx;
  const double qyqy = qy * qy;
  const double qzqz = qz * qz;
  const double q0qx = q0 * qx;
  const double q0qz = q0 * qz;
  const double q0qy = q0 * qy;
  const double qxqy = qx * qy;
  const double qxqz = qx * qz;
  const double qyqz = qy * qz;
  const double data[9] = {q0q0 + qxqx - qyqy - qzqz, 2 * (qxqy - q0qz),
                          2 * (qxqz + q0qy),         2 * (qxqy + q0qz),
                          q0q0 - qxqx + qyqy - qzqz, 2 * (qyqz - q0qx),
                          2 * (qxqz - q0qy),         2 * (qyqz + q0qx),
                          q0q0 - qxqx - qyqy + qzqz};
  memcpy(R, data, 9 * sizeof(double));
}


x86 assembly (clang, -O0):
<so3_quat2rot>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%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)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0xd0(%rbp)
ff
movsd  -0x70(%rbp),%xmm1
subsd  -0x60(%rbp),%xmm1
movsd  0xde2(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
movsd  -0x78(%rbp),%xmm1
addsd  -0x68(%rbp),%xmm1
movsd  0xdc4(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0x70(%rbp),%xmm1
addsd  -0x60(%rbp),%xmm1
movsd  0xda6(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x80(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  0xd6c(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x78(%rbp),%xmm1
subsd  -0x68(%rbp),%xmm1
movsd  0xd4e(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x80(%rbp),%xmm1
addsd  -0x58(%rbp),%xmm1
movsd  0xd30(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x10(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0x48,%edx
call   1030 <memcpy@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<so3_quat2rot>:
sub    $0x48,%rsp
mov    %rsi,%rax
movupd (%rdi),%xmm6
movsd  0x10(%rdi),%xmm0
movsd  0x18(%rdi),%xmm1
movapd %xmm6,%xmm4
movapd %xmm0,%xmm9
movapd %xmm1,%xmm3
movapd %xmm6,%xmm8
movapd %xmm0,%xmm7
unpcklpd %xmm0,%xmm7
mulpd  %xmm6,%xmm7
mulsd  %xmm1,%xmm0
unpcklpd %xmm1,%xmm1
mulpd  %xmm6,%xmm1
mulsd  %xmm6,%xmm6
unpckhpd %xmm4,%xmm4
mulsd  %xmm9,%xmm9
mulsd  %xmm3,%xmm3
mulsd  %xmm4,%xmm8
mulsd  %xmm4,%xmm4
movapd %xmm8,%xmm5
unpcklpd %xmm7,%xmm5
shufpd $0x1,%xmm7,%xmm7
movapd %xmm6,%xmm2
addsd  %xmm4,%xmm2
subsd  %xmm9,%xmm2
subsd  %xmm3,%xmm2
movsd  %xmm2,(%rsp)
movapd %xmm7,%xmm2
subpd  %xmm1,%xmm2
addpd  %xmm1,%xmm7
shufpd $0x2,%xmm7,%xmm2
addpd  %xmm2,%xmm2
movupd %xmm2,0x8(%rsp)
addsd  %xmm7,%xmm7
movsd  %xmm7,0x18(%rsp)
subsd  %xmm4,%xmm6
movapd %xmm6,%xmm2
addsd  %xmm9,%xmm2
subsd  %xmm3,%xmm2
movsd  %xmm2,0x20(%rsp)
movsd  %xmm0,%xmm1
subpd  %xmm5,%xmm1
addpd  %xmm1,%xmm1
movupd %xmm1,0x28(%rsp)
addsd  %xmm8,%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x38(%rsp)
subsd  %xmm9,%xmm6
addsd  %xmm3,%xmm6
movsd  %xmm6,0x40(%rsp)
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0x48,%edx
call   1030 <memcpy@plt>
add    $0x48,%rsp
ret

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

LLVM IR (-O2):
define void @so3_quat2rot(double* nocapture %0, double* %1) {
%3 = alloca [9 x double]
%4 = bitcast double* %0 to <2 x double>*
%5 = load <2 x double>, <2 x double>* %4
%6 = getelementptr inbounds double, double* %0, i64 2
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %0, i64 3
%9 = load double, double* %8
%10 = extractelement <2 x double> %5, i64 0
%11 = fmul <2 x double> %5, %5
%12 = extractelement <2 x double> %11, i64 0
%13 = extractelement <2 x double> %5, i64 1
%14 = fmul double %13, %13
%15 = fmul double %7, %7
%16 = fmul double %9, %9
%17 = fmul double %10, %13
%18 = insertelement <2 x double> poison, double %7, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = fmul <2 x double> %5, %19
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%22 = insertelement <2 x double> poison, double %9, i64 0
%23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
%24 = fmul <2 x double> %5, %23
%25 = fmul double %7, %9
%26 = bitcast [9 x double]* %3 to i8*
%27 = getelementptr inbounds [9 x double], [9 x double]* %3, i64 0, i64 0
%28 = fadd double %12, %14
%29 = fsub double %28, %15
%30 = fsub double %29, %16
store double %30, double* %27
%31 = getelementptr inbounds [9 x double], [9 x double]* %3, i64 0, i64 1
%32 = fsub <2 x double> %21, %24
%33 = fadd <2 x double> %21, %24
%34 = shufflevector <2 x double> %32, <2 x double> %33, <2 x i32> <i32 0, i32 3>
%35 = fmul <2 x double> %34, <double 2.000000e+00, double 2.000000e+00>
%36 = bitcast double* %31 to <2 x double>*
store <2 x double> %35, <2 x double>* %36
%37 = getelementptr inbounds [9 x double], [9 x double]* %3, i64 0, i64 3
%38 = fadd <2 x double> %21, %24
%39 = extractelement <2 x double> %38, i64 0
%40 = fmul double %39, 2.000000e+00
store double %40, double* %37
%41 = getelementptr inbounds [9 x double], [9 x double]* %3, i64 0, i64 4
%42 = fsub double %12, %14
%43 = fadd double %42, %15
%44 = fsub double %43, %16
store double %44, double* %41
%45 = getelementptr inbounds [9 x double], [9 x double]* %3, i64 0, i64 5
%46 = insertelement <2 x double> %24, double %25, i64 0
%47 = insertelement <2 x double> poison, double %17, i64 0
%48 = shufflevector <2 x double> %47, <2 x double> %20, <2 x i32> <i32 0, i32 2>
%49 = fsub <2 x double> %46, %48
%50 = fmul <2 x double> %49, <double 2.000000e+00, double 2.000000e+00>
%51 = bitcast double* %45 to <2 x double>*
store <2 x double> %50, <2 x double>* %51
%52 = getelementptr inbounds [9 x double], [9 x double]* %3, i64 0, i64 7
%53 = fadd double %17, %25
%54 = fmul double %53, 2.000000e+00
store double %54, double* %52
%55 = getelementptr inbounds [9 x double], [9 x double]* %3, i64 0, i64 8
%56 = fsub double %42, %15
%57 = fadd double %56, %16
store double %57, double* %55
%58 = call i32 @memcpy(double* %1, double* %27, i32 72)
ret void
}