#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 fabsf(float const);
float sqrtf(int);
float geom_norm2f(const float v[2]) {
  float x = fabsf(v[0]);
  float y = fabsf(v[1]);
  if (x <= y) {
    if (0.f == x) {
      return y;
    }
    x /= y;
    return y * sqrtf(1 + x * x);
  } else {
    y /= x;
    return x * sqrtf(1 + y * y);
  }
}


x86 assembly (clang, -O0):
<geom_norm2f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movaps 0xed5(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
movaps 0xebc(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11d8 <geom_norm2f+0xc8>
xorps  %xmm0,%xmm0
ucomiss -0x14(%rbp),%xmm0
jne    1182 <geom_norm2f+0x72>
jp     1182 <geom_norm2f+0x72>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1229 <geom_norm2f+0x119>
movss  -0x18(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xe5b(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1030 <sqrtf@plt>
movaps %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1229 <geom_norm2f+0x119>
movss  -0x14(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  0xe05(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1030 <sqrtf@plt>
movaps %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_norm2f>:
sub    $0x18,%rsp
movq   (%rdi),%xmm1
movdqa 0xee0(%rip),%xmm3
pand   %xmm1,%xmm3
pshufd $0x55,%xmm3,%xmm0
ucomiss %xmm3,%xmm0
jae    114a <geom_norm2f+0x3a>
movaps %xmm3,%xmm1
divss  %xmm3,%xmm0
mulss  %xmm0,%xmm0
addss  0xecf(%rip),%xmm0
movaps %xmm0,%xmm3
movaps %xmm1,(%rsp)
jmp    116d <geom_norm2f+0x5d>
xorps  %xmm2,%xmm2
ucomiss %xmm2,%xmm1
jne    1159 <geom_norm2f+0x49>
jp     1159 <geom_norm2f+0x49>
add    $0x18,%rsp
ret
divss  %xmm0,%xmm3
mulss  %xmm3,%xmm3
addss  0xea7(%rip),%xmm3
movaps %xmm0,(%rsp)
cvttss2si %xmm3,%edi
call   1030 <sqrtf@plt>
movaps (%rsp),%xmm1
mulss  %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @geom_norm2f(float* %0) {
%2 = alloca float
%3 = alloca float*
%4 = alloca float
%5 = alloca float
store float* %0, float** %3
%6 = load float*, float** %3
%7 = getelementptr inbounds float, float* %6, i64 0
%8 = load float, float* %7
%9 = call float @llvm.fabs.f32(float %8)
store float %9, float* %4
%10 = load float*, float** %3
%11 = getelementptr inbounds float, float* %10, i64 1
%12 = load float, float* %11
%13 = call float @llvm.fabs.f32(float %12)
store float %13, float* %5
%14 = load float, float* %4
%15 = load float, float* %5
%16 = fcmp ole float %14, %15
br i1 %16, label %17, label %33
17: ; preds = %1
%18 = load float, float* %4
%19 = fcmp oeq float 0.000000e+00, %18
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load float, float* %5
store float %21, float* %2
br label %44
22: ; preds = %17
%23 = load float, float* %5
%24 = load float, float* %4
%25 = fdiv float %24, %23
store float %25, float* %4
%26 = load float, float* %5
%27 = load float, float* %4
%28 = load float, float* %4
%29 = call float @llvm.fmuladd.f32(float %27, float %28, float 1.000000e+00)
%30 = fptosi float %29 to i32
%31 = call float @sqrtf(i32 %30)
%32 = fmul float %26, %31
store float %32, float* %2
br label %44
33: ; preds = %1
%34 = load float, float* %4
%35 = load float, float* %5
%36 = fdiv float %35, %34
store float %36, float* %5
%37 = load float, float* %4
%38 = load float, float* %5
%39 = load float, float* %5
%40 = call float @llvm.fmuladd.f32(float %38, float %39, float 1.000000e+00)
%41 = fptosi float %40 to i32
%42 = call float @sqrtf(i32 %41)
%43 = fmul float %37, %42
store float %43, float* %2
br label %44
44: ; preds = %33, %22, %20
%45 = load float, float* %2
ret float %45
}

LLVM IR (-O2):
define float @geom_norm2f(float* nocapture %0) {
%2 = bitcast float* %0 to <2 x float>*
%3 = load <2 x float>, <2 x float>* %2
%4 = call <2 x float> @llvm.fabs.v2f32(<2 x float> %3)
%5 = extractelement <2 x float> %4, i64 0
%6 = extractelement <2 x float> %4, i64 1
%7 = fcmp ugt float %5, %6
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = extractelement <2 x float> %3, i64 0
%10 = fcmp oeq float %9, 0.000000e+00
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = fdiv float %5, %6
%13 = tail call float @llvm.fmuladd.f32(float %12, float %12, float 1.000000e+00)
br label %17
14: ; preds = %1
%15 = fdiv float %6, %5
%16 = tail call float @llvm.fmuladd.f32(float %15, float %15, float 1.000000e+00)
br label %17
17: ; preds = %11, %14
%18 = phi float [ %16, %14 ], [ %13, %11 ]
%19 = phi float [ %5, %14 ], [ %6, %11 ]
%20 = fptosi float %18 to i32
%21 = tail call float @sqrtf(i32 %20)
%22 = fmul float %19, %21
br label %23
23: ; preds = %17, %8
%24 = phi float [ %6, %8 ], [ %22, %17 ]
ret float %24
}