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


x86 assembly (clang, -O0):
<lib3ds_quat_normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulss  0x4(%rax),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe56(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ed <lib3ds_quat_normalize+0xcd>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,0x4(%rax)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movss  0xe2d(%rip),%xmm0
movss  %xmm0,0xc(%rax)
jmp    124a <lib3ds_quat_normalize+0x12a>
movsd  0xe13(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    1245 <lib3ds_quat_normalize+0x125>
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    1206 <lib3ds_quat_normalize+0xe6>
jmp    124a <lib3ds_quat_normalize+0x12a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib3ds_quat_normalize>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  0x8(%rdi),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  0xc(%rdi),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
call   1030 <fabs@plt>
test   %eax,%eax
jle    11d2 <lib3ds_quat_normalize+0xb2>
movsd  0xe8d(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm2
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,(%rbx)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x4(%rbx)
movss  0x8(%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x8(%rbx)
movss  0xc(%rbx),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
jmp    11e8 <lib3ds_quat_normalize+0xc8>
movl   $0x0,0x8(%rbx)
movq   $0x0,(%rbx)
movss  0xe20(%rip),%xmm0
movss  %xmm0,0xc(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @lib3ds_quat_normalize(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 = load float*, float** %2
%28 = getelementptr inbounds float, float* %27, i64 3
%29 = load float, float* %28
%30 = load float*, float** %2
%31 = getelementptr inbounds float, float* %30, i64 3
%32 = load float, float* %31
%33 = call float @llvm.fmuladd.f32(float %29, float %32, float %26)
%34 = call double @sqrt(float %33)
store double %34, double* %3
%35 = load double, double* %3
%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 %48
39: ; preds = %1
%40 = load float*, float** %2
%41 = getelementptr inbounds float, float* %40, i64 2
store float 0.000000e+00, float* %41
%42 = load float*, float** %2
%43 = getelementptr inbounds float, float* %42, i64 1
store float 0.000000e+00, float* %43
%44 = load float*, float** %2
%45 = getelementptr inbounds float, float* %44, i64 0
store float 0.000000e+00, float* %45
%46 = load float*, float** %2
%47 = getelementptr inbounds float, float* %46, i64 3
store float 1.000000e+00, float* %47
br label %72
48: ; preds = %1
%49 = load double, double* %3
%50 = fdiv double 1.000000e+00, %49
store double %50, double* %4
store i32 0, i32* %5
br label %51
51: ; preds = %68, %48
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 4
br i1 %53, label %54, label %71
54: ; preds = %51
%55 = load float*, float** %2
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds float, float* %55, i64 %57
%59 = load float, float* %58
%60 = fpext float %59 to double
%61 = load double, double* %4
%62 = fmul double %60, %61
%63 = fptrunc double %62 to float
%64 = load float*, float** %2
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds float, float* %64, i64 %66
store float %63, float* %67
br label %68
68: ; preds = %54
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %51
71: ; preds = %51
br label %72
72: ; preds = %71, %39
ret void
}

LLVM IR (-O2):
define void @lib3ds_quat_normalize(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 = getelementptr inbounds float, float* %0, i64 3
%11 = load float, float* %10
%12 = tail call float @llvm.fmuladd.f32(float %11, float %11, float %9)
%13 = tail call double @sqrt(float %12)
%14 = tail call i32 @fabs(double %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %1
store float 0.000000e+00, float* %7
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %0
br label %35
17: ; preds = %1
%18 = fdiv double 1.000000e+00, %13
%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
%31 = load float, float* %10
%32 = fpext float %31 to double
%33 = fmul double %18, %32
%34 = fptrunc double %33 to float
br label %35
35: ; preds = %17, %16
%36 = phi float [ %34, %17 ], [ 1.000000e+00, %16 ]
store float %36, float* %10
ret void
}