#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__ memcmp(unsigned char const *, unsigned char const *, unsigned int);
const unsigned char *array_search_forward(const unsigned char *data,
                                          unsigned int size,
                                          const unsigned char *marker,
                                          unsigned int msize) {
  while (size >= msize) {
    if (memcmp(data, marker, msize) == 0)
      return data;
    size--;
    data++;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<array_search_forward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jb     1173 <array_search_forward+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1159 <array_search_forward+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    117b <array_search_forward+0x6b>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1126 <array_search_forward+0x16>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_search_forward>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %ecx,%esi
jb     114f <array_search_forward+0x3f>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1151 <array_search_forward+0x41>
add    $0xffffffff,%ebp
add    $0x1,%rbx
cmp    %r15d,%ebp
jae    1130 <array_search_forward+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @array_search_forward(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
br label %10
10: ; preds = %22, %4
%11 = load i32, i32* %7
%12 = load i32, i32* %9
%13 = icmp uge i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = call i64 @memcmp(i8* %15, i8* %16, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load i8*, i8** %6
store i8* %21, i8** %5
br label %28
22: ; preds = %14
%23 = load i32, i32* %7
%24 = add i32 %23, -1
store i32 %24, i32* %7
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
br label %10
27: ; preds = %10
store i8* null, i8** %5
br label %28
28: ; preds = %27, %20
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
define i8* @array_search_forward(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp ult i32 %1, %3
br i1 %5, label %15, label %6
6: ; preds = %4, %11
%7 = phi i8* [ %13, %11 ], [ %0, %4 ]
%8 = phi i32 [ %12, %11 ], [ %1, %4 ]
%9 = tail call i64 @memcmp(i8* %7, i8* %2, i32 %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = add i32 %8, -1
%13 = getelementptr inbounds i8, i8* %7, i64 1
%14 = icmp ult i32 %12, %3
br i1 %14, label %15, label %6
15: ; preds = %6, %11, %4
%16 = phi i8* [ null, %4 ], [ null, %11 ], [ %7, %6 ]
ret i8* %16
}