#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 guess(int);
int guessNumber(int n) {
  int lo = 1;
  int hi = n;
  while (lo < hi) {
    int mid = lo + (hi - lo) / 2;
    int g = guess(mid);
    if (g == 0)
      return mid;
    if (g == -1)
      hi = mid - 1;
    if (g == 1)
      lo = mid + 1;
  }
  return lo;
}


x86 assembly (clang, -O0):
<guessNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119d <guessNumber+0x8d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <guess@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1172 <guessNumber+0x62>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <guessNumber+0x93>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1185 <guessNumber+0x75>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1198 <guessNumber+0x88>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1128 <guessNumber+0x18>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guessNumber>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     1167 <guessNumber+0x57>
mov    %edi,%r14d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%eax
sub    %ebx,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
add    %ebx,%ebp
mov    %ebp,%edi
call   1030 <guess@plt>
test   %eax,%eax
je     1165 <guessNumber+0x55>
lea    -0x1(%rbp),%ecx
cmp    $0xffffffff,%eax
cmove  %ecx,%r14d
add    $0x1,%ebp
cmp    $0x1,%eax
cmove  %ebp,%ebx
cmp    %ebx,%r14d
jg     1130 <guessNumber+0x20>
jmp    1167 <guessNumber+0x57>
mov    %ebp,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @guessNumber(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %4
%8 = load i32, i32* %3
store i32 %8, i32* %5
br label %9
9: ; preds = %38, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = sub nsw i32 %15, %16
%18 = sdiv i32 %17, 2
%19 = add nsw i32 %14, %18
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i32 @guess(i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = load i32, i32* %6
store i32 %25, i32* %2
br label %41
26: ; preds = %13
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %29, %26
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %38
38: ; preds = %35, %32
br label %9
39: ; preds = %9
%40 = load i32, i32* %4
store i32 %40, i32* %2
br label %41
41: ; preds = %39, %24
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
define i32 @guessNumber(i32 %0) {
%2 = icmp sgt i32 %0, 1
br i1 %2, label %3, label %19
3: ; preds = %1, %11
%4 = phi i32 [ %17, %11 ], [ 1, %1 ]
%5 = phi i32 [ %14, %11 ], [ %0, %1 ]
%6 = sub nsw i32 %5, %4
%7 = sdiv i32 %6, 2
%8 = add nsw i32 %7, %4
%9 = tail call i32 @guess(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %3
%12 = icmp eq i32 %9, -1
%13 = add nsw i32 %8, -1
%14 = select i1 %12, i32 %13, i32 %5
%15 = icmp eq i32 %9, 1
%16 = add nsw i32 %8, 1
%17 = select i1 %15, i32 %16, i32 %4
%18 = icmp sgt i32 %14, %17
br i1 %18, label %3, label %19
19: ; preds = %11, %3, %1
%20 = phi i32 [ 1, %1 ], [ %8, %3 ], [ %17, %11 ]
ret i32 %20
}