#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 sqrt(double);
double glmNormalizeVector4d(double v[4]) {
  double length;
  length = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
  if (length > 0) {
    v[0] /= length;
    v[1] /= length;
    v[2] /= length;
    v[3] /= length;
  }
  return length;
}


x86 assembly (clang, -O0):
<glmNormalizeVector4d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11f0 <glmNormalizeVector4d+0xe0>
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):
<glmNormalizeVector4d>:
push   %rbx
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0x10(%rdi),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x18(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1159 <glmNormalizeVector4d+0x49>
sqrtsd %xmm0,%xmm0
ucomisd %xmm1,%xmm0
ja     1168 <glmNormalizeVector4d+0x58>
jmp    118a <glmNormalizeVector4d+0x7a>
call   1030 <sqrt@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    118a <glmNormalizeVector4d+0x7a>
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 @glmNormalizeVector4d(double* %0) {
%2 = alloca double*
%3 = alloca double
store double* %0, double** %2
%4 = load double*, double** %2
%5 = getelementptr inbounds double, double* %4, i64 0
%6 = load double, double* %5
%7 = load double*, double** %2
%8 = getelementptr inbounds double, double* %7, i64 0
%9 = load double, double* %8
%10 = load double*, double** %2
%11 = getelementptr inbounds double, double* %10, i64 1
%12 = load double, double* %11
%13 = load double*, double** %2
%14 = getelementptr inbounds double, double* %13, i64 1
%15 = load double, double* %14
%16 = fmul double %12, %15
%17 = call double @llvm.fmuladd.f64(double %6, double %9, double %16)
%18 = load double*, double** %2
%19 = getelementptr inbounds double, double* %18, i64 2
%20 = load double, double* %19
%21 = load double*, double** %2
%22 = getelementptr inbounds double, double* %21, i64 2
%23 = load double, double* %22
%24 = call double @llvm.fmuladd.f64(double %20, double %23, double %17)
%25 = load double*, double** %2
%26 = getelementptr inbounds double, double* %25, i64 3
%27 = load double, double* %26
%28 = load double*, double** %2
%29 = getelementptr inbounds double, double* %28, i64 3
%30 = load double, double* %29
%31 = call double @llvm.fmuladd.f64(double %27, double %30, double %24)
%32 = call double @sqrt(double %31)
store double %32, double* %3
%33 = load double, double* %3
%34 = fcmp ogt double %33, 0.000000e+00
br i1 %34, label %35, label %56
35: ; preds = %1
%36 = load double, double* %3
%37 = load double*, double** %2
%38 = getelementptr inbounds double, double* %37, i64 0
%39 = load double, double* %38
%40 = fdiv double %39, %36
store double %40, double* %38
%41 = load double, double* %3
%42 = load double*, double** %2
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = fdiv double %44, %41
store double %45, double* %43
%46 = load double, double* %3
%47 = load double*, double** %2
%48 = getelementptr inbounds double, double* %47, i64 2
%49 = load double, double* %48
%50 = fdiv double %49, %46
store double %50, double* %48
%51 = load double, double* %3
%52 = load double*, double** %2
%53 = getelementptr inbounds double, double* %52, i64 3
%54 = load double, double* %53
%55 = fdiv double %54, %51
store double %55, double* %53
br label %56
56: ; preds = %35, %1
%57 = load double, double* %3
ret double %57
}

LLVM IR (-O2):
define double @glmNormalizeVector4d(double* nocapture %0) {
%2 = load double, double* %0
%3 = getelementptr inbounds double, double* %0, i64 1
%4 = load double, double* %3
%5 = fmul double %4, %4
%6 = tail call double @llvm.fmuladd.f64(double %2, double %2, double %5)
%7 = getelementptr inbounds double, double* %0, i64 2
%8 = load double, double* %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %6)
%10 = getelementptr inbounds double, double* %0, i64 3
%11 = load double, double* %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %9)
%13 = tail call double @sqrt(double %12)
%14 = fcmp ogt double %13, 0.000000e+00
br i1 %14, label %15, label %26
15: ; preds = %1
%16 = bitcast double* %0 to <2 x double>*
%17 = load <2 x double>, <2 x double>* %16
%18 = insertelement <2 x double> poison, double %13, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = fdiv <2 x double> %17, %19
%21 = bitcast double* %0 to <2 x double>*
store <2 x double> %20, <2 x double>* %21
%22 = bitcast double* %7 to <2 x double>*
%23 = load <2 x double>, <2 x double>* %22
%24 = fdiv <2 x double> %23, %19
%25 = bitcast double* %7 to <2 x double>*
store <2 x double> %24, <2 x double>* %25
br label %26
26: ; preds = %15, %1
ret double %13
}