#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();
void init_mat(char **mat) {
  int i, j;
  for (i = 0; i < (1024 * 2); i++) {
    for (j = 0; j < (1024 * 2); j++) {
      mat[i][j] = (random() % 9) + 1;
    }
  }
}


x86 assembly (clang, -O0):
<init_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x800,-0xc(%rbp)
jge    118a <init_mat+0x7a>
movl   $0x0,-0x10(%rbp)
cmpl   $0x800,-0x10(%rbp)
jge    1177 <init_mat+0x67>
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x9,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1137 <init_mat+0x27>
jmp    117c <init_mat+0x6c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <init_mat+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_mat>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <random@plt>
cltq
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,8),%ecx
sub    %ecx,%eax
add    $0x1,%al
mov    (%r14,%r15,8),%rcx
mov    %al,(%rcx,%rbx,1)
add    $0x1,%rbx
cmp    $0x800,%rbx
jne    1130 <init_mat+0x20>
add    $0x1,%r15
cmp    $0x800,%r15
jne    1120 <init_mat+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @init_mat(i8** nocapture %0) {
br label %2
2: ; preds = %1, %15
%3 = phi i64 [ 0, %1 ], [ %16, %15 ]
%4 = getelementptr inbounds i8*, i8** %0, i64 %3
br label %5
5: ; preds = %2, %5
%6 = phi i64 [ 0, %2 ], [ %13, %5 ]
%7 = tail call i32 (...) @random()
%8 = srem i32 %7, 9
%9 = trunc i32 %8 to i8
%10 = add nsw i8 %9, 1
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 %6
store i8 %10, i8* %12
%13 = add nuw nsw i64 %6, 1
%14 = icmp eq i64 %13, 2048
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = add nuw nsw i64 %3, 1
%17 = icmp eq i64 %16, 2048
br i1 %17, label %18, label %2
18: ; preds = %15
ret void
}