#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
void print2DArray(int **arr, int rows, int cols) {
  int row, col, len;
  len = sizeof(char) * (rows * cols + rows) * 5 + 1;
  char *s = malloc(len);
  *s = '\0';
  char t[100];
  for (row = 0; row < rows; row++) {
    for (col = 0; col < cols; col++) {
      sprintf(t, "%4d ", arr[row][col]);
      strcat(s, t);
    }
    strcat(s, "\n");
  }
  fprintf(stderr, "%s", s);
  free(s);
}


x86 assembly (clang, -O0):
<print2DArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
cltq
shl    $0x0,%rax
imul   $0x5,%rax,%rax
add    $0x1,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121b <print2DArray+0xcb>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fd <print2DArray+0xad>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe26(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ad <print2DArray+0x5d>
mov    -0x28(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119a <print2DArray+0x4a>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdd8(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print2DArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %esi,%ebp
mov    %rdi,0x28(%rsp)
mov    %edx,0xc(%rsp)
mov    %edx,%eax
imul   %esi,%eax
add    %esi,%eax
lea    (%rax,%rax,4),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   %ebp,%ebp
jle    121e <print2DArray+0xce>
mov    %ebp,%eax
mov    %rax,0x20(%rsp)
mov    0xc(%rsp),%eax
mov    %rax,0x18(%rsp)
xor    %eax,%eax
mov    0x28(%rsp),%r14
mov    0x18(%rsp),%rbp
jmp    11cf <print2DArray+0x7f>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe4b(%rip),%rsi
call   1060 <strcat@plt>
mov    0x10(%rsp),%rax
add    $0x1,%rax
cmp    0x20(%rsp),%rax
je     121e <print2DArray+0xce>
mov    %rax,0x10(%rsp)
cmpl   $0x0,0xc(%rsp)
lea    0xe20(%rip),%r12
lea    0x30(%rsp),%r13
jle    11b0 <print2DArray+0x60>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%r14,%rax,8),%rax
mov    (%rax,%r15,4),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcat@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    11f0 <print2DArray+0xa0>
jmp    11b0 <print2DArray+0x60>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%4d \00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @print2DArray(i32** %0, i32 %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [100 x i8]
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = mul nsw i32 %12, %13
%15 = load i32, i32* %5
%16 = add nsw i32 %14, %15
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = mul i64 %18, 5
%20 = add i64 %19, 1
%21 = trunc i64 %20 to i32
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
store i8 0, i8* %24
store i32 0, i32* %7
br label %25
25: ; preds = %55, %3
%26 = load i32, i32* %7
%27 = load i32, i32* %5
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %58
29: ; preds = %25
store i32 0, i32* %8
br label %30
30: ; preds = %49, %29
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%36 = load i32**, i32*** %4
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32*, i32** %36, i64 %38
%40 = load i32*, i32** %39
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = load i8*, i8** %10
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%48 = call i32 @strcat(i8* %46, i8* %47)
br label %49
49: ; preds = %34
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %30
52: ; preds = %30
%53 = load i8*, i8** %10
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %55
55: ; preds = %52
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %25
58: ; preds = %25
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %10
%61 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %60)
%62 = load i8*, i8** %10
%63 = call i32 @free(i8* %62)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%4d \00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @print2DArray(i32** nocapture %0, i32 %1, i32 %2) {
%4 = alloca [100 x i8]
%5 = mul nsw i32 %2, %1
%6 = add nsw i32 %5, %1
%7 = mul i32 %6, 5
%8 = add i32 %7, 1
%9 = tail call i8* @malloc(i32 %8)
store i8 0, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %33
12: ; preds = %3
%13 = icmp sgt i32 %2, 0
%14 = zext i32 %1 to i64
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %12, %29
%17 = phi i64 [ 0, %12 ], [ %31, %29 ]
br i1 %13, label %18, label %29
18: ; preds = %16
%19 = getelementptr inbounds i32*, i32** %0, i64 %17
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %27, %20 ]
%22 = load i32*, i32** %19
%23 = getelementptr inbounds i32, i32* %22, i64 %21
%24 = load i32, i32* %23
%25 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = call i32 @strcat(i8* %9, i8* %10)
%27 = add nuw nsw i64 %21, 1
%28 = icmp eq i64 %27, %15
br i1 %28, label %29, label %20
29: ; preds = %20, %16
%30 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = add nuw nsw i64 %17, 1
%32 = icmp eq i64 %31, %14
br i1 %32, label %33, label %16
33: ; preds = %29, %3
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%36 = call i32 @free(i8* %9)
ret void
}