void test_random(length) {
  int i = 0;
  int r = 0;
  int *array;
  array = malloc(length * sizeof(int));
  memset(array, 0, length * sizeof(int));
  int iterations = 1800000;
  while (i < iterations) {
    r = randomInRange(0, length - 1);
    array[r]++;
    i++;
  }
  printf("Random generation test needs to be built with DEBUG=y to see o/p\n");
  printArray(array, length);
}


x86 assembly (clang, -O0):
<test_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0x4(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x4(%rbp),%rdx
shl    $0x2,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x1b7740,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d1 <test_random+0x81>
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
xor    %edi,%edi
mov    $0x0,%al
call   1060 <randomInRange@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1194 <test_random+0x44>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1070 <printArray@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_random>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
movslq %edi,%rbp
lea    0x0(,%rbp,4),%rsi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,%r15
add    $0xffffffff,%ebp
mov    $0x1b7740,%ebx
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <randomInRange@plt>
cltq
addl   $0x1,(%r15,%rax,4)
add    $0xffffffff,%ebx
jne    1170 <test_random+0x30>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printArray@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"Random generation test needs to be built with DEBUG=y to see o/p\0A\00"
define void @test_random(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = call i8* @malloc(i64 %9)
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = bitcast i32* %12 to i8*
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
store i32 1800000, i32* %6
br label %17
17: ; preds = %21, %1
%18 = load i32, i32* %3
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i32, i32* %2
%23 = sub nsw i32 %22, 1
%24 = call i32 (i32, i32, ...) bitcast (i32 (...)* @randomInRange to i32 (i32, i32, ...)*)(i32 0, i32 %23)
store i32 %24, i32* %4
%25 = load i32*, i32** %5
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
store i32 %30, i32* %28
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %17
33: ; preds = %17
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%35 = load i32*, i32** %5
%36 = load i32, i32* %2
%37 = call i32 (i32*, i32, ...) bitcast (i32 (...)* @printArray to i32 (i32*, i32, ...)*)(i32* %35, i32 %36)
ret void
}

LLVM IR (-O2):
@str = [65 x i8] c"Random generation test needs to be built with DEBUG=y to see o/p\00"
define void @test_random(i32 %0) {
%2 = sext i32 %0 to i64
%3 = shl nsw i64 %2, 2
%4 = call i8* @calloc(i64 1, i64 %3)
%5 = bitcast i8* %4 to i32*
%6 = add nsw i32 %0, -1
br label %7
7: ; preds = %1, %7
%8 = phi i32 [ 0, %1 ], [ %14, %7 ]
%9 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @randomInRange to i32 (i32, i32, ...)*)(i32 0, i32 %6)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %5, i64 %10
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
store i32 %13, i32* %11
%14 = add nuw nsw i32 %8, 1
%15 = icmp eq i32 %14, 1800000
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 (i32*, i32, ...) bitcast (i32 (...)* @printArray to i32 (i32*, i32, ...)*)(i32* %5, i32 %0)
ret void
}