#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*/ print_submatrix(size_t, size_t, int **, size_t, size_t,
                                   size_t, size_t);
void submatrices(size_t N, size_t M, int matrix[N][M], size_t rows,
                 size_t cols) {
  size_t i, j;
  for (i = 0; i + rows - 1 < N; i++) {
    for (j = 0; j + cols - 1 < M; j++) {
      print_submatrix(N, M, matrix, i, j, rows, cols);
    }
  }
}


x86 assembly (clang, -O0):
<submatrices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
sub    $0x1,%rax
cmp    -0x8(%rbp),%rax
jae    11b4 <submatrices+0xa4>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    -0x28(%rbp),%rax
sub    $0x1,%rax
cmp    -0x10(%rbp),%rax
jae    119e <submatrices+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <print_submatrix@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1152 <submatrices+0x42>
jmp    11a3 <submatrices+0x93>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1134 <submatrices+0x24>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<submatrices>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    -0x1(%rcx),%rax
cmp    %rdi,%rax
jae    11c0 <submatrices+0xb0>
mov    %rcx,%rbx
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbp
lea    -0x1(%r8),%rax
mov    %rax,0x10(%rsp)
mov    %rsi,%rax
sub    %r8,%rax
add    $0x1,%rax
mov    %rdi,%rcx
sub    %rbx,%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rsp)
xor    %r12d,%r12d
mov    %r8,0x20(%rsp)
mov    %rax,0x18(%rsp)
jmp    117b <submatrices+0x6b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    0x8(%rsp),%r12
je     11c0 <submatrices+0xb0>
cmp    %r15,0x10(%rsp)
jae    1170 <submatrices+0x60>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r8,(%rsp)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r14,%r8
mov    %rbx,%r9
call   1030 <print_submatrix@plt>
mov    0x18(%rsp),%rax
mov    0x20(%rsp),%r8
add    $0x1,%r14
cmp    %r14,%rax
jne    1190 <submatrices+0x80>
jmp    1170 <submatrices+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @submatrices(i64 %0, i64 %1, i32* %2, i64 %3, i64 %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i64 %0, i64* %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%13 = load i64, i64* %6
%14 = load i64, i64* %7
store i64 0, i64* %11
br label %15
15: ; preds = %44, %5
%16 = load i64, i64* %11
%17 = load i64, i64* %9
%18 = add i64 %16, %17
%19 = sub i64 %18, 1
%20 = load i64, i64* %6
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %47
22: ; preds = %15
store i64 0, i64* %12
br label %23
23: ; preds = %40, %22
%24 = load i64, i64* %12
%25 = load i64, i64* %10
%26 = add i64 %24, %25
%27 = sub i64 %26, 1
%28 = load i64, i64* %7
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %23
%31 = load i64, i64* %6
%32 = load i64, i64* %7
%33 = load i32*, i32** %8
%34 = bitcast i32* %33 to i32**
%35 = load i64, i64* %11
%36 = load i64, i64* %12
%37 = load i64, i64* %9
%38 = load i64, i64* %10
%39 = call i32 @print_submatrix(i64 %31, i64 %32, i32** %34, i64 %35, i64 %36, i64 %37, i64 %38)
br label %40
40: ; preds = %30
%41 = load i64, i64* %12
%42 = add i64 %41, 1
store i64 %42, i64* %12
br label %23
43: ; preds = %23
br label %44
44: ; preds = %43
%45 = load i64, i64* %11
%46 = add i64 %45, 1
store i64 %46, i64* %11
br label %15
47: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @submatrices(i64 %0, i64 %1, i32* %2, i64 %3, i64 %4) {
%6 = add i64 %3, -1
%7 = icmp ult i64 %6, %0
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = add i64 %4, -1
%10 = icmp ult i64 %9, %1
%11 = bitcast i32* %2 to i32**
%12 = add i64 %1, 1
%13 = sub i64 %12, %4
%14 = add i64 %0, 1
%15 = sub i64 %14, %3
br label %16
16: ; preds = %8, %23
%17 = phi i64 [ 0, %8 ], [ %24, %23 ]
br i1 %10, label %18, label %23
18: ; preds = %16, %18
%19 = phi i64 [ %21, %18 ], [ 0, %16 ]
%20 = tail call i32 @print_submatrix(i64 %0, i64 %1, i32** %11, i64 %17, i64 %19, i64 %3, i64 %4)
%21 = add i64 %19, 1
%22 = icmp eq i64 %21, %13
br i1 %22, label %23, label %18
23: ; preds = %18, %16
%24 = add i64 %17, 1
%25 = icmp eq i64 %24, %15
br i1 %25, label %26, label %16
26: ; preds = %23, %5
ret void
}