#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 rand_double();
void rand_array_i32(int *out, const unsigned int len, const int a,
                    const int b) {
  unsigned int i;
  double delta;
  int r;
  delta = (double)(b - a);
  for (i = 0; i < len; i++) {
    r = (int)(delta * rand_double());
    out[i] = a + r;
  }
}


x86 assembly (clang, -O0):
<rand_array_i32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1189 <rand_array_i32+0x79>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rand_double@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%edx
add    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113b <rand_array_i32+0x2b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_array_i32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     1150 <rand_array_i32+0x40>
mov    %edx,%r14d
mov    %rdi,%r15
sub    %edx,%ecx
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,(%rsp)
mov    %esi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <rand_double@plt>
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%eax
add    %r14d,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1130 <rand_array_i32+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @rand_array_i32(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = sub nsw i32 %12, %13
%15 = sitofp i32 %14 to double
store double %15, double* %10
store i32 0, i32* %9
br label %16
16: ; preds = %32, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %6
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load double, double* %10
%22 = call double (...) @rand_double()
%23 = fmul double %21, %22
%24 = fptosi double %23 to i32
store i32 %24, i32* %11
%25 = load i32, i32* %7
%26 = load i32, i32* %11
%27 = add nsw i32 %25, %26
%28 = load i32*, i32** %5
%29 = load i32, i32* %9
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %20
%33 = load i32, i32* %9
%34 = add i32 %33, 1
store i32 %34, i32* %9
br label %16
35: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @rand_array_i32(i32* nocapture writeonly %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %3, %2
%6 = sitofp i32 %5 to double
%7 = icmp eq i32 %1, 0
br i1 %7, label %19, label %8
8: ; preds = %4
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %17, %10 ]
%12 = tail call double (...) @rand_double()
%13 = fmul double %12, %6
%14 = fptosi double %13 to i32
%15 = add nsw i32 %14, %2
%16 = getelementptr inbounds i32, i32* %0, i64 %11
store i32 %15, i32* %16
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %9
br i1 %18, label %19, label %10
19: ; preds = %10, %4
ret void
}