#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 /*<<< orphan*/ patch(int, int *);
int random();
void fill(int mwidth, int *m) {
  for (int i = 0; i < mwidth; i++) {
    for (int j = 0; j < mwidth; j++) {
      m[i * mwidth + j] = random() % 2;
    }
  }
  patch(mwidth, m);
}


x86 assembly (clang, -O0):
<fill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1199 <fill+0x79>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1186 <fill+0x66>
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1149 <fill+0x29>
jmp    118b <fill+0x6b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <fill+0x16>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <patch@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
mov    %edi,%r15d
test   %edi,%edi
jle    118d <fill+0x6d>
mov    %r15d,%ebx
lea    0x0(,%rbx,4),%r12
mov    (%rsp),%rbp
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <random@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %eax,0x0(%rbp,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbx
jne    1160 <fill+0x40>
add    $0x1,%r13
add    %r12,%rbp
cmp    %rbx,%r13
jne    1150 <fill+0x30>
mov    %r15d,%edi
mov    (%rsp),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <patch@plt>

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

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