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


x86 assembly (clang, -O0):
<geomrnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    1175 <geomrnd+0x35>
movsd  -0x10(%rbp),%xmm0
movsd  0xe95(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1181 <geomrnd+0x41>
lea    0xe8c(%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    11e6 <geomrnd+0xa6>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e30(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <geominv@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    1199 <geomrnd+0x59>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geomrnd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
jae    1162 <geomrnd+0x22>
ucomisd 0xea0(%rip),%xmm0
jbe    116e <geomrnd+0x2e>
lea    0xe9f(%rip),%rdi
call   1050 <error@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
je     11c4 <geomrnd+0x84>
mov    %ebp,%ebp
mov    0x2e5e(%rip),%r14
xor    %ebx,%ebx
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 <geominv@plt>
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <geomrnd+0x50>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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