#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 const sin(double);
double sqrt(double const);
void cquat_from_axisangle(double *q, const double *v, double angle) {
  double n = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
  angle = angle / 2.0;
  q[0] = sin(angle) * v[0] / n;
  q[1] = sin(angle) * v[1] / n;
  q[2] = sin(angle) * v[2] / n;
  q[3] = cos(angle);
}


x86 assembly (clang, -O0):
<cquat_from_axisangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe60(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
mov    -0x10(%rbp),%rax
mulsd  0x10(%rax),%xmm0
divsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cquat_from_axisangle>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  (%rsi),%xmm1
movsd  0x8(%rsi),%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1175 <cquat_from_axisangle+0x45>
sqrtsd %xmm0,%xmm0
jmp    117a <cquat_from_axisangle+0x4a>
call   1050 <sqrt@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe72(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <sin@plt>
mulsd  (%rbx),%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r14)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x8(%rbx),%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%r14)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x10(%rbx),%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%r14)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,0x18(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @cquat_from_axisangle(double* %0, double* %1, double %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double
%7 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double %2, double* %6
%8 = load double*, double** %5
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = load double*, double** %5
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = load double*, double** %5
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = fmul double %16, %19
%21 = call double @llvm.fmuladd.f64(double %10, double %13, double %20)
%22 = load double*, double** %5
%23 = getelementptr inbounds double, double* %22, i64 2
%24 = load double, double* %23
%25 = load double*, double** %5
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = call double @llvm.fmuladd.f64(double %24, double %27, double %21)
%29 = call double @sqrt(double %28)
store double %29, double* %7
%30 = load double, double* %6
%31 = fdiv double %30, 2.000000e+00
store double %31, double* %6
%32 = load double, double* %6
%33 = call double @sin(double %32)
%34 = load double*, double** %5
%35 = getelementptr inbounds double, double* %34, i64 0
%36 = load double, double* %35
%37 = fmul double %33, %36
%38 = load double, double* %7
%39 = fdiv double %37, %38
%40 = load double*, double** %4
%41 = getelementptr inbounds double, double* %40, i64 0
store double %39, double* %41
%42 = load double, double* %6
%43 = call double @sin(double %42)
%44 = load double*, double** %5
%45 = getelementptr inbounds double, double* %44, i64 1
%46 = load double, double* %45
%47 = fmul double %43, %46
%48 = load double, double* %7
%49 = fdiv double %47, %48
%50 = load double*, double** %4
%51 = getelementptr inbounds double, double* %50, i64 1
store double %49, double* %51
%52 = load double, double* %6
%53 = call double @sin(double %52)
%54 = load double*, double** %5
%55 = getelementptr inbounds double, double* %54, i64 2
%56 = load double, double* %55
%57 = fmul double %53, %56
%58 = load double, double* %7
%59 = fdiv double %57, %58
%60 = load double*, double** %4
%61 = getelementptr inbounds double, double* %60, i64 2
store double %59, double* %61
%62 = load double, double* %6
%63 = call double @cos(double %62)
%64 = load double*, double** %4
%65 = getelementptr inbounds double, double* %64, i64 3
store double %63, double* %65
ret void
}

LLVM IR (-O2):
define void @cquat_from_axisangle(double* nocapture writeonly %0, double* nocapture %1, double %2) {
%4 = load double, double* %1
%5 = getelementptr inbounds double, double* %1, i64 1
%6 = load double, double* %5
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = getelementptr inbounds double, double* %1, i64 2
%10 = load double, double* %9
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %8)
%12 = tail call double @sqrt(double %11)
%13 = fmul double %2, 5.000000e-01
%14 = tail call double @sin(double %13)
%15 = load double, double* %1
%16 = fmul double %14, %15
%17 = fdiv double %16, %12
store double %17, double* %0
%18 = tail call double @sin(double %13)
%19 = load double, double* %5
%20 = fmul double %18, %19
%21 = fdiv double %20, %12
%22 = getelementptr inbounds double, double* %0, i64 1
store double %21, double* %22
%23 = tail call double @sin(double %13)
%24 = load double, double* %9
%25 = fmul double %23, %24
%26 = fdiv double %25, %12
%27 = getelementptr inbounds double, double* %0, i64 2
store double %26, double* %27
%28 = tail call double @cos(double %13)
%29 = getelementptr inbounds double, double* %0, i64 3
store double %28, double* %29
ret void
}