#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 */
scalar_t__ doesGridMatchPattern(char **, char **, int, int, int);
int doesGridContainPattern(char **grid, char **pattern, int numGridRows,
                           int numGridColumns, int numPatternRows,
                           int numPatternColumns) {
  int maxRow = numGridRows - numPatternRows;
  int maxColumn = numGridColumns - numPatternColumns;
  for (int row = 0; row <= maxRow; row++) {
    for (int column = 0; column <= maxColumn; column++) {
      if (doesGridMatchPattern(grid + row, pattern, column, numPatternRows,
                               numPatternColumns)) {
        return 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<doesGridContainPattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     11c4 <doesGridContainPattern+0xb4>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     11b1 <doesGridContainPattern+0xa1>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1030 <doesGridMatchPattern@plt>
cmp    $0x0,%rax
je     119e <doesGridContainPattern+0x8e>
movl   $0x1,-0x4(%rbp)
jmp    11cb <doesGridContainPattern+0xbb>
jmp    11a3 <doesGridContainPattern+0x93>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    115a <doesGridContainPattern+0x4a>
jmp    11b6 <doesGridContainPattern+0xa6>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1147 <doesGridContainPattern+0x37>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doesGridContainPattern>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x20(%rsp)
xor    %eax,%eax
sub    %r8d,%edx
jl     11c8 <doesGridContainPattern+0xb8>
mov    %r9d,%ebx
mov    %r8d,%ebp
mov    %rsi,%r12
mov    %ecx,%r15d
sub    %r9d,%r15d
add    $0x1,%r15d
add    $0x1,%edx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    %ecx,0x14(%rsp)
mov    %rdx,0x18(%rsp)
jmp    117f <doesGridContainPattern+0x6f>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
mov    0x18(%rsp),%rdx
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
cmp    %rdx,%rcx
mov    0x14(%rsp),%ecx
je     11d7 <doesGridContainPattern+0xc7>
cmp    %ebx,%ecx
jl     1160 <doesGridContainPattern+0x50>
mov    0x20(%rsp),%rax
mov    0x8(%rsp),%rcx
lea    (%rax,%rcx,8),%r13
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
call   1030 <doesGridMatchPattern@plt>
test   %rax,%rax
jne    11c3 <doesGridContainPattern+0xb3>
add    $0x1,%r14d
cmp    %r14d,%r15d
jne    11a0 <doesGridContainPattern+0x90>
jmp    1160 <doesGridContainPattern+0x50>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    11c8 <doesGridContainPattern+0xb8>

LLVM IR (-O0):
define i32 @doesGridContainPattern(i8** %0, i8** %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i8** %0, i8*** %8
store i8** %1, i8*** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%18 = load i32, i32* %10
%19 = load i32, i32* %12
%20 = sub nsw i32 %18, %19
store i32 %20, i32* %14
%21 = load i32, i32* %11
%22 = load i32, i32* %13
%23 = sub nsw i32 %21, %22
store i32 %23, i32* %15
store i32 0, i32* %16
br label %24
24: ; preds = %50, %6
%25 = load i32, i32* %16
%26 = load i32, i32* %14
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %53
28: ; preds = %24
store i32 0, i32* %17
br label %29
29: ; preds = %46, %28
%30 = load i32, i32* %17
%31 = load i32, i32* %15
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %49
33: ; preds = %29
%34 = load i8**, i8*** %8
%35 = load i32, i32* %16
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8**, i8*** %9
%39 = load i32, i32* %17
%40 = load i32, i32* %12
%41 = load i32, i32* %13
%42 = call i64 @doesGridMatchPattern(i8** %37, i8** %38, i32 %39, i32 %40, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %33
store i32 1, i32* %7
br label %54
45: ; preds = %33
br label %46
46: ; preds = %45
%47 = load i32, i32* %17
%48 = add nsw i32 %47, 1
store i32 %48, i32* %17
br label %29
49: ; preds = %29
br label %50
50: ; preds = %49
%51 = load i32, i32* %16
%52 = add nsw i32 %51, 1
store i32 %52, i32* %16
br label %24
53: ; preds = %24
store i32 0, i32* %7
br label %54
54: ; preds = %53, %44
%55 = load i32, i32* %7
ret i32 %55
}

LLVM IR (-O2):
define i32 @doesGridContainPattern(i8** %0, i8** %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp slt i32 %2, %4
br i1 %7, label %29, label %8
8: ; preds = %6
%9 = icmp slt i32 %3, %5
%10 = add i32 %3, 1
%11 = sub i32 %10, %5
%12 = add i32 %2, 1
%13 = sub i32 %12, %4
%14 = zext i32 %13 to i64
br label %15
15: ; preds = %8, %26
%16 = phi i64 [ 0, %8 ], [ %27, %26 ]
br i1 %9, label %26, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %0, i64 %16
br label %22
19: ; preds = %22
%20 = add nuw i32 %23, 1
%21 = icmp eq i32 %20, %11
br i1 %21, label %26, label %22
22: ; preds = %17, %19
%23 = phi i32 [ 0, %17 ], [ %20, %19 ]
%24 = tail call i64 @doesGridMatchPattern(i8** %18, i8** %1, i32 %23, i32 %4, i32 %5)
%25 = icmp eq i64 %24, 0
br i1 %25, label %19, label %29
26: ; preds = %19, %15
%27 = add nuw nsw i64 %16, 1
%28 = icmp eq i64 %27, %14
br i1 %28, label %29, label %15
29: ; preds = %26, %22, %6
%30 = phi i32 [ 0, %6 ], [ 1, %22 ], [ 0, %26 ]
ret i32 %30
}