#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 */
scalar_t__ cos(double);
int fabs(double);
double sin(double);
double sqrt(float);
void lib3ds_quat_exp(float c[4]) {
  double om, sinom;
  om = sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]);
  if (fabs(om) < (1e-5)) {
    sinom = 1.0f;
  } else {
    sinom = sin(om) / om;
  }
  {
    int i;
    for (i = 0; i < 3; ++i) {
      c[i] = (float)(c[i] * sinom);
    }
    c[3] = (float)cos(om);
  }
}


x86 assembly (clang, -O0):
<lib3ds_quat_exp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe50(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11cc <lib3ds_quat_exp+0x8c>
movsd  0xe46(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e0 <lib3ds_quat_exp+0xa0>
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1226 <lib3ds_quat_exp+0xe6>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x18(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e7 <lib3ds_quat_exp+0xa7>
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
cvtsi2ss %rax,%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib3ds_quat_exp>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movss  (%rdi),%xmm1
movss  0x4(%rdi),%xmm0
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0x8(%rdi),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
call   1030 <fabs@plt>
test   %eax,%eax
jle    1195 <lib3ds_quat_exp+0x55>
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  0x8(%rsp),%xmm3
divsd  %xmm3,%xmm0
jmp    11a3 <lib3ds_quat_exp+0x63>
movsd  0xe63(%rip),%xmm0
movsd  0x8(%rsp),%xmm3
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm2
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
cvtss2sd %xmm2,%xmm2
mulsd  %xmm0,%xmm2
cvtsd2ss %xmm2,%xmm2
movss  %xmm1,(%rbx)
movss  %xmm2,0x4(%rbx)
movss  0x8(%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x8(%rbx)
movapd %xmm3,%xmm0
call   1050 <cos@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0xc(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @lib3ds_quat_exp(float* %0) {
%2 = alloca float*
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store float* %0, float** %2
%6 = load float*, float** %2
%7 = getelementptr inbounds float, float* %6, i64 0
%8 = load float, float* %7
%9 = load float*, float** %2
%10 = getelementptr inbounds float, float* %9, i64 0
%11 = load float, float* %10
%12 = load float*, float** %2
%13 = getelementptr inbounds float, float* %12, i64 1
%14 = load float, float* %13
%15 = load float*, float** %2
%16 = getelementptr inbounds float, float* %15, i64 1
%17 = load float, float* %16
%18 = fmul float %14, %17
%19 = call float @llvm.fmuladd.f32(float %8, float %11, float %18)
%20 = load float*, float** %2
%21 = getelementptr inbounds float, float* %20, i64 2
%22 = load float, float* %21
%23 = load float*, float** %2
%24 = getelementptr inbounds float, float* %23, i64 2
%25 = load float, float* %24
%26 = call float @llvm.fmuladd.f32(float %22, float %25, float %19)
%27 = call double @sqrt(float %26)
store double %27, double* %3
%28 = load double, double* %3
%29 = call i32 @fabs(double %28)
%30 = sitofp i32 %29 to double
%31 = fcmp olt double %30, 1.000000e-05
br i1 %31, label %32, label %33
32: ; preds = %1
store double 1.000000e+00, double* %4
br label %38
33: ; preds = %1
%34 = load double, double* %3
%35 = call double @sin(double %34)
%36 = load double, double* %3
%37 = fdiv double %35, %36
store double %37, double* %4
br label %38
38: ; preds = %33, %32
store i32 0, i32* %5
br label %39
39: ; preds = %56, %38
%40 = load i32, i32* %5
%41 = icmp slt i32 %40, 3
br i1 %41, label %42, label %59
42: ; preds = %39
%43 = load float*, float** %2
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds float, float* %43, i64 %45
%47 = load float, float* %46
%48 = fpext float %47 to double
%49 = load double, double* %4
%50 = fmul double %48, %49
%51 = fptrunc double %50 to float
%52 = load float*, float** %2
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds float, float* %52, i64 %54
store float %51, float* %55
br label %56
56: ; preds = %42
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %39
59: ; preds = %39
%60 = load double, double* %3
%61 = call i64 @cos(double %60)
%62 = sitofp i64 %61 to float
%63 = load float*, float** %2
%64 = getelementptr inbounds float, float* %63, i64 3
store float %62, float* %64
ret void
}

LLVM IR (-O2):
define void @lib3ds_quat_exp(float* nocapture %0) {
%2 = load float, float* %0
%3 = getelementptr inbounds float, float* %0, i64 1
%4 = load float, float* %3
%5 = fmul float %4, %4
%6 = tail call float @llvm.fmuladd.f32(float %2, float %2, float %5)
%7 = getelementptr inbounds float, float* %0, i64 2
%8 = load float, float* %7
%9 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %6)
%10 = tail call double @sqrt(float %9)
%11 = tail call i32 @fabs(double %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = tail call double @sin(double %10)
%15 = fdiv double %14, %10
br label %16
16: ; preds = %1, %13
%17 = phi double [ %15, %13 ], [ 1.000000e+00, %1 ]
%18 = load float, float* %0
%19 = fpext float %18 to double
%20 = fmul double %17, %19
%21 = fptrunc double %20 to float
store float %21, float* %0
%22 = load float, float* %3
%23 = fpext float %22 to double
%24 = fmul double %17, %23
%25 = fptrunc double %24 to float
store float %25, float* %3
%26 = load float, float* %7
%27 = fpext float %26 to double
%28 = fmul double %17, %27
%29 = fptrunc double %28 to float
store float %29, float* %7
%30 = tail call i64 @cos(double %10)
%31 = sitofp i64 %30 to float
%32 = getelementptr inbounds float, float* %0, i64 3
store float %31, float* %32
ret void
}