#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 print_matrix(int *mat, int m, int n) {
  int i, j;
  if (mat == NULL || m <= 0 || n <= 0) {
    return;
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      printf("%d ", mat[i * n + j]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1141 <print_matrix+0x31>
cmpl   $0x0,-0xc(%rbp)
jle    1141 <print_matrix+0x31>
cmpl   $0x0,-0x10(%rbp)
jg     1146 <print_matrix+0x36>
jmp    11b8 <print_matrix+0xa8>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <print_matrix+0xa8>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119c <print_matrix+0x8c>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1160 <print_matrix+0x50>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <print_matrix+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     119e <print_matrix+0x7e>
test   %esi,%esi
jle    119e <print_matrix+0x7e>
test   %edx,%edx
jle    119e <print_matrix+0x7e>
mov    %rdi,%rbx
mov    %edx,%r15d
mov    %esi,%eax
mov    %rax,(%rsp)
lea    0x0(,%r15,4),%r13
lea    0xead(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx,%r12,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
cmp    %r12,%r15
jne    1170 <print_matrix+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
add    %r13,%rbx
cmp    (%rsp),%rbp
jne    1160 <print_matrix+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_matrix(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
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %6
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %3
br label %47
18: ; preds = %14
store i32 0, i32* %7
br label %19
19: ; preds = %44, %18
%20 = load i32, i32* %7
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %47
23: ; preds = %19
store i32 0, i32* %8
br label %24
24: ; preds = %39, %23
%25 = load i32, i32* %8
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = load i32*, i32** %4
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = mul nsw i32 %30, %31
%33 = load i32, i32* %8
%34 = add nsw i32 %32, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %29, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %28
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %24
42: ; preds = %24
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, 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 %19
47: ; preds = %17, %19
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define void @print_matrix(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32* %0, null
%5 = icmp slt i32 %1, 1
%6 = or i1 %4, %5
%7 = icmp slt i32 %2, 1
%8 = or i1 %6, %7
br i1 %8, label %28, label %9
9: ; preds = %3
%10 = zext i32 %2 to i64
%11 = zext i32 %1 to i64
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %24, %9
%14 = phi i64 [ 0, %9 ], [ %26, %24 ]
%15 = mul nsw i64 %14, %10
br label %16
16: ; preds = %13, %16
%17 = phi i64 [ 0, %13 ], [ %22, %16 ]
%18 = add nuw nsw i64 %17, %15
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %24, label %16
24: ; preds = %16
%25 = tail call i32 @putchar(i32 10)
%26 = add nuw nsw i64 %14, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %28, label %13
28: ; preds = %24, %3
ret void
}