#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*/ printf(char *, ...);
void prettyprint(int m[], int r, int c) {
  int i = 0;
  int j = 0;
  printf("\n");
  if (m == NULL) {
    printf("Tried to print a null pointer.\n");
    return;
  }
  if (r * c > 1000) {
    printf("%d by %d is too big to pretty print.\n", r, c);
    return;
  }
  for (i = 0; i < r; i++) {
    printf("[ ");
    for (j = 0; j < c; j++) {
      printf("%5d ", *m++);
    }
    printf("]\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<prettyprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
jne    115c <prettyprint+0x4c>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <prettyprint+0x102>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cmp    $0x3e8,%eax
jle    1187 <prettyprint+0x77>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <prettyprint+0x102>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1204 <prettyprint+0xf4>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e8 <prettyprint+0xd8>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11af <prettyprint+0x9f>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118e <prettyprint+0x7e>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prettyprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%r14d
mov    %rdi,%rbp
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %rbp,%rbp
je     1183 <prettyprint+0x53>
mov    %r13d,%eax
imul   %r14d,%eax
cmp    $0x3e8,%eax
jle    119d <prettyprint+0x6d>
lea    0xe98(%rip),%rdi
mov    %r14d,%esi
mov    %r13d,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
lea    0xea6(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
test   %r14d,%r14d
jle    11f9 <prettyprint+0xc9>
lea    0xe80(%rip),%rbx
xor    %r15d,%r15d
jmp    11c5 <prettyprint+0x95>
xchg   %ax,%ax
lea    0xe77(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%r15d
cmp    %r14d,%r15d
je     11f9 <prettyprint+0xc9>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13d,%r13d
jle    11b0 <prettyprint+0x80>
mov    %r13d,%r12d
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%esi
add    $0x4,%rbp
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%r12d
jne    11e0 <prettyprint+0xb0>
jmp    11b0 <prettyprint+0x80>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [32 x i8] c"Tried to print a null pointer.\0A\00"
@.str.2 = [38 x i8] c"%d by %d is too big to pretty print.\0A\00"
@.str.3 = [3 x i8] c"[ \00"
@.str.4 = [5 x i8] c"%5d \00"
@.str.5 = [3 x i8] c"]\0A\00"
define void @prettyprint(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %49
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = mul nsw i32 %15, %16
%18 = icmp sgt i32 %17, 1000
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
br label %49
23: ; preds = %14
store i32 0, i32* %7
br label %24
24: ; preds = %44, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %47
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %30
30: ; preds = %39, %28
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i32 1
store i32* %36, i32** %4
%37 = load i32, i32* %35
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %34
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %30
42: ; preds = %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %42
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %24
47: ; preds = %24
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %49
49: ; preds = %47, %19, %12
ret void
}

LLVM IR (-O2):
@.str.2 = [38 x i8] c"%d by %d is too big to pretty print.\0A\00"
@.str.3 = [3 x i8] c"[ \00"
@.str.4 = [5 x i8] c"%5d \00"
@str = [2 x i8] c"]\00"
@str.6 = [31 x i8] c"Tried to print a null pointer.\00"
define void @prettyprint(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 @putchar(i32 10)
%5 = icmp eq i32* %0, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.6, i64 0, i64 0))
br label %36
8: ; preds = %3
%9 = mul nsw i32 %2, %1
%10 = icmp sgt i32 %9, 1000
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %34
13: ; preds = %11
%14 = icmp sgt i32 %2, 0
br label %17
15: ; preds = %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %2)
br label %36
17: ; preds = %13, %29
%18 = phi i32 [ 0, %13 ], [ %32, %29 ]
%19 = phi i32* [ %0, %13 ], [ %30, %29 ]
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br i1 %14, label %21, label %29
21: ; preds = %17, %21
%22 = phi i32 [ %27, %21 ], [ 0, %17 ]
%23 = phi i32* [ %24, %21 ], [ %19, %17 ]
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = load i32, i32* %23
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i32 %22, 1
%28 = icmp eq i32 %27, %2
br i1 %28, label %29, label %21
29: ; preds = %21, %17
%30 = phi i32* [ %19, %17 ], [ %24, %21 ]
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%32 = add nuw nsw i32 %18, 1
%33 = icmp eq i32 %32, %1
br i1 %33, label %34, label %17
34: ; preds = %29, %11
%35 = tail call i32 @putchar(i32 10)
br label %36
36: ; preds = %34, %15, %6
ret void
}