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


x86 assembly (clang, -O0):
<random_matrix_int_3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <random_matrix_int_3+0xb8>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b5 <random_matrix_int_3+0xa5>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11a2 <random_matrix_int_3+0x92>
mov    -0x18(%rbp),%eax
imul   -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    %ecx,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x1,%edi
mov    $0xa,%esi
call   1030 <random_int@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1152 <random_matrix_int_3+0x42>
jmp    11a7 <random_matrix_int_3+0x97>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <random_matrix_int_3+0x2f>
jmp    11ba <random_matrix_int_3+0xaa>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112c <random_matrix_int_3+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_matrix_int_3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,0xc(%rsp)
mov    %rdi,0x28(%rsp)
mov    %ecx,0x20(%rsp)
test   %ecx,%ecx
jle    11ee <random_matrix_int_3+0xde>
mov    %edx,%ebp
mov    0xc(%rsp),%eax
mov    %eax,%ecx
mov    %rcx,0x30(%rsp)
mov    %edx,%ebx
mov    %edx,%ecx
imul   %eax,%ecx
mov    %ecx,0x1c(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %ecx,%ecx
jmp    117b <random_matrix_int_3+0x6b>
cs nopw 0x0(%rax,%rax,1)
mov    0x24(%rsp),%ecx
add    $0x1,%ecx
mov    0x10(%rsp),%rax
add    0x1c(%rsp),%eax
mov    %rax,0x10(%rsp)
cmp    0x20(%rsp),%ecx
je     11ee <random_matrix_int_3+0xde>
mov    %ecx,0x24(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    1160 <random_matrix_int_3+0x50>
mov    0x10(%rsp),%rax
mov    %eax,%r15d
xor    %r14d,%r14d
jmp    11ae <random_matrix_int_3+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
add    %ebp,%r15d
cmp    0x30(%rsp),%r14
je     1160 <random_matrix_int_3+0x50>
test   %ebp,%ebp
jle    11a0 <random_matrix_int_3+0x90>
movslq %r15d,%rax
mov    0x28(%rsp),%rcx
lea    (%rcx,%rax,4),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    $0xa,%esi
call   1030 <random_int@plt>
mov    %eax,(%r12,%r13,4)
add    $0x1,%r13
cmp    %r13,%rbx
jne    11d0 <random_matrix_int_3+0xc0>
jmp    11a0 <random_matrix_int_3+0x90>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @random_matrix_int_3(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 i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %13
13: ; preds = %52, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %55
17: ; preds = %13
store i32 0, i32* %10
br label %18
18: ; preds = %48, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %51
22: ; preds = %18
store i32 0, i32* %11
br label %23
23: ; preds = %44, %22
%24 = load i32, i32* %11
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %47
27: ; preds = %23
%28 = load i32, i32* %9
%29 = load i32, i32* %6
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* %7
%32 = mul nsw i32 %30, %31
%33 = load i32, i32* %10
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = add nsw i32 %32, %35
%37 = load i32, i32* %11
%38 = add nsw i32 %36, %37
store i32 %38, i32* %12
%39 = call i32 @random_int(i32 1, i32 10)
%40 = load i32*, i32** %5
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
br label %44
44: ; preds = %27
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %23
47: ; preds = %23
br label %48
48: ; preds = %47
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %18
51: ; preds = %18
br label %52
52: ; preds = %51
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %13
55: ; preds = %13
ret void
}

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