#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, double);
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, (double)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
cvtss2sd %xmm1,%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe44(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d3 <lib3ds_quat_ln+0xa3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11e2 <lib3ds_quat_ln+0xb2>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    1228 <lib3ds_quat_ln+0xf8>
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    11e9 <lib3ds_quat_ln+0xb9>
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
cvtss2sd %xmm1,%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    1193 <lib3ds_quat_ln+0x63>
movsd  0x8(%rsp),%xmm2
divsd  (%rsp),%xmm2
jmp    1197 <lib3ds_quat_ln+0x67>
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 = fpext float %32 to double
%34 = call double @atan2(double %29, double %33)
store double %34, double* %3
%35 = load double, double* %4
%36 = call i32 @fabs(double %35)
%37 = sitofp i32 %36 to double
%38 = fcmp olt double %37, 1.000000e-05
br i1 %38, label %39, label %40
39: ; preds = %1
store double 0.000000e+00, double* %5
br label %44
40: ; preds = %1
%41 = load double, double* %3
%42 = load double, double* %4
%43 = fdiv double %41, %42
store double %43, double* %5
br label %44
44: ; preds = %40, %39
store i32 0, i32* %6
br label %45
45: ; preds = %62, %44
%46 = load i32, i32* %6
%47 = icmp slt i32 %46, 3
br i1 %47, label %48, label %65
48: ; preds = %45
%49 = load float*, float** %2
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds float, float* %49, i64 %51
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = load double, double* %5
%56 = fmul double %54, %55
%57 = fptrunc double %56 to float
%58 = load float*, float** %2
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %58, i64 %60
store float %57, float* %61
br label %62
62: ; preds = %48
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %45
65: ; preds = %45
%66 = load float*, float** %2
%67 = getelementptr inbounds float, float* %66, i64 3
store float 0.000000e+00, float* %67
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 = fpext float %12 to double
%14 = tail call double @atan2(double %10, double %13)
%15 = tail call i32 @fabs(double %10)
%16 = icmp slt i32 %15, 1
%17 = fdiv double %14, %10
%18 = select i1 %16, double 0.000000e+00, double %17
%19 = load float, float* %0
%20 = fpext float %19 to double
%21 = fmul double %18, %20
%22 = fptrunc double %21 to float
store float %22, float* %0
%23 = load float, float* %3
%24 = fpext float %23 to double
%25 = fmul double %18, %24
%26 = fptrunc double %25 to float
store float %26, float* %3
%27 = load float, float* %7
%28 = fpext float %27 to double
%29 = fmul double %18, %28
%30 = fptrunc double %29 to float
store float %30, float* %7
store float 0.000000e+00, float* %11
ret void
}