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


x86 assembly (clang, -O0):
<guessNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ab <guessNumber+0x9b>
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    1180 <guessNumber+0x70>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <guessNumber+0xa1>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1198 <guessNumber+0x88>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a1 <guessNumber+0x91>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a6 <guessNumber+0x96>
jmp    1136 <guessNumber+0x26>
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
test   %edi,%edi
jle    1157 <guessNumber+0x47>
mov    %edi,%r14d
xor    %ebp,%ebp
jmp    112b <guessNumber+0x1b>
nop
add    $0xffffffff,%ebx
mov    %ebx,%r14d
cmp    %ebp,%r14d
jle    115d <guessNumber+0x4d>
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>
cmp    $0xffffffff,%eax
je     1120 <guessNumber+0x10>
test   %eax,%eax
je     115b <guessNumber+0x4b>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %ebp,%r14d
jg     112b <guessNumber+0x1b>
jmp    115d <guessNumber+0x4d>
xor    %ebp,%ebp
jmp    115d <guessNumber+0x4d>
mov    %ebx,%ebp
mov    %ebp,%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 0, i32* %4
%8 = load i32, i32* %3
store i32 %8, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %36, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %37
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 %39
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 %35
32: ; preds = %26
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35
br label %9
37: ; preds = %9
%38 = load i32, i32* %4
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %24
%40 = load i32, i32* %2
ret i32 %40
}

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