#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 MAP_ANONYMOUS;
char *MAP_FAILED;
int MAP_PRIVATE;
int /*<<< orphan*/ PROT_WRITE;
char *mmap(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/, int,
           int /*<<< orphan*/, int /*<<< orphan*/);
size_t search(size_t begin, size_t end) {
  while (begin < end) {
    size_t mid = begin + (end - begin) / 2;
    char *m = mmap(NULL, mid, PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
    if (m == MAP_FAILED) {
      end = mid;
    } else {
      begin = mid + 1;
    }
  }
  return end;
}


x86 assembly (clang, -O0):
<search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a9 <search+0x99>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    -0x8(%rbp),%rcx
shr    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
mov    0x2e86(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <search+0x88>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11a4 <search+0x94>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1120 <search+0x10>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    %rdi,%rsi
jbe    118c <search+0x7c>
mov    %rdi,%r15
mov    0x2ebb(%rip),%rbp
mov    0x2e94(%rip),%r12
jmp    114c <search+0x3c>
cs nopw 0x0(%rax,%rax,1)
add    %r14,%r15
add    $0x1,%r15
cmp    %r15,%r13
jbe    118c <search+0x7c>
mov    %r13,%r14
sub    %r15,%r14
shr    %r14
lea    (%r14,%r15,1),%rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%edx
mov    0x0(%rbp),%ecx
mov    0x2e64(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    (%r12),%rax
jne    1140 <search+0x30>
mov    %rbx,%r13
cmp    %r15,%r13
ja     114c <search+0x3c>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
define i64 @search(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
br label %7
7: ; preds = %32, %2
%8 = load i64, i64* %3
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %33
11: ; preds = %7
%12 = load i64, i64* %3
%13 = load i64, i64* %4
%14 = load i64, i64* %3
%15 = sub i64 %13, %14
%16 = udiv i64 %15, 2
%17 = add i64 %12, %16
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = load i32, i32* @PROT_WRITE
%20 = load i32, i32* @MAP_PRIVATE
%21 = load i32, i32* @MAP_ANONYMOUS
%22 = or i32 %20, %21
%23 = call i8* @mmap(i32* null, i64 %18, i32 %19, i32 %22, i32 0, i32 0)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = load i8*, i8** @MAP_FAILED
%26 = icmp eq i8* %24, %25
br i1 %26, label %27, label %29
27: ; preds = %11
%28 = load i64, i64* %5
store i64 %28, i64* %4
br label %32
29: ; preds = %11
%30 = load i64, i64* %5
%31 = add i64 %30, 1
store i64 %31, i64* %3
br label %32
32: ; preds = %29, %27
br label %7
33: ; preds = %7
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_FAILED = global i8* null
define i64 @search(i64 %0, i64 %1) {
%3 = icmp ugt i64 %1, %0
br i1 %3, label %4, label %21
4: ; preds = %2, %4
%5 = phi i64 [ %19, %4 ], [ %0, %2 ]
%6 = phi i64 [ %18, %4 ], [ %1, %2 ]
%7 = sub i64 %6, %5
%8 = lshr i64 %7, 1
%9 = add i64 %8, %5
%10 = load i32, i32* @PROT_WRITE
%11 = load i32, i32* @MAP_PRIVATE
%12 = load i32, i32* @MAP_ANONYMOUS
%13 = or i32 %12, %11
%14 = tail call i8* @mmap(i32* null, i64 %9, i32 %10, i32 %13, i32 0, i32 0)
%15 = load i8*, i8** @MAP_FAILED
%16 = icmp eq i8* %14, %15
%17 = add i64 %9, 1
%18 = select i1 %16, i64 %9, i64 %6
%19 = select i1 %16, i64 %5, i64 %17
%20 = icmp ugt i64 %18, %19
br i1 %20, label %4, label %21
21: ; preds = %4, %2
%22 = phi i64 [ %1, %2 ], [ %18, %4 ]
ret i64 %22
}