#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 rand();
void fill_random(int a[][124], int h, int w) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; j++) {
      int value = rand() % 1000;
      a[i][j] = value;
    }
  }
}


x86 assembly (clang, -O0):
<fill_random>:
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    1197 <fill_random+0x87>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1184 <fill_random+0x74>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x1f0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <fill_random+0x2c>
jmp    1189 <fill_random+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <fill_random+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_random>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1183 <fill_random+0x73>
mov    %edx,%r14d
mov    %rdi,%rbx
mov    %esi,%r15d
mov    %edx,%r13d
xor    %r12d,%r12d
jmp    1140 <fill_random+0x30>
add    $0x1,%r12
add    $0x1f0,%rbx
cmp    %r15,%r12
je     1183 <fill_random+0x73>
test   %r14d,%r14d
jle    1130 <fill_random+0x20>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1150 <fill_random+0x40>
jmp    1130 <fill_random+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fill_random([124 x i32]* %0, i32 %1, i32 %2) {
%4 = alloca [124 x i32]*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store [124 x i32]* %0, [124 x 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 = call i32 (...) @rand()
%21 = srem i32 %20, 1000
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = load [124 x i32]*, [124 x i32]** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [124 x i32], [124 x i32]* %23, i64 %25
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [124 x i32], [124 x i32]* %26, i64 0, i64 %28
store i32 %22, 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 @fill_random([124 x i32]* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
%7 = zext i32 %1 to i64
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %5, %12
%10 = phi i64 [ 0, %5 ], [ %13, %12 ]
br i1 %6, label %15, label %12
11: ; preds = %12, %3
ret void
12: ; preds = %15, %9
%13 = add nuw nsw i64 %10, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %11, label %9
15: ; preds = %9, %15
%16 = phi i64 [ %20, %15 ], [ 0, %9 ]
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 1000
%19 = getelementptr inbounds [124 x i32], [124 x i32]* %0, i64 %10, i64 %16
store i32 %18, i32* %19
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %12, label %15
}