#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 Norm(double vecX[20]) {
  int i;
  double *p;
  double norm = 0.0;
  for (i = 0; i < 20; i++) {
    norm = norm + vecX[i] * vecX[i];
  }
  norm = sqrt(norm);
  p = &norm;
  return *p;
}


x86 assembly (clang, -O0):
<Norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jge    116f <Norm+0x5f>
movsd  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112b <Norm+0x1b>
movsd  -0x20(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Norm>:
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm2
mulsd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x10(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x18(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x20(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x28(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x30(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x38(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x40(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x48(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x50(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x58(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x60(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x68(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x70(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x78(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x80(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
movsd  0x88(%rdi),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x90(%rdi),%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
movsd  0x98(%rdi),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm3,%xmm0
ucomisd %xmm1,%xmm0
jb     122e <Norm+0x11e>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

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

LLVM IR (-O2):
define double @Norm(double* nocapture %0) {
%2 = load double, double* %0
%3 = tail call double @llvm.fmuladd.f64(double %2, double %2, double 0.000000e+00)
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %3)
%7 = getelementptr inbounds double, double* %0, i64 2
%8 = load double, double* %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %6)
%10 = getelementptr inbounds double, double* %0, i64 3
%11 = load double, double* %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %9)
%13 = getelementptr inbounds double, double* %0, i64 4
%14 = load double, double* %13
%15 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %12)
%16 = getelementptr inbounds double, double* %0, i64 5
%17 = load double, double* %16
%18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %15)
%19 = getelementptr inbounds double, double* %0, i64 6
%20 = load double, double* %19
%21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %18)
%22 = getelementptr inbounds double, double* %0, i64 7
%23 = load double, double* %22
%24 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %21)
%25 = getelementptr inbounds double, double* %0, i64 8
%26 = load double, double* %25
%27 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %24)
%28 = getelementptr inbounds double, double* %0, i64 9
%29 = load double, double* %28
%30 = tail call double @llvm.fmuladd.f64(double %29, double %29, double %27)
%31 = getelementptr inbounds double, double* %0, i64 10
%32 = load double, double* %31
%33 = tail call double @llvm.fmuladd.f64(double %32, double %32, double %30)
%34 = getelementptr inbounds double, double* %0, i64 11
%35 = load double, double* %34
%36 = tail call double @llvm.fmuladd.f64(double %35, double %35, double %33)
%37 = getelementptr inbounds double, double* %0, i64 12
%38 = load double, double* %37
%39 = tail call double @llvm.fmuladd.f64(double %38, double %38, double %36)
%40 = getelementptr inbounds double, double* %0, i64 13
%41 = load double, double* %40
%42 = tail call double @llvm.fmuladd.f64(double %41, double %41, double %39)
%43 = getelementptr inbounds double, double* %0, i64 14
%44 = load double, double* %43
%45 = tail call double @llvm.fmuladd.f64(double %44, double %44, double %42)
%46 = getelementptr inbounds double, double* %0, i64 15
%47 = load double, double* %46
%48 = tail call double @llvm.fmuladd.f64(double %47, double %47, double %45)
%49 = getelementptr inbounds double, double* %0, i64 16
%50 = load double, double* %49
%51 = tail call double @llvm.fmuladd.f64(double %50, double %50, double %48)
%52 = getelementptr inbounds double, double* %0, i64 17
%53 = load double, double* %52
%54 = tail call double @llvm.fmuladd.f64(double %53, double %53, double %51)
%55 = getelementptr inbounds double, double* %0, i64 18
%56 = load double, double* %55
%57 = tail call double @llvm.fmuladd.f64(double %56, double %56, double %54)
%58 = getelementptr inbounds double, double* %0, i64 19
%59 = load double, double* %58
%60 = tail call double @llvm.fmuladd.f64(double %59, double %59, double %57)
%61 = tail call double @sqrt(double %60)
ret double %61
}