#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 /*<<< orphan*/ i_disable();
int /*<<< orphan*/ i_enable();
scalar_t__ jmm_test_cell(unsigned int);
unsigned int jmm_test_mem(unsigned int low) {
  i_disable();
  unsigned int high = low + 0x100000;
  while (high > low) {
    if (jmm_test_cell(high)) {
      unsigned int l = high - low;
      low = high + 1;
      high = high + l * 2;
    } else {
      unsigned int m = (high + low) / 2;
      if (jmm_test_cell(m))
        low = m + 1;
      else
        high = m - 1;
    }
  }
  i_enable();
  return low;
}


x86 assembly (clang, -O0):
<jmm_test_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <i_disable@plt>
mov    -0x4(%rbp),%eax
add    $0x100000,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jbe    11cf <jmm_test_mem+0x9f>
mov    -0x8(%rbp),%edi
call   1050 <jmm_test_cell@plt>
cmp    $0x0,%rax
je     1190 <jmm_test_mem+0x60>
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    11ca <jmm_test_mem+0x9a>
mov    -0x8(%rbp),%eax
add    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <jmm_test_cell@plt>
cmp    $0x0,%rax
je     11bc <jmm_test_mem+0x8c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <jmm_test_mem+0x95>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ca <jmm_test_mem+0x9a>
jmp    114d <jmm_test_mem+0x1d>
mov    $0x0,%al
call   1030 <i_enable@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jmm_test_mem>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %eax,%eax
call   1040 <i_disable@plt>
cmp    $0xffefffff,%r14d
ja     1191 <jmm_test_mem+0x61>
lea    0x100000(%r14),%ebx
jmp    1164 <jmm_test_mem+0x34>
mov    %ebx,%eax
sub    %r14d,%eax
mov    %ebx,%r14d
add    $0x1,%r14d
lea    (%rbx,%rax,2),%ebx
cmp    %r14d,%ebx
jbe    1191 <jmm_test_mem+0x61>
mov    %ebx,%edi
call   1050 <jmm_test_cell@plt>
test   %rax,%rax
jne    1150 <jmm_test_mem+0x20>
lea    (%r14,%rbx,1),%ebp
shr    %ebp
mov    %ebp,%edi
call   1050 <jmm_test_cell@plt>
test   %rax,%rax
je     118a <jmm_test_mem+0x5a>
add    $0x1,%ebp
mov    %ebp,%r14d
jmp    115f <jmm_test_mem+0x2f>
add    $0xffffffff,%ebp
mov    %ebp,%ebx
jmp    115f <jmm_test_mem+0x2f>
xor    %eax,%eax
call   1030 <i_enable@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @jmm_test_mem(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 (...) @i_disable()
%7 = load i32, i32* %2
%8 = add i32 %7, 1048576
store i32 %8, i32* %3
br label %9
9: ; preds = %42, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp ugt i32 %10, %11
br i1 %12, label %13, label %43
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i64 @jmm_test_cell(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = sub i32 %18, %19
store i32 %20, i32* %4
%21 = load i32, i32* %3
%22 = add i32 %21, 1
store i32 %22, i32* %2
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = mul i32 %24, 2
%26 = add i32 %23, %25
store i32 %26, i32* %3
br label %42
27: ; preds = %13
%28 = load i32, i32* %3
%29 = load i32, i32* %2
%30 = add i32 %28, %29
%31 = udiv i32 %30, 2
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = call i64 @jmm_test_cell(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = load i32, i32* %5
%37 = add i32 %36, 1
store i32 %37, i32* %2
br label %41
38: ; preds = %27
%39 = load i32, i32* %5
%40 = sub i32 %39, 1
store i32 %40, i32* %3
br label %41
41: ; preds = %38, %35
br label %42
42: ; preds = %41, %17
br label %9
43: ; preds = %9
%44 = call i32 (...) @i_enable()
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
define i32 @jmm_test_mem(i32 %0) {
%2 = tail call i32 (...) @i_disable()
%3 = icmp ult i32 %0, -1048576
br i1 %3, label %4, label %29
4: ; preds = %1
%5 = add nuw i32 %0, 1048576
br label %6
6: ; preds = %4, %25
%7 = phi i32 [ %27, %25 ], [ %0, %4 ]
%8 = phi i32 [ %26, %25 ], [ %5, %4 ]
%9 = tail call i64 @jmm_test_cell(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %6
%12 = sub i32 %8, %7
%13 = add i32 %8, 1
%14 = shl i32 %12, 1
%15 = add i32 %14, %8
br label %25
16: ; preds = %6
%17 = add i32 %7, %8
%18 = lshr i32 %17, 1
%19 = tail call i64 @jmm_test_cell(i32 %18)
%20 = icmp eq i64 %19, 0
%21 = add nuw i32 %18, 1
%22 = add nsw i32 %18, -1
%23 = select i1 %20, i32 %22, i32 %8
%24 = select i1 %20, i32 %7, i32 %21
br label %25
25: ; preds = %16, %11
%26 = phi i32 [ %15, %11 ], [ %23, %16 ]
%27 = phi i32 [ %13, %11 ], [ %24, %16 ]
%28 = icmp ugt i32 %26, %27
br i1 %28, label %6, label %29
29: ; preds = %25, %1
%30 = phi i32 [ %0, %1 ], [ %27, %25 ]
%31 = tail call i32 (...) @i_enable()
ret i32 %30
}