#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_MAX;
scalar_t__ rand();
void sampler_i(int n, int m, int *x) {
  int i;
  for (i = 0; i < m; i++)
    x[i] = (int)((double)rand() / RAND_MAX * (double)(n - 1));
}


x86 assembly (clang, -O0):
<sampler_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1177 <sampler_i+0x67>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2ea0(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <sampler_i+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sampler_i>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    116a <sampler_i+0x5a>
mov    %rdx,%r14
add    $0xffffffff,%edi
cvtsi2sd %edi,%xmm0
movsd  %xmm0,(%rsp)
mov    %esi,%r12d
mov    0x2eb3(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r15),%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <sampler_i+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define void @sampler_i(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %26, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load double, double* @RAND_MAX
%16 = fdiv double %14, %15
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = sitofp i32 %18 to double
%20 = fmul double %16, %19
%21 = fptosi double %20 to i32
%22 = load i32*, i32** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
br label %26
26: ; preds = %12
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %8
29: ; preds = %8
ret void
}

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