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


x86 assembly (clang, -O0):
<unifrnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1175 <unifrnd+0x35>
lea    0xe90(%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    11df <unifrnd+0x9f>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e3c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1040 <unifinv@plt>
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    118d <unifrnd+0x4d>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unifrnd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
ucomisd %xmm1,%xmm0
jbe    116a <unifrnd+0x2a>
lea    0xe9b(%rip),%rdi
call   1050 <error@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
je     11cb <unifrnd+0x8b>
mov    %ebp,%ebp
mov    0x2e62(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1040 <unifinv@plt>
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <unifrnd+0x50>
mov    %r15,%rax
add    $0x18,%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* @unifrnd(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 = load double, double* %5
%11 = fcmp olt double %9, %10
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
%15 = load i32, i32* %4
%16 = call double* @calloc(i32 %15, i32 8)
store double* %16, double** %7
store i32 0, i32* %8
br label %17
17: ; preds = %34, %14
%18 = load i32, i32* %8
%19 = load i32, i32* %4
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %37
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* %5
%28 = load double, double* %6
%29 = call double @unifinv(double %26, double %27, double %28)
%30 = load double*, double** %7
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %21
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %17
37: ; preds = %17
%38 = load double*, double** %7
ret double* %38
}

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