#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 fabs(double const);
double sqrt(int);
double geom_norm2d(const double v[2]) {
  double x = fabs(v[0]);
  double y = fabs(v[1]);
  if (x <= y) {
    if (0. == x) {
      return y;
    }
    x /= y;
    return y * sqrt(1 + x * x);
  } else {
    y /= x;
    return x * sqrt(1 + y * y);
  }
}


x86 assembly (clang, -O0):
<geom_norm2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xed5(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movaps 0xebc(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11da <geom_norm2d+0xca>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1184 <geom_norm2d+0x74>
jp     1184 <geom_norm2d+0x74>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122b <geom_norm2d+0x11b>
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe59(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122b <geom_norm2d+0x11b>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe03(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_norm2d>:
sub    $0x18,%rsp
movdqu (%rdi),%xmm1
movdqa 0xee0(%rip),%xmm3
pand   %xmm1,%xmm3
pshufd $0xee,%xmm3,%xmm0
ucomisd %xmm3,%xmm0
jae    114e <geom_norm2d+0x3e>
movapd %xmm3,%xmm1
divsd  %xmm3,%xmm0
mulsd  %xmm0,%xmm0
addsd  0xecd(%rip),%xmm0
movapd %xmm0,%xmm3
movapd %xmm1,(%rsp)
jmp    1173 <geom_norm2d+0x63>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    115f <geom_norm2d+0x4f>
jp     115f <geom_norm2d+0x4f>
add    $0x18,%rsp
ret
divsd  %xmm0,%xmm3
mulsd  %xmm3,%xmm3
addsd  0xea1(%rip),%xmm3
movaps %xmm0,(%rsp)
cvttsd2si %xmm3,%edi
call   1030 <sqrt@plt>
movapd (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

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

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