#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 */
int random_int(int, int);
void random_matrix_int_2(int *a, const int rows, const int cols) {
  for (int r = 0; r < rows; r++) {
    for (int c = 0; c < cols; c++) {
      const int pos = (r * cols) + c;
      a[pos] = random_int(1, 10);
    }
  }
}


x86 assembly (clang, -O0):
<random_matrix_int_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <random_matrix_int_2+0x82>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    117f <random_matrix_int_2+0x6f>
mov    -0x14(%rbp),%eax
imul   -0x10(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1,%edi
mov    $0xa,%esi
call   1030 <random_int@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <random_matrix_int_2+0x2c>
jmp    1184 <random_matrix_int_2+0x74>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <random_matrix_int_2+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_matrix_int_2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,0x4(%rsp)
test   %esi,%esi
jle    117e <random_matrix_int_2+0x6e>
mov    %rdi,%rbx
movslq 0x4(%rsp),%r12
mov    %esi,%r15d
mov    %r12d,%ebp
shl    $0x2,%r12
xor    %r13d,%r13d
jmp    114c <random_matrix_int_2+0x3c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
add    %r12,%rbx
cmp    %r15,%r13
je     117e <random_matrix_int_2+0x6e>
cmpl   $0x0,0x4(%rsp)
jle    1140 <random_matrix_int_2+0x30>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    $0xa,%esi
call   1030 <random_int@plt>
mov    %eax,(%rbx,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbp
jne    1160 <random_matrix_int_2+0x50>
jmp    1140 <random_matrix_int_2+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @random_matrix_int_2(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
%7 = sext i32 %2 to i64
%8 = zext i32 %1 to i64
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %5, %15
%11 = phi i64 [ 0, %5 ], [ %16, %15 ]
br i1 %6, label %12, label %15
12: ; preds = %10
%13 = mul nsw i64 %11, %7
br label %18
14: ; preds = %15, %3
ret void
15: ; preds = %18, %10
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %14, label %10
18: ; preds = %12, %18
%19 = phi i64 [ 0, %12 ], [ %23, %18 ]
%20 = add nsw i64 %19, %13
%21 = tail call i32 @random_int(i32 1, i32 10)
%22 = getelementptr inbounds i32, i32* %0, i64 %20
store i32 %21, i32* %22
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, %9
br i1 %24, label %15, label %18
}