#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 sqrt(double);
double euclideanNorm(int m, double **v) {
  double squareOfMagnitude = 0;
  int j = 0;
  for (j = 0; j < m; j++) {
    squareOfMagnitude += v[j][0] * v[j][0];
  }
  return sqrt(squareOfMagnitude);
}


x86 assembly (clang, -O0):
<euclideanNorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1181 <euclideanNorm+0x71>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  (%rax),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <euclideanNorm+0x25>
movsd  -0x18(%rbp),%xmm0
call   1030 <sqrt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euclideanNorm>:
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %edi,%edi
jle    11c9 <euclideanNorm+0xb9>
mov    %edi,%ecx
lea    -0x1(%rcx),%rdx
mov    %ecx,%r8d
and    $0x3,%r8d
cmp    $0x3,%rdx
jae    113b <euclideanNorm+0x2b>
xorpd  %xmm0,%xmm0
xor    %edx,%edx
jmp    119c <euclideanNorm+0x8c>
and    $0xfffffffc,%ecx
xorpd  %xmm0,%xmm0
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsi,%rdx,8),%rdi
mov    0x8(%rsi,%rdx,8),%rax
movsd  (%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  (%rax),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
mov    0x10(%rsi,%rdx,8),%rax
movsd  (%rax),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mov    0x18(%rsi,%rdx,8),%rax
movsd  (%rax),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    1150 <euclideanNorm+0x40>
test   %r8,%r8
je     11c9 <euclideanNorm+0xb9>
lea    (%rsi,%rdx,8),%rcx
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
mov    (%rcx,%rdx,8),%rax
movsd  (%rax),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%rdx
cmp    %rdx,%r8
jne    11b0 <euclideanNorm+0xa0>
ucomisd %xmm1,%xmm0
jb     11d4 <euclideanNorm+0xc4>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
define double @euclideanNorm(i32 %0, double** %1) {
%3 = alloca i32
%4 = alloca double**
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
store double** %1, double*** %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
store i32 0, i32* %6
br label %7
7: ; preds = %28, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load double**, double*** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double*, double** %12, i64 %14
%16 = load double*, double** %15
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
%19 = load double**, double*** %4
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double*, double** %19, i64 %21
%23 = load double*, double** %22
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = load double, double* %5
%27 = call double @llvm.fmuladd.f64(double %18, double %25, double %26)
store double %27, double* %5
br label %28
28: ; preds = %11
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %7
31: ; preds = %7
%32 = load double, double* %5
%33 = call double @sqrt(double %32)
ret double %33
}

LLVM IR (-O2):
define double @euclideanNorm(i32 %0, double** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %53
4: ; preds = %2
%5 = zext i32 %0 to i64
%6 = add nsw i64 %5, -1
%7 = and i64 %5, 3
%8 = icmp ult i64 %6, 3
br i1 %8, label %37, label %9
9: ; preds = %4
%10 = and i64 %5, 4294967292
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %34, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %33, %11 ]
%14 = phi i64 [ 0, %9 ], [ %35, %11 ]
%15 = getelementptr inbounds double*, double** %1, i64 %12
%16 = load double*, double** %15
%17 = load double, double* %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %13)
%19 = or i64 %12, 1
%20 = getelementptr inbounds double*, double** %1, i64 %19
%21 = load double*, double** %20
%22 = load double, double* %21
%23 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %18)
%24 = or i64 %12, 2
%25 = getelementptr inbounds double*, double** %1, i64 %24
%26 = load double*, double** %25
%27 = load double, double* %26
%28 = tail call double @llvm.fmuladd.f64(double %27, double %27, double %23)
%29 = or i64 %12, 3
%30 = getelementptr inbounds double*, double** %1, i64 %29
%31 = load double*, double** %30
%32 = load double, double* %31
%33 = tail call double @llvm.fmuladd.f64(double %32, double %32, double %28)
%34 = add nuw nsw i64 %12, 4
%35 = add i64 %14, 4
%36 = icmp eq i64 %35, %10
br i1 %36, label %37, label %11
37: ; preds = %11, %4
%38 = phi double [ undef, %4 ], [ %33, %11 ]
%39 = phi i64 [ 0, %4 ], [ %34, %11 ]
%40 = phi double [ 0.000000e+00, %4 ], [ %33, %11 ]
%41 = icmp eq i64 %7, 0
br i1 %41, label %53, label %42
42: ; preds = %37, %42
%43 = phi i64 [ %50, %42 ], [ %39, %37 ]
%44 = phi double [ %49, %42 ], [ %40, %37 ]
%45 = phi i64 [ %51, %42 ], [ 0, %37 ]
%46 = getelementptr inbounds double*, double** %1, i64 %43
%47 = load double*, double** %46
%48 = load double, double* %47
%49 = tail call double @llvm.fmuladd.f64(double %48, double %48, double %44)
%50 = add nuw nsw i64 %43, 1
%51 = add i64 %45, 1
%52 = icmp eq i64 %51, %7
br i1 %52, label %53, label %42
53: ; preds = %37, %42, %2
%54 = phi double [ 0.000000e+00, %2 ], [ %38, %37 ], [ %49, %42 ]
%55 = tail call double @sqrt(double %54)
ret double %55
}