#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 _stdnormrnd();
double *calloc(unsigned int, int);
int /*<<< orphan*/ error(char *);
double *normrnd(unsigned n, double mu, double sig) {
  if (sig <= 0)
    error("Parameter sig has to be larger than 0.");
  double *arr = calloc(n, sizeof(double));
  for (int i = 0; i < n; i++) {
    arr[i] = mu + _stdnormrnd() * sig;
  }
  return arr;
}


x86 assembly (clang, -O0):
<normrnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     115f <normrnd+0x2f>
lea    0xea6(%rip),%rdi
call   1050 <error@plt>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11c1 <normrnd+0x91>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <_stdnormrnd@plt>
movsd  -0x30(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1177 <normrnd+0x47>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normrnd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,(%rsp)
mov    %edi,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm1,0x8(%rsp)
ucomisd %xmm1,%xmm0
jb     115b <normrnd+0x2b>
lea    0xeaa(%rip),%rdi
call   1050 <error@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
je     11a9 <normrnd+0x79>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <_stdnormrnd@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <normrnd+0x50>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Parameter sig has to be larger than 0.\00"
define double* @normrnd(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
%9 = load double, double* %6
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = load i32, i32* %4
%15 = call double* @calloc(i32 %14, i32 8)
store double* %15, double** %7
store i32 0, i32* %8
br label %16
16: ; preds = %29, %13
%17 = load i32, i32* %8
%18 = load i32, i32* %4
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load double, double* %5
%22 = call double (...) @_stdnormrnd()
%23 = load double, double* %6
%24 = call double @llvm.fmuladd.f64(double %22, double %23, double %21)
%25 = load double*, double** %7
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
store double %24, double* %28
br label %29
29: ; preds = %20
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %16
32: ; preds = %16
%33 = load double*, double** %7
ret double* %33
}

LLVM IR (-O2):
@.str = [39 x i8] c"Parameter sig has to be larger than 0.\00"
define noalias double* @normrnd(i32 %0, double %1, double %2) {
%4 = fcmp ugt double %2, 0.000000e+00
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = tail call double* @calloc(i32 %0, i32 8)
%9 = icmp eq i32 %0, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = zext i32 %0 to i64
br label %13
12: ; preds = %13, %7
ret double* %8
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %18, %13 ]
%15 = tail call double (...) @_stdnormrnd()
%16 = tail call double @llvm.fmuladd.f64(double %15, double %2, double %1)
%17 = getelementptr inbounds double, double* %8, i64 %14
store double %16, double* %17
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %12, label %13
}