#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 */
bool locate_backward(const char **needle_ptr, char *read_ptr,
                     const char *needle, const char *needle_last) {
  if (**needle_ptr == *read_ptr) {
    (*needle_ptr)--;
    if (*needle_ptr < needle) {
      *needle_ptr = (const char *)needle_last;
      return true;
    }
  } else
    *needle_ptr = (const char *)needle_last;
  return false;
}


x86 assembly (clang, -O0):
<locate_backward>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1168 <locate_backward+0x68>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jae    1163 <locate_backward+0x63>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    117a <locate_backward+0x7a>
jmp    1173 <locate_backward+0x73>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<locate_backward>:
mov    (%rdi),%r8
mov    (%r8),%al
cmp    (%rsi),%al
jne    111e <locate_backward+0x1e>
add    $0xffffffffffffffff,%r8
xor    %eax,%eax
cmp    %rdx,%r8
setb   %al
cmovb  %rcx,%r8
mov    %r8,(%rdi)
ret
mov    %rcx,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @locate_backward(i8** %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8** %0, i8*** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%10 = load i8**, i8*** %6
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %13, %16
br i1 %17, label %18, label %30
18: ; preds = %4
%19 = load i8**, i8*** %6
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i32 -1
store i8* %21, i8** %19
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = load i8*, i8** %8
%25 = icmp ult i8* %23, %24
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = load i8*, i8** %9
%28 = load i8**, i8*** %6
store i8* %27, i8** %28
store i32 1, i32* %5
br label %34
29: ; preds = %18
br label %33
30: ; preds = %4
%31 = load i8*, i8** %9
%32 = load i8**, i8*** %6
store i8* %31, i8** %32
br label %33
33: ; preds = %30, %29
store i32 0, i32* %5
br label %34
34: ; preds = %33, %26
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @locate_backward(i8** nocapture %0, i8* nocapture %1, i8* readnone %2, i8* %3) {
%5 = load i8*, i8** %0
%6 = load i8, i8* %5
%7 = load i8, i8* %1
%8 = icmp eq i8 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %5, i64 -1
%11 = icmp ult i8* %10, %2
%12 = select i1 %11, i8* %3, i8* %10
store i8* %12, i8** %0
%13 = zext i1 %11 to i32
br label %15
14: ; preds = %4
store i8* %3, i8** %0
br label %15
15: ; preds = %9, %14
%16 = phi i32 [ 0, %14 ], [ %13, %9 ]
ret i32 %16
}