#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 */
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int *);
int *malloc(int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *make_random_r(size_t m, size_t n) {
  int i, j;
  int *r;
  time_t curr;
  assert(r = malloc(sizeof(int) * m * n));
  curr = time(NULL);
  srand(curr);
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      r[i * n + j] = 1 + (rand() % 1000);
    }
  }
  return (r);
}


x86 assembly (clang, -O0):
<make_random_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x2,%rax
imul   -0x10(%rbp),%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x20(%rbp)
call   1040 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <srand@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1208 <make_random_r+0xb8>
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11f5 <make_random_r+0xa5>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rsi
add    %rsi,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <make_random_r+0x60>
jmp    11fa <make_random_r+0xaa>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <make_random_r+0x4b>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_random_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r14
mov    %r13d,%edi
imul   %r14d,%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1040 <assert@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r14,%r14
je     11f9 <make_random_r+0xa9>
lea    0x0(,%r13,4),%r12
mov    (%rsp),%rbx
xor    %ebp,%ebp
jmp    11ac <make_random_r+0x5c>
nop
add    $0x1,%rbp
add    %r12,%rbx
cmp    %r14,%rbp
je     11f9 <make_random_r+0xa9>
test   %r13,%r13
je     11a0 <make_random_r+0x50>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%rbx,%r15,4)
add    $0x1,%r15
cmp    %r15,%r13
jne    11c0 <make_random_r+0x70>
jmp    11a0 <make_random_r+0x50>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @make_random_r(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i64 %0, i64* %3
store i64 %1, i64* %4
%9 = load i64, i64* %3
%10 = mul i64 4, %9
%11 = load i64, i64* %4
%12 = mul i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %7
%15 = call i32 @assert(i32* %14)
%16 = call i32 @time(i32* null)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = call i32 @srand(i32 %17)
store i32 0, i32* %5
br label %19
19: ; preds = %47, %2
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = load i64, i64* %3
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %50
24: ; preds = %19
store i32 0, i32* %6
br label %25
25: ; preds = %43, %24
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = load i64, i64* %4
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %46
30: ; preds = %25
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 1000
%33 = add nsw i32 1, %32
%34 = load i32*, i32** %7
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = load i64, i64* %4
%38 = mul i64 %36, %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = add i64 %38, %40
%42 = getelementptr inbounds i32, i32* %34, i64 %41
store i32 %33, i32* %42
br label %43
43: ; preds = %30
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %25
46: ; preds = %25
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %19
50: ; preds = %19
%51 = load i32*, i32** %7
ret i32* %51
}

LLVM IR (-O2):
define i32* @make_random_r(i64 %0, i64 %1) {
%3 = shl i64 %0, 2
%4 = mul i64 %3, %1
%5 = trunc i64 %4 to i32
%6 = tail call i32* @malloc(i32 %5)
%7 = tail call i32 @assert(i32* %6)
%8 = tail call i32 @time(i32* null)
%9 = tail call i32 @srand(i32 %8)
%10 = icmp eq i64 %0, 0
br i1 %10, label %29, label %11
11: ; preds = %2
%12 = icmp eq i64 %1, 0
br label %13
13: ; preds = %11, %26
%14 = phi i64 [ 0, %11 ], [ %27, %26 ]
br i1 %12, label %26, label %15
15: ; preds = %13
%16 = mul i64 %14, %1
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %24, %17 ]
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, 1000
%21 = add nsw i32 %20, 1
%22 = add i64 %18, %16
%23 = getelementptr inbounds i32, i32* %6, i64 %22
store i32 %21, i32* %23
%24 = add nuw i64 %18, 1
%25 = icmp eq i64 %24, %1
br i1 %25, label %26, label %17
26: ; preds = %17, %13
%27 = add nuw i64 %14, 1
%28 = icmp eq i64 %27, %0
br i1 %28, label %29, label %13
29: ; preds = %26, %2
ret i32* %6
}