#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 snorm();
void sample_NorMV(double *x, double *mu, double si2, int lo, int hi) {
  int i;
  double s = 0;
  for (i = 0; i <= hi - lo; i++) {
    x[i] = si2 * snorm() + mu[i];
    s = s + x[i];
  }
  x[hi - lo + 1] = s;
}


x86 assembly (clang, -O0):
<sample_NorMV>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jg     11ab <sample_NorMV+0x9b>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <snorm@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113a <sample_NorMV+0x2a>
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sample_NorMV>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdi,%r15
sub    %edx,%r14d
js     1180 <sample_NorMV+0x70>
movapd %xmm0,%xmm1
mov    %rsi,%r12
lea    0x1(%r14),%r13d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
nop
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <snorm@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  (%r12,%rbx,8),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <sample_NorMV+0x30>
jmp    1184 <sample_NorMV+0x74>
xorpd  %xmm0,%xmm0
movslq %r14d,%rax
movsd  %xmm0,0x8(%r15,%rax,8)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sample_NorMV(double* %0, double* %1, double %2, i32 %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double %2, double* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store double 0.000000e+00, double* %12
store i32 0, i32* %11
br label %13
13: ; preds = %39, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %10
%16 = load i32, i32* %9
%17 = sub nsw i32 %15, %16
%18 = icmp sle i32 %14, %17
br i1 %18, label %19, label %42
19: ; preds = %13
%20 = load double, double* %8
%21 = call double (...) @snorm()
%22 = load double*, double** %7
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = call double @llvm.fmuladd.f64(double %20, double %21, double %26)
%28 = load double*, double** %6
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
store double %27, double* %31
%32 = load double, double* %12
%33 = load double*, double** %6
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = fadd double %32, %37
store double %38, double* %12
br label %39
39: ; preds = %19
%40 = load i32, i32* %11
%41 = add nsw i32 %40, 1
store i32 %41, i32* %11
br label %13
42: ; preds = %13
%43 = load double, double* %12
%44 = load double*, double** %6
%45 = load i32, i32* %10
%46 = load i32, i32* %9
%47 = sub nsw i32 %45, %46
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %44, i64 %49
store double %43, double* %50
ret void
}

LLVM IR (-O2):
define void @sample_NorMV(double* nocapture writeonly %0, double* nocapture %1, double %2, i32 %3, i32 %4) {
%6 = sub nsw i32 %4, %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = add i32 %4, 1
%10 = sub i32 %9, %3
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %8, %12
%13 = phi i64 [ 0, %8 ], [ %21, %12 ]
%14 = phi double [ 0.000000e+00, %8 ], [ %20, %12 ]
%15 = tail call double (...) @snorm()
%16 = getelementptr inbounds double, double* %1, i64 %13
%17 = load double, double* %16
%18 = tail call double @llvm.fmuladd.f64(double %2, double %15, double %17)
%19 = getelementptr inbounds double, double* %0, i64 %13
store double %18, double* %19
%20 = fadd double %14, %18
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %12, %5
%24 = phi double [ 0.000000e+00, %5 ], [ %20, %12 ]
%25 = add nsw i32 %6, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %0, i64 %26
store double %24, double* %27
ret void
}