#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(double);
double geom_norm3d(const double v[3]) {
  double a[3] = {fabs(v[0]), fabs(v[1]), fabs(v[2])};
  double w = a[0];
  if (a[1] > w) {
    w = a[1];
  }
  if (a[2] > w) {
    w = a[2];
  }
  if (0 == w) {
    return a[0] + a[1] + a[2];
  } else {
    a[0] /= w;
    a[1] /= w;
    a[2] /= w;
    w *= sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
    return w;
  }
}


x86 assembly (clang, -O0):
<geom_norm3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movaps 0xed5(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movaps 0xebc(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movaps 0xea3(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    118a <geom_norm3d+0x7a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11a4 <geom_norm3d+0x94>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jne    11d1 <geom_norm3d+0xc1>
jp     11d1 <geom_norm3d+0xc1>
movsd  -0x30(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1251 <geom_norm3d+0x141>
movsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_norm3d>:
sub    $0x18,%rsp
movdqu (%rdi),%xmm1
movdqa 0xee0(%rip),%xmm2
pand   %xmm2,%xmm1
movq   0x10(%rdi),%xmm0
pand   %xmm2,%xmm0
pshufd $0xee,%xmm1,%xmm2
movdqa %xmm2,%xmm3
maxsd  %xmm1,%xmm3
movdqa %xmm0,%xmm4
maxsd  %xmm3,%xmm4
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm4
jne    115c <geom_norm3d+0x4c>
jp     115c <geom_norm3d+0x4c>
addsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm4
jmp    119b <geom_norm3d+0x8b>
divsd  %xmm4,%xmm1
divsd  %xmm4,%xmm2
divsd  %xmm4,%xmm0
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm3,%xmm0
jb     1188 <geom_norm3d+0x78>
sqrtsd %xmm0,%xmm0
jmp    1197 <geom_norm3d+0x87>
movapd %xmm4,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm4
mulsd  %xmm0,%xmm4
movapd %xmm4,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @geom_norm3d(double* %0) {
%2 = alloca double
%3 = alloca double*
%4 = alloca [3 x double]
%5 = alloca double
store double* %0, double** %3
%6 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%7 = load double*, double** %3
%8 = getelementptr inbounds double, double* %7, i64 0
%9 = load double, double* %8
%10 = call double @llvm.fabs.f64(double %9)
store double %10, double* %6
%11 = getelementptr inbounds double, double* %6, i64 1
%12 = load double*, double** %3
%13 = getelementptr inbounds double, double* %12, i64 1
%14 = load double, double* %13
%15 = call double @llvm.fabs.f64(double %14)
store double %15, double* %11
%16 = getelementptr inbounds double, double* %11, i64 1
%17 = load double*, double** %3
%18 = getelementptr inbounds double, double* %17, i64 2
%19 = load double, double* %18
%20 = call double @llvm.fabs.f64(double %19)
store double %20, double* %16
%21 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%22 = load double, double* %21
store double %22, double* %5
%23 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%24 = load double, double* %23
%25 = load double, double* %5
%26 = fcmp ogt double %24, %25
br i1 %26, label %27, label %30
27: ; preds = %1
%28 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%29 = load double, double* %28
store double %29, double* %5
br label %30
30: ; preds = %27, %1
%31 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%32 = load double, double* %31
%33 = load double, double* %5
%34 = fcmp ogt double %32, %33
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%37 = load double, double* %36
store double %37, double* %5
br label %38
38: ; preds = %35, %30
%39 = load double, double* %5
%40 = fcmp oeq double 0.000000e+00, %39
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%43 = load double, double* %42
%44 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%45 = load double, double* %44
%46 = fadd double %43, %45
%47 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%48 = load double, double* %47
%49 = fadd double %46, %48
store double %49, double* %2
br label %82
50: ; preds = %38
%51 = load double, double* %5
%52 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%53 = load double, double* %52
%54 = fdiv double %53, %51
store double %54, double* %52
%55 = load double, double* %5
%56 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%57 = load double, double* %56
%58 = fdiv double %57, %55
store double %58, double* %56
%59 = load double, double* %5
%60 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%61 = load double, double* %60
%62 = fdiv double %61, %59
store double %62, double* %60
%63 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%64 = load double, double* %63
%65 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%66 = load double, double* %65
%67 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%68 = load double, double* %67
%69 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%70 = load double, double* %69
%71 = fmul double %68, %70
%72 = call double @llvm.fmuladd.f64(double %64, double %66, double %71)
%73 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%74 = load double, double* %73
%75 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
%76 = load double, double* %75
%77 = call double @llvm.fmuladd.f64(double %74, double %76, double %72)
%78 = call double @sqrt(double %77)
%79 = load double, double* %5
%80 = fmul double %79, %78
store double %80, double* %5
%81 = load double, double* %5
store double %81, double* %2
br label %82
82: ; preds = %50, %41
%83 = load double, double* %2
ret double %83
}

LLVM IR (-O2):
define double @geom_norm3d(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 = getelementptr inbounds double, double* %0, i64 2
%6 = load double, double* %5
%7 = tail call double @llvm.fabs.f64(double %6)
%8 = extractelement <2 x double> %4, i64 0
%9 = extractelement <2 x double> %4, i64 1
%10 = fcmp ogt double %9, %8
%11 = select i1 %10, double %9, double %8
%12 = fcmp ogt double %7, %11
%13 = select i1 %12, double %7, double %11
%14 = fcmp oeq double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = fadd double %8, %9
%17 = fadd double %16, %7
br label %27
18: ; preds = %1
%19 = fdiv double %8, %13
%20 = fdiv double %9, %13
%21 = fdiv double %7, %13
%22 = fmul double %20, %20
%23 = tail call double @llvm.fmuladd.f64(double %19, double %19, double %22)
%24 = tail call double @llvm.fmuladd.f64(double %21, double %21, double %23)
%25 = tail call double @sqrt(double %24)
%26 = fmul double %13, %25
br label %27
27: ; preds = %18, %15
%28 = phi double [ %17, %15 ], [ %26, %18 ]
ret double %28
}