#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 atan2(double, float);
int fabs(double);
double sqrt(float);
void lib3ds_quat_ln(float c[4]) {
  double om, s, t;
  s = sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]);
  om = atan2(s, c[3]);
  if (fabs(s) < (1e-5)) {
    t = 0.0f;
  } else {
    t = om / s;
  }
  {
    int i;
    for (i = 0; i < 3; ++i) {
      c[i] = (float)(c[i] * t);
    }
    c[3] = 0.0f;
  }
}


x86 assembly (clang, -O0):
<lib3ds_quat_ln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe48(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11cf <lib3ds_quat_ln+0x9f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11de <lib3ds_quat_ln+0xae>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1224 <lib3ds_quat_ln+0xf4>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e5 <lib3ds_quat_ln+0xb5>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0xc(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib3ds_quat_ln>:
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   1050 <sqrt@plt>
movsd  %xmm0,(%rsp)
movss  0xc(%rbx),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    118f <lib3ds_quat_ln+0x5f>
movsd  0x8(%rsp),%xmm2
divsd  (%rsp),%xmm2
jmp    1193 <lib3ds_quat_ln+0x63>
xorpd  %xmm2,%xmm2
movss  (%rbx),%xmm0
movss  0x4(%rbx),%xmm1
cvtss2sd %xmm0,%xmm0
mulsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mulsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x4(%rbx)
movss  0x8(%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rbx)
movl   $0x0,0xc(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define void @lib3ds_quat_ln(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 = getelementptr inbounds float, float* %0, i64 3
%12 = load float, float* %11
%13 = tail call double @atan2(double %10, float %12)
%14 = tail call i32 @fabs(double %10)
%15 = icmp slt i32 %14, 1
%16 = fdiv double %13, %10
%17 = select i1 %15, double 0.000000e+00, double %16
%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
store float 0.000000e+00, float* %11
ret void
}