#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 */
scalar_t__ guess(int);
int guessNumber(int n) {
  int l = 1;
  int r = n;
  int m = 0;
  while (l <= r) {
    m = l + (r - l) / 2;
    if (guess(m) > 0) {
      l = m + 1;
    } else if (guess(m) == 0) {
      return m;
    } else {
      r = m - 1;
    }
  }
  return m;
}


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)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11a9 <guessNumber+0x99>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <guess@plt>
cmp    $0x0,%rax
jle    1179 <guessNumber+0x69>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a4 <guessNumber+0x94>
mov    -0x14(%rbp),%edi
call   1030 <guess@plt>
cmp    $0x0,%rax
jne    1196 <guessNumber+0x86>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <guessNumber+0x9f>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a4 <guessNumber+0x94>
jmp    112f <guessNumber+0x1f>
mov    -0x14(%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
test   %edi,%edi
jle    116b <guessNumber+0x5b>
mov    %edi,%r14d
mov    $0x1,%ebp
jmp    1138 <guessNumber+0x28>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%ebp
cmp    %ebp,%r14d
jl     116d <guessNumber+0x5d>
mov    %r14d,%eax
sub    %ebp,%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
add    %ebp,%ebx
mov    %ebx,%edi
call   1030 <guess@plt>
test   %rax,%rax
jg     1130 <guessNumber+0x20>
mov    %ebx,%edi
call   1030 <guess@plt>
test   %rax,%rax
je     116d <guessNumber+0x5d>
lea    -0x1(%rbx),%r14d
cmp    %ebp,%r14d
jge    1138 <guessNumber+0x28>
jmp    116d <guessNumber+0x5d>
xor    %ebx,%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
store i32 %0, i32* %3
store i32 1, i32* %4
%7 = load i32, i32* %3
store i32 %7, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %35, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %8
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = sub nsw i32 %14, %15
%17 = sdiv i32 %16, 2
%18 = add nsw i32 %13, %17
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i64 @guess(i32 %19)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %35
25: ; preds = %12
%26 = load i32, i32* %6
%27 = call i64 @guess(i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i32, i32* %6
store i32 %30, i32* %2
br label %38
31: ; preds = %25
%32 = load i32, i32* %6
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %5
br label %34
34: ; preds = %31
br label %35
35: ; preds = %34, %22
br label %8
36: ; preds = %8
%37 = load i32, i32* %6
store i32 %37, i32* %2
br label %38
38: ; preds = %36, %29
%39 = load i32, i32* %2
ret i32 %39
}

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