#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 */
char getchar();
int /*<<< orphan*/ printf(char *, int);
int guess_itr(int lb, int ub) {
  char answer;
  int mid;
  while (ub != lb) {
    mid = (ub + lb) / 2;
    printf("Is the number greater than %d? (Y/N)\n", mid);
    answer = getchar();
    while (getchar() != '\n')
      ;
    if (answer == 'N') {
      ub = mid;
    } else {
      lb = mid + 1;
    }
  }
  return lb;
}


x86 assembly (clang, -O0):
<guess_itr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     11a2 <guess_itr+0x82>
mov    -0x8(%rbp),%eax
add    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x9(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     117c <guess_itr+0x5c>
jmp    1164 <guess_itr+0x44>
movsbl -0x9(%rbp),%eax
cmp    $0x4e,%eax
jne    1194 <guess_itr+0x74>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    119d <guess_itr+0x7d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112e <guess_itr+0xe>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_itr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
cmp    %edi,%esi
je     1182 <guess_itr+0x62>
mov    %edi,%r14d
lea    0xec7(%rip),%r15
nopl   0x0(%rax)
lea    (%r14,%r12,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1160 <guess_itr+0x40>
cmp    $0x4e,%bpl
cmove  %ebx,%r12d
lea    0x1(%rbx),%eax
cmove  %r14d,%eax
mov    %eax,%r14d
cmp    %eax,%r12d
jne    1140 <guess_itr+0x20>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Is the number greater than %d? (Y/N)\0A\00"
define i32 @guess_itr(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %7
7: ; preds = %33, %2
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = add nsw i32 %12, %13
%15 = sdiv i32 %14, 2
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call signext i8 (...) @getchar()
store i8 %18, i8* %5
br label %19
19: ; preds = %23, %11
%20 = call signext i8 (...) @getchar()
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %19
br label %19
24: ; preds = %19
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 78
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i32, i32* %6
store i32 %29, i32* %4
br label %33
30: ; preds = %24
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %30, %28
br label %7
34: ; preds = %7
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [38 x i8] c"Is the number greater than %d? (Y/N)\0A\00"
define i32 @guess_itr(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, %0
br i1 %3, label %20, label %4
4: ; preds = %2, %14
%5 = phi i32 [ %18, %14 ], [ %0, %2 ]
%6 = phi i32 [ %17, %14 ], [ %1, %2 ]
%7 = add nsw i32 %5, %6
%8 = sdiv i32 %7, 2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call signext i8 (...) @getchar()
br label %11
11: ; preds = %11, %4
%12 = tail call signext i8 (...) @getchar()
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %11
14: ; preds = %11
%15 = icmp eq i8 %10, 78
%16 = add nsw i32 %8, 1
%17 = select i1 %15, i32 %8, i32 %6
%18 = select i1 %15, i32 %5, i32 %16
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %4
20: ; preds = %14, %2
%21 = phi i32 [ %1, %2 ], [ %17, %14 ]
ret i32 %21
}