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


x86 assembly (clang, -O0):
<glmNormalizeVector2f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%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
call   1030 <sqrt@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    118d <glmNormalizeVector2f+0x7d>
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),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmNormalizeVector2f>:
push   %rbx
mov    %rdi,%rbx
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     113c <glmNormalizeVector2f+0x2c>
sqrtss %xmm0,%xmm0
ucomiss %xmm1,%xmm0
ja     1149 <glmNormalizeVector2f+0x39>
jmp    1163 <glmNormalizeVector2f+0x53>
call   1030 <sqrt@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1163 <glmNormalizeVector2f+0x53>
movss  (%rbx),%xmm1
movss  0x4(%rbx),%xmm2
divss  %xmm0,%xmm1
movss  %xmm1,(%rbx)
divss  %xmm0,%xmm2
movss  %xmm2,0x4(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define float @glmNormalizeVector2f(float* %0) {
%2 = alloca float*
%3 = alloca float
store float* %0, float** %2
%4 = load float*, float** %2
%5 = getelementptr inbounds float, float* %4, i64 0
%6 = load float, float* %5
%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 1
%12 = load float, float* %11
%13 = load float*, float** %2
%14 = getelementptr inbounds float, float* %13, i64 1
%15 = load float, float* %14
%16 = fmul float %12, %15
%17 = call float @llvm.fmuladd.f32(float %6, float %9, float %16)
%18 = call float @sqrt(float %17)
store float %18, float* %3
%19 = load float, float* %3
%20 = fcmp ogt float %19, 0.000000e+00
br i1 %20, label %21, label %32
21: ; preds = %1
%22 = load float, float* %3
%23 = load float*, float** %2
%24 = getelementptr inbounds float, float* %23, i64 0
%25 = load float, float* %24
%26 = fdiv float %25, %22
store float %26, float* %24
%27 = load float, float* %3
%28 = load float*, float** %2
%29 = getelementptr inbounds float, float* %28, i64 1
%30 = load float, float* %29
%31 = fdiv float %30, %27
store float %31, float* %29
br label %32
32: ; preds = %21, %1
%33 = load float, float* %3
ret float %33
}

LLVM IR (-O2):
define float @glmNormalizeVector2f(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 = tail call float @sqrt(float %6)
%8 = fcmp ogt float %7, 0.000000e+00
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load float, float* %0
%11 = fdiv float %10, %7
store float %11, float* %0
%12 = load float, float* %3
%13 = fdiv float %12, %7
store float %13, float* %3
br label %14
14: ; preds = %9, %1
ret float %7
}