#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 */
scalar_t__ RAND_MAX;
double *calloc(unsigned int, int);
int /*<<< orphan*/ error(char *);
double expinv(double, double);
scalar_t__ rand();
double *exprnd(unsigned n, double lambda) {
  if (lambda < 0)
    error("Parameter b is smaller than a.");
  double *arr = calloc(n, sizeof(double));
  for (int i = 0; i < n; i++) {
    arr[i] = expinv((double)rand() / (double)RAND_MAX, lambda);
  }
  return arr;
}


x86 assembly (clang, -O0):
<exprnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    116a <exprnd+0x2a>
lea    0xe9b(%rip),%rdi
call   1050 <error@plt>
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11cf <exprnd+0x8f>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e47(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <expinv@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1182 <exprnd+0x42>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exprnd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
xorpd  %xmm1,%xmm1
movsd  %xmm0,(%rsp)
ucomisd %xmm0,%xmm1
jbe    1164 <exprnd+0x24>
lea    0xea1(%rip),%rdi
call   1050 <error@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
je     11c4 <exprnd+0x84>
mov    %ebp,%ebp
mov    0x2e68(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
movsd  (%rsp),%xmm1
call   1030 <expinv@plt>
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <exprnd+0x50>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Parameter b is smaller than a.\00"
@RAND_MAX = global i64 0
define double* @exprnd(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double*
%6 = alloca i32
store i32 %0, i32* %3
store double %1, double* %4
%7 = load double, double* %4
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* %3
%13 = call double* @calloc(i32 %12, i32 8)
store double* %13, double** %5
store i32 0, i32* %6
br label %14
14: ; preds = %30, %11
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to double
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to double
%23 = fdiv double %20, %22
%24 = load double, double* %4
%25 = call double @expinv(double %23, double %24)
%26 = load double*, double** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
br label %30
30: ; preds = %18
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %14
33: ; preds = %14
%34 = load double*, double** %5
ret double* %34
}

LLVM IR (-O2):
@.str = [31 x i8] c"Parameter b is smaller than a.\00"
@RAND_MAX = global i64 0
define noalias double* @exprnd(i32 %0, double %1) {
%3 = fcmp olt double %1, 0.000000e+00
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = tail call double* @calloc(i32 %0, i32 8)
%8 = icmp eq i32 %0, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = zext i32 %0 to i64
br label %12
11: ; preds = %12, %6
ret double* %7
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %21, %12 ]
%14 = tail call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to double
%18 = fdiv double %15, %17
%19 = tail call double @expinv(double %18, double %1)
%20 = getelementptr inbounds double, double* %7, i64 %13
store double %19, double* %20
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %11, label %12
}