#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 */
float glmComputeQuaternionMagnitudef(float *);
float glmNormalizeQuaternionf(float q[4]) {
  float m = glmComputeQuaternionMagnitudef(q);
  if (m != 0) {
    q[0] /= m;
    q[1] /= m;
    q[2] /= m;
    q[3] /= m;
  }
  return m;
}


x86 assembly (clang, -O0):
<glmNormalizeQuaternionf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <glmComputeQuaternionMagnitudef@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1146 <glmNormalizeQuaternionf+0x36>
jp     1146 <glmNormalizeQuaternionf+0x36>
jmp    11a0 <glmNormalizeQuaternionf+0x90>
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0x4(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x4(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0x8(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0x8(%rax)
movss  -0xc(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movss  0xc(%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,0xc(%rax)
movss  -0xc(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmNormalizeQuaternionf>:
push   %rbx
mov    %rdi,%rbx
call   1030 <glmComputeQuaternionMagnitudef@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1123 <glmNormalizeQuaternionf+0x13>
jnp    1133 <glmNormalizeQuaternionf+0x23>
movups (%rbx),%xmm1
movaps %xmm0,%xmm2
shufps $0x0,%xmm0,%xmm2
divps  %xmm2,%xmm1
movups %xmm1,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define float @glmNormalizeQuaternionf(float* %0) {
%2 = alloca float*
%3 = alloca float
store float* %0, float** %2
%4 = load float*, float** %2
%5 = call float @glmComputeQuaternionMagnitudef(float* %4)
store float %5, float* %3
%6 = load float, float* %3
%7 = fcmp une float %6, 0.000000e+00
br i1 %7, label %8, label %29
8: ; preds = %1
%9 = load float, float* %3
%10 = load float*, float** %2
%11 = getelementptr inbounds float, float* %10, i64 0
%12 = load float, float* %11
%13 = fdiv float %12, %9
store float %13, float* %11
%14 = load float, float* %3
%15 = load float*, float** %2
%16 = getelementptr inbounds float, float* %15, i64 1
%17 = load float, float* %16
%18 = fdiv float %17, %14
store float %18, float* %16
%19 = load float, float* %3
%20 = load float*, float** %2
%21 = getelementptr inbounds float, float* %20, i64 2
%22 = load float, float* %21
%23 = fdiv float %22, %19
store float %23, float* %21
%24 = load float, float* %3
%25 = load float*, float** %2
%26 = getelementptr inbounds float, float* %25, i64 3
%27 = load float, float* %26
%28 = fdiv float %27, %24
store float %28, float* %26
br label %29
29: ; preds = %8, %1
%30 = load float, float* %3
ret float %30
}

LLVM IR (-O2):
define float @glmNormalizeQuaternionf(float* %0) {
%2 = tail call float @glmComputeQuaternionMagnitudef(float* %0)
%3 = fcmp une float %2, 0.000000e+00
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = bitcast float* %0 to <4 x float>*
%6 = load <4 x float>, <4 x float>* %5
%7 = insertelement <4 x float> poison, float %2, i64 0
%8 = shufflevector <4 x float> %7, <4 x float> poison, <4 x i32> zeroinitializer
%9 = fdiv <4 x float> %6, %8
%10 = bitcast float* %0 to <4 x float>*
store <4 x float> %9, <4 x float>* %10
br label %11
11: ; preds = %4, %1
ret float %2
}