#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 */
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
int search_back(const char *end, const char *start, const char *target) {
  size_t tlen = strlen(target);
  if (start + tlen >= end)
    return 0;
  return (strncmp(end - tlen, target, tlen) == 0);
}


x86 assembly (clang, -O0):
<search_back>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     115f <search_back+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1188 <search_back+0x68>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
sub    -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_back>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
xor    %ecx,%ecx
cmp    %r15,%rbx
jae    1159 <search_back+0x39>
sub    %rax,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @search_back(i8* %0, i8* readnone %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = icmp ult i8* %5, %0
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = sub i64 0, %4
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i64 @strncmp(i8* %9, i8* %2, i64 %4)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %3, %7
%14 = phi i32 [ %12, %7 ], [ 0, %3 ]
ret i32 %14
}