#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(char *name, int rows, int cols, int matrix[rows][cols]) {
  printf("\n%s [%d][%d]\n", name, rows, cols);
  for (int row = 0; row < rows; row++) {
    for (int col = 0; col < cols; col++)
      printf("%d ", matrix[row][col]);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <print_matrix+0xb1>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11a5 <print_matrix+0x95>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115f <print_matrix+0x4f>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <print_matrix+0x3c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %edx,%ecx
mov    %esi,%r15d
mov    %rdi,%rsi
lea    0xec0(%rip),%rdi
mov    %r15d,%edx
mov    %ecx,0xc(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    11c9 <print_matrix+0xa9>
mov    0xc(%rsp),%ebp
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
lea    0x0(,%rbp,4),%r13
lea    0xea0(%rip),%r15
xor    %r14d,%r14d
jmp    1198 <print_matrix+0x78>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
add    %r13,%rbx
cmp    0x10(%rsp),%r14
je     11c9 <print_matrix+0xa9>
cmpl   $0x0,0xc(%rsp)
jle    1180 <print_matrix+0x60>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx,%r12,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    11b0 <print_matrix+0x90>
jmp    1180 <print_matrix+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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