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


x86 assembly (clang, -O0):
<glmNormalizeQuaterniond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <glmComputeQuaternionMagnituded@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1147 <glmNormalizeQuaterniond+0x37>
jp     1147 <glmNormalizeQuaterniond+0x37>
jmp    11a1 <glmNormalizeQuaterniond+0x91>
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rax)
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rax)
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmNormalizeQuaterniond>:
push   %rbx
mov    %rdi,%rbx
call   1030 <glmComputeQuaternionMagnituded@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1125 <glmNormalizeQuaterniond+0x15>
jnp    1147 <glmNormalizeQuaterniond+0x37>
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
movupd (%rbx),%xmm2
movupd 0x10(%rbx),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rbx)
pop    %rbx
ret

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

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