#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 */
int find_line_size(char const *, size_t const);
char *find_line_start(char const *, size_t);
int match(char const *, int const, char const *);
const char *bisect_end(const char *data, const size_t data_size,
                       const char *pattern) {
  if (data_size <= 1)
    return NULL;
  size_t mid = data_size / 2;
  const char *line_start = find_line_start(data, mid);
  mid = line_start - data;
  const int line_size = find_line_size(line_start, data_size - mid);
  const int compare = match(line_start, line_size, pattern);
  if (compare < 0) {
    return bisect_end(data, mid, pattern);
  } else {
    const char *end = bisect_end(line_start + line_size + 1,
                                 data_size - mid - line_size - 1, pattern);
    if (compare == 0 && end == NULL)
      end = line_start + line_size + 1;
    return end;
  }
}


x86 assembly (clang, -O0):
<bisect_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x1,-0x18(%rbp)
ja     116c <bisect_end+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    1242 <bisect_end+0x102>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <find_line_start@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x28(%rbp),%rsi
call   1040 <find_line_size@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <match@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11e3 <bisect_end+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <bisect_end@plt>
mov    %rax,-0x8(%rbp)
jmp    1242 <bisect_end+0x102>
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
sub    -0x28(%rbp),%rsi
movslq -0x34(%rbp),%rax
sub    %rax,%rsi
sub    $0x1,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <bisect_end@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    123a <bisect_end+0xfa>
cmpq   $0x0,-0x40(%rbp)
jne    123a <bisect_end+0xfa>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bisect_end>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r14
mov    %rdi,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
cmp    $0x2,%r14
jb     11de <bisect_end+0x9e>
mov    %r14,%rsi
shr    %rsi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <find_line_start@plt>
mov    %rax,%r13
mov    %rax,%r12
sub    %rbx,%r12
mov    %r14,%rbx
sub    %r12,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <find_line_size@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %eax,%esi
mov    0x8(%rsp),%rdx
call   1060 <match@plt>
mov    %r12,%r14
test   %eax,%eax
js     1160 <bisect_end+0x20>
mov    %eax,%ebp
movslq %r15d,%rax
lea    (%rax,%r13,1),%r14
add    $0x1,%r14
not    %rax
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    0x8(%rsp),%rdx
call   1030 <bisect_end@plt>
test   %rax,%rax
cmovne %rax,%r14
test   %ebp,%ebp
cmovne %rax,%r14
jmp    11e1 <bisect_end+0xa1>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bisect_end(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%13 = load i64, i64* %6
%14 = icmp ule i64 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %3
store i8* null, i8** %4
br label %71
16: ; preds = %3
%17 = load i64, i64* %6
%18 = udiv i64 %17, 2
store i64 %18, i64* %8
%19 = load i8*, i8** %5
%20 = load i64, i64* %8
%21 = call i8* @find_line_start(i8* %19, i64 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = load i8*, i8** %5
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
store i64 %26, i64* %8
%27 = load i8*, i8** %9
%28 = load i64, i64* %6
%29 = load i64, i64* %8
%30 = sub i64 %28, %29
%31 = call i32 @find_line_size(i8* %27, i64 %30)
store i32 %31, i32* %10
%32 = load i8*, i8** %9
%33 = load i32, i32* %10
%34 = load i8*, i8** %7
%35 = call i32 @match(i8* %32, i32 %33, i8* %34)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %16
%39 = load i8*, i8** %5
%40 = load i64, i64* %8
%41 = load i8*, i8** %7
%42 = call i8* @bisect_end(i8* %39, i64 %40, i8* %41)
store i8* %42, i8** %4
br label %71
43: ; preds = %16
%44 = load i8*, i8** %9
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = load i64, i64* %6
%50 = load i64, i64* %8
%51 = sub i64 %49, %50
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = sub i64 %51, %53
%55 = sub i64 %54, 1
%56 = load i8*, i8** %7
%57 = call i8* @bisect_end(i8* %48, i64 %55, i8* %56)
store i8* %57, i8** %12
%58 = load i32, i32* %11
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %43
%61 = load i8*, i8** %12
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = load i8*, i8** %9
%65 = load i32, i32* %10
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = getelementptr inbounds i8, i8* %67, i64 1
store i8* %68, i8** %12
br label %69
69: ; preds = %63, %60, %43
%70 = load i8*, i8** %12
store i8* %70, i8** %4
br label %71
71: ; preds = %69, %38, %15
%72 = load i8*, i8** %4
ret i8* %72
}

LLVM IR (-O2):
define i8* @bisect_end(i8* %0, i64 %1, i8* %2) {
%4 = ptrtoint i8* %0 to i64
br label %5
5: ; preds = %8, %3
%6 = phi i64 [ %1, %3 ], [ %12, %8 ]
%7 = icmp ult i64 %6, 2
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = lshr i64 %6, 1
%10 = tail call i8* @find_line_start(i8* %0, i64 %9)
%11 = ptrtoint i8* %10 to i64
%12 = sub i64 %11, %4
%13 = sub i64 %6, %12
%14 = tail call i32 @find_line_size(i8* %10, i64 %13)
%15 = tail call i32 @match(i8* %10, i32 %14, i8* %2)
%16 = icmp slt i32 %15, 0
br i1 %16, label %5, label %19
17: ; preds = %5, %19
%18 = phi i8* [ %29, %19 ], [ null, %5 ]
ret i8* %18
19: ; preds = %8
%20 = sext i32 %14 to i64
%21 = getelementptr inbounds i8, i8* %10, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = xor i64 %20, -1
%24 = add i64 %13, %23
%25 = tail call i8* @bisect_end(i8* %22, i64 %24, i8* %2)
%26 = icmp eq i32 %15, 0
%27 = icmp eq i8* %25, null
%28 = select i1 %26, i1 %27, i1 false
%29 = select i1 %28, i8* %22, i8* %25
br label %17
}