#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 */
typedef int uint32_t;

/* Variables and functions */
scalar_t__ memcmp(int *, int *, int);
int GoRgbaCheckCrop(void *haystackBytes, void *needleBytes, int hayWidth,
                    int needleWidth, int needleHeight, int needleLeft,
                    int needleTop) {
  uint32_t *haystackRow =
      (uint32_t *)haystackBytes + needleTop * hayWidth + needleLeft;
  uint32_t *needleRow = (uint32_t *)needleBytes;
  uint32_t needleStride = needleWidth * 4;
  for (int y = needleHeight; y > 0; --y) {
    if (memcmp(haystackRow, needleRow, needleStride))
      return 0;
    haystackRow += hayWidth;
    needleRow += needleWidth;
  }
  return 1;
}


x86 assembly (clang, -O0):
<GoRgbaCheckCrop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
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    -0x10(%rbp),%rax
mov    0x10(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jle    11d4 <GoRgbaCheckCrop+0xc4>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     119c <GoRgbaCheckCrop+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    11db <GoRgbaCheckCrop+0xcb>
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x40(%rbp)
jmp    116c <GoRgbaCheckCrop+0x5c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GoRgbaCheckCrop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%eax
test   %r8d,%r8d
jle    118c <GoRgbaCheckCrop+0x7c>
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
movslq %edx,%r13
imul   0x40(%rsp),%edx
movslq %edx,%rax
movslq %r9d,%rcx
movslq %r15d,%r14
shl    $0x2,%r15d
add    $0x1,%r12d
shl    $0x2,%r14
shl    $0x2,%rax
lea    (%rax,%rcx,4),%rax
add    %rax,%rbp
shl    $0x2,%r13
nopl   (%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    118a <GoRgbaCheckCrop+0x7a>
add    $0xffffffff,%r12d
add    %r14,%rbx
add    %r13,%rbp
cmp    $0x1,%r12d
jg     1160 <GoRgbaCheckCrop+0x50>
mov    $0x1,%eax
jmp    118c <GoRgbaCheckCrop+0x7c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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