#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 doubles_magnitude(const double *v, int len) {
  double acc = 0;
  for (int i = 0; i < len; i++)
    acc += v[i] * v[i];
  return sqrt(acc);
}


x86 assembly (clang, -O0):
<doubles_magnitude>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1174 <doubles_magnitude+0x64>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%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    112e <doubles_magnitude+0x1e>
movsd  -0x18(%rbp),%xmm0
call   1030 <sqrt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_magnitude>:
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
test   %esi,%esi
jle    11b6 <doubles_magnitude+0xa6>
mov    %esi,%ecx
lea    -0x1(%rcx),%rdx
mov    %ecx,%eax
and    $0x3,%eax
cmp    $0x3,%rdx
jae    1139 <doubles_magnitude+0x29>
xorpd  %xmm0,%xmm0
xor    %edx,%edx
jmp    1190 <doubles_magnitude+0x80>
and    $0xfffffffc,%ecx
xorpd  %xmm0,%xmm0
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rdi,%rdx,8),%xmm2
movsd  0x8(%rdi,%rdx,8),%xmm3
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
movsd  0x10(%rdi,%rdx,8),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm3,%xmm2
movsd  0x18(%rdi,%rdx,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    1150 <doubles_magnitude+0x40>
test   %rax,%rax
je     11b6 <doubles_magnitude+0xa6>
lea    (%rdi,%rdx,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    11a0 <doubles_magnitude+0x90>
ucomisd %xmm1,%xmm0
jb     11c1 <doubles_magnitude+0xb1>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

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

LLVM IR (-O2):
define double @doubles_magnitude(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = add nsw i64 %5, -1
%7 = and i64 %5, 3
%8 = icmp ult i64 %6, 3
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = and i64 %5, 4294967292
br label %29
11: ; preds = %29, %4
%12 = phi double [ undef, %4 ], [ %47, %29 ]
%13 = phi i64 [ 0, %4 ], [ %48, %29 ]
%14 = phi double [ 0.000000e+00, %4 ], [ %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 nsw 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 nsw i64 %30, 4
%49 = add i64 %32, 4
%50 = icmp eq i64 %49, %10
br i1 %50, label %11, label %29
}