#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 */
int /*<<< orphan*/ assert(double const *);
double sqrt(double);
double math_vector_norm(const double *vector, size_t size) {
  assert(vector);
  double norm = 0.0;
  for (size_t i = 0; i != size; ++i) {
    norm += vector[i] * vector[i];
  }
  return sqrt(norm);
}


x86 assembly (clang, -O0):
<math_vector_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1194 <math_vector_norm+0x74>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1149 <math_vector_norm+0x29>
movsd  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_vector_norm>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <assert@plt>
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %r14,%r14
je     11d6 <math_vector_norm+0xb6>
lea    -0x1(%r14),%rcx
mov    %r14d,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    1158 <math_vector_norm+0x38>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    11b0 <math_vector_norm+0x90>
and    $0xfffffffffffffffc,%r14
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rbx,%rcx,8),%xmm2
movsd  0x8(%rbx,%rcx,8),%xmm3
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
movsd  0x10(%rbx,%rcx,8),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm3,%xmm2
movsd  0x18(%rbx,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
add    $0x4,%rcx
cmp    %rcx,%r14
jne    1170 <math_vector_norm+0x50>
test   %rax,%rax
je     11d6 <math_vector_norm+0xb6>
lea    (%rbx,%rcx,8),%rcx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movsd  (%rcx,%rdx,8),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%rdx
cmp    %rdx,%rax
jne    11c0 <math_vector_norm+0xa0>
ucomisd %xmm1,%xmm0
jb     11e8 <math_vector_norm+0xc8>
sqrtsd %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sqrt@plt>

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

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