#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_start(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_start(line_start + line_size + 1,
                        data_size - mid - line_size - 1, pattern);
  } else {
    const char *start = bisect_start(data, mid, pattern);
    if (compare == 0 && start == NULL)
      start = line_start;
    return start;
  }
}


x86 assembly (clang, -O0):
<bisect_start>:
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_start+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    1237 <bisect_start+0xf7>
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)
jle    11fd <bisect_start+0xbd>
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_start@plt>
mov    %rax,-0x8(%rbp)
jmp    1237 <bisect_start+0xf7>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <bisect_start@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    122f <bisect_start+0xef>
cmpq   $0x0,-0x40(%rbp)
jne    122f <bisect_start+0xef>
mov    -0x30(%rbp),%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_start>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
cmp    $0x2,%rsi
jb     11b1 <bisect_start+0x71>
mov    %rsi,%rbx
mov    %rdi,%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rsi
shr    %rsi
mov    %r12,%rdi
call   1050 <find_line_start@plt>
mov    %rax,%r13
mov    %rax,%rbp
sub    %r12,%rbp
sub    %rbp,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <find_line_size@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %eax,%esi
mov    (%rsp),%rdx
call   1060 <match@plt>
test   %eax,%eax
jle    11b5 <bisect_start+0x75>
movslq %r15d,%rax
lea    (%rax,%r13,1),%r12
add    $0x1,%r12
not    %rax
add    %rax,%rbx
cmp    $0x1,%rbx
ja     1160 <bisect_start+0x20>
xor    %eax,%eax
jmp    11d8 <bisect_start+0x98>
mov    %eax,%r14d
mov    %r12,%rdi
mov    %rbp,%rsi
mov    (%rsp),%rdx
call   1030 <bisect_start@plt>
test   %rax,%rax
cmovne %rax,%r13
test   %r14d,%r14d
cmovne %rax,%r13
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bisect_start(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 %67
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 sgt i32 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %16
%39 = load i8*, i8** %9
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i64, i64* %6
%45 = load i64, i64* %8
%46 = sub i64 %44, %45
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = sub i64 %46, %48
%50 = sub i64 %49, 1
%51 = load i8*, i8** %7
%52 = call i8* @bisect_start(i8* %43, i64 %50, i8* %51)
store i8* %52, i8** %4
br label %67
53: ; preds = %16
%54 = load i8*, i8** %5
%55 = load i64, i64* %8
%56 = load i8*, i8** %7
%57 = call i8* @bisect_start(i8* %54, 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 %65
60: ; preds = %53
%61 = load i8*, i8** %12
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = load i8*, i8** %9
store i8* %64, i8** %12
br label %65
65: ; preds = %63, %60, %53
%66 = load i8*, i8** %12
store i8* %66, i8** %4
br label %67
67: ; preds = %65, %38, %15
%68 = load i8*, i8** %4
ret i8* %68
}

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