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


x86 assembly (clang, -O0):
<array_search_backward>:
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),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jb     1190 <array_search_backward+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    1176 <array_search_backward+0x66>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <array_search_backward+0x88>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1136 <array_search_backward+0x26>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_search_backward>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %ecx,%esi
jb     1160 <array_search_backward+0x50>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %ecx,%r12d
neg    %r12
mov    %esi,%eax
add    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rbx,%r12,1),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1162 <array_search_backward+0x52>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
cmp    %r15d,%ebp
jae    1140 <array_search_backward+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @array_search_backward(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
%10 = load i32, i32* %7
%11 = load i8*, i8** %6
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8* %13, i8** %6
br label %14
14: ; preds = %30, %4
%15 = load i32, i32* %7
%16 = load i32, i32* %9
%17 = icmp uge i32 %15, %16
br i1 %17, label %18, label %35
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i32, i32* %9
%21 = zext i32 %20 to i64
%22 = sub i64 0, %21
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = call i64 @memcmp(i8* %23, i8* %24, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = load i8*, i8** %6
store i8* %29, i8** %5
br label %36
30: ; preds = %18
%31 = load i32, i32* %7
%32 = add i32 %31, -1
store i32 %32, i32* %7
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %6
br label %14
35: ; preds = %14
store i8* null, i8** %5
br label %36
36: ; preds = %35, %28
%37 = load i8*, i8** %5
ret i8* %37
}

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