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


x86 assembly (clang, -O0):
<geom_norm4d>:
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)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
movaps 0xe8a(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11a3 <geom_norm4d+0x93>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11bd <geom_norm4d+0xad>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11d7 <geom_norm4d+0xc7>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jne    1209 <geom_norm4d+0xf9>
jp     1209 <geom_norm4d+0xf9>
movsd  -0x30(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ae <geom_norm4d+0x19e>
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  -0x38(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%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_norm4d>:
sub    $0x18,%rsp
movdqu (%rdi),%xmm1
movdqa 0xee0(%rip),%xmm3
pand   %xmm3,%xmm1
movq   0x10(%rdi),%xmm2
pand   %xmm3,%xmm2
movq   0x18(%rdi),%xmm0
pand   %xmm3,%xmm0
pshufd $0xee,%xmm1,%xmm3
movdqa %xmm3,%xmm4
maxsd  %xmm1,%xmm4
movdqa %xmm2,%xmm5
maxsd  %xmm4,%xmm5
movdqa %xmm0,%xmm6
maxsd  %xmm5,%xmm6
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm6
jne    1171 <geom_norm4d+0x61>
jp     1171 <geom_norm4d+0x61>
addsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm6
jmp    11bc <geom_norm4d+0xac>
divsd  %xmm6,%xmm1
divsd  %xmm6,%xmm3
divsd  %xmm6,%xmm2
divsd  %xmm6,%xmm0
mulsd  %xmm3,%xmm3
mulsd  %xmm1,%xmm1
addsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm4,%xmm0
jb     11a9 <geom_norm4d+0x99>
sqrtsd %xmm0,%xmm0
jmp    11b8 <geom_norm4d+0xa8>
movapd %xmm6,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm6
mulsd  %xmm0,%xmm6
movapd %xmm6,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @geom_norm4d(double* %0) {
%2 = alloca double
%3 = alloca double*
%4 = alloca [4 x double]
%5 = alloca double
store double* %0, double** %3
%6 = getelementptr inbounds [4 x double], [4 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 double, double* %16, i64 1
%22 = load double*, double** %3
%23 = getelementptr inbounds double, double* %22, i64 3
%24 = load double, double* %23
%25 = call double @llvm.fabs.f64(double %24)
store double %25, double* %21
%26 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%27 = load double, double* %26
store double %27, double* %5
%28 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%29 = load double, double* %28
%30 = load double, double* %5
%31 = fcmp ogt double %29, %30
br i1 %31, label %32, label %35
32: ; preds = %1
%33 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%34 = load double, double* %33
store double %34, double* %5
br label %35
35: ; preds = %32, %1
%36 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%37 = load double, double* %36
%38 = load double, double* %5
%39 = fcmp ogt double %37, %38
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%42 = load double, double* %41
store double %42, double* %5
br label %43
43: ; preds = %40, %35
%44 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%45 = load double, double* %44
%46 = load double, double* %5
%47 = fcmp ogt double %45, %46
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%50 = load double, double* %49
store double %50, double* %5
br label %51
51: ; preds = %48, %43
%52 = load double, double* %5
%53 = fcmp oeq double 0.000000e+00, %52
br i1 %53, label %54, label %66
54: ; preds = %51
%55 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%56 = load double, double* %55
%57 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%58 = load double, double* %57
%59 = fadd double %56, %58
%60 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%61 = load double, double* %60
%62 = fadd double %59, %61
%63 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%64 = load double, double* %63
%65 = fadd double %62, %64
store double %65, double* %2
br label %107
66: ; preds = %51
%67 = load double, double* %5
%68 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%69 = load double, double* %68
%70 = fdiv double %69, %67
store double %70, double* %68
%71 = load double, double* %5
%72 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%73 = load double, double* %72
%74 = fdiv double %73, %71
store double %74, double* %72
%75 = load double, double* %5
%76 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%77 = load double, double* %76
%78 = fdiv double %77, %75
store double %78, double* %76
%79 = load double, double* %5
%80 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%81 = load double, double* %80
%82 = fdiv double %81, %79
store double %82, double* %80
%83 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%84 = load double, double* %83
%85 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%86 = load double, double* %85
%87 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%88 = load double, double* %87
%89 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%90 = load double, double* %89
%91 = fmul double %88, %90
%92 = call double @llvm.fmuladd.f64(double %84, double %86, double %91)
%93 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%94 = load double, double* %93
%95 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%96 = load double, double* %95
%97 = call double @llvm.fmuladd.f64(double %94, double %96, double %92)
%98 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%99 = load double, double* %98
%100 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 3
%101 = load double, double* %100
%102 = call double @llvm.fmuladd.f64(double %99, double %101, double %97)
%103 = call double @sqrt(double %102)
%104 = load double, double* %5
%105 = fmul double %104, %103
store double %105, double* %5
%106 = load double, double* %5
store double %106, double* %2
br label %107
107: ; preds = %66, %54
%108 = load double, double* %2
ret double %108
}

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