#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 *, int);
int /*<<< orphan*/ putchar(char);
void print_submatrix(size_t N, size_t M, int matrix[N][M], size_t row_begin,
                     size_t col_begin, size_t rows, size_t cols) {
  size_t i, j;
  for (i = 0; i < rows; i++) {
    for (j = 0; j < cols; j++) {
      printf("%d ", matrix[row_begin + i][col_begin + j]);
    }
    putchar('\n');
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<print_submatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11d6 <print_submatrix+0xb6>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    0x10(%rbp),%rax
jae    11bb <print_submatrix+0x9b>
mov    -0x48(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x38(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    -0x28(%rbp),%rcx
add    -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    116a <print_submatrix+0x4a>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1154 <print_submatrix+0x34>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_submatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
test   %r9,%r9
je     1197 <print_submatrix+0x77>
mov    %rsi,%r15
mov    0x40(%rsp),%r13
imul   %rsi,%rcx
add    %rcx,%r8
lea    (%rdx,%r8,4),%rbx
shl    $0x2,%r15
xor    %ebp,%ebp
lea    0xeac(%rip),%r12
jmp    1177 <print_submatrix+0x57>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
add    %r15,%rbx
cmp    (%rsp),%rbp
je     1197 <print_submatrix+0x77>
test   %r13,%r13
je     1160 <print_submatrix+0x40>
xor    %r14d,%r14d
nop
mov    (%rbx,%r14,4),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    1180 <print_submatrix+0x60>
jmp    1160 <print_submatrix+0x40>
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 = [4 x i8] c"%d \00"
define void @print_submatrix(i64 %0, i64 %1, i32* %2, i64 %3, i64 %4, i64 %5, i64 %6) {
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
store i64 %0, i64* %8
store i64 %1, i64* %9
store i32* %2, i32** %10
store i64 %3, i64* %11
store i64 %4, i64* %12
store i64 %5, i64* %13
store i64 %6, i64* %14
%17 = load i64, i64* %8
%18 = load i64, i64* %9
store i64 0, i64* %15
br label %19
19: ; preds = %46, %7
%20 = load i64, i64* %15
%21 = load i64, i64* %13
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %49
23: ; preds = %19
store i64 0, i64* %16
br label %24
24: ; preds = %41, %23
%25 = load i64, i64* %16
%26 = load i64, i64* %14
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = load i32*, i32** %10
%30 = load i64, i64* %11
%31 = load i64, i64* %15
%32 = add i64 %30, %31
%33 = mul nsw i64 %32, %18
%34 = getelementptr inbounds i32, i32* %29, i64 %33
%35 = load i64, i64* %12
%36 = load i64, i64* %16
%37 = add i64 %35, %36
%38 = getelementptr inbounds i32, i32* %34, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %28
%42 = load i64, i64* %16
%43 = add i64 %42, 1
store i64 %43, i64* %16
br label %24
44: ; preds = %24
%45 = call i32 @putchar(i8 signext 10)
br label %46
46: ; preds = %44
%47 = load i64, i64* %15
%48 = add i64 %47, 1
store i64 %48, i64* %15
br label %19
49: ; preds = %19
%50 = call i32 @putchar(i8 signext 10)
ret void
}

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