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


x86 assembly (clang, -O0):
<guess_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1155 <guess_rec+0x25>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <guess_rec+0x98>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1197 <guess_rec+0x67>
jmp    117f <guess_rec+0x4f>
movsbl -0xd(%rbp),%eax
cmp    $0x4e,%eax
jne    11b7 <guess_rec+0x87>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1050 <guess_rec@plt>
mov    %eax,-0x4(%rbp)
jmp    11c8 <guess_rec+0x98>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    -0xc(%rbp),%esi
call   1050 <guess_rec@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_rec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
cmp    %esi,%edi
jne    1134 <guess_rec+0x14>
mov    %r14d,%eax
jmp    1182 <guess_rec+0x62>
mov    %esi,%r12d
lea    0xec2(%rip),%r15
xchg   %ax,%ax
lea    (%r12,%r14,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_rec+0x40>
lea    0x1(%rbx),%eax
cmp    $0x4e,%bpl
cmove  %r14d,%eax
cmove  %ebx,%r12d
mov    %eax,%r14d
cmp    %r12d,%eax
jne    1140 <guess_rec+0x20>
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_rec(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %4
store i32 %12, i32* %3
br label %39
13: ; preds = %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = add nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call signext i8 (...) @getchar()
store i8 %20, i8* %6
br label %21
21: ; preds = %25, %13
%22 = call signext i8 (...) @getchar()
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %26
25: ; preds = %21
br label %21
26: ; preds = %21
%27 = load i8, i8* %6
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 78
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* %4
%32 = load i32, i32* %7
%33 = call i32 @guess_rec(i32 %31, i32 %32)
store i32 %33, i32* %3
br label %39
34: ; preds = %26
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %5
%38 = call i32 @guess_rec(i32 %36, i32 %37)
store i32 %38, i32* %3
br label %39
39: ; preds = %34, %30, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [38 x i8] c"Is the number greater than %d? (Y/N)\0A\00"
define i32 @guess_rec(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, %1
br i1 %3, label %20, label %4
4: ; preds = %2, %14
%5 = phi i32 [ %18, %14 ], [ %1, %2 ]
%6 = phi i32 [ %17, %14 ], [ %0, %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 %6, i32 %16
%18 = select i1 %15, i32 %8, i32 %5
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %4
20: ; preds = %14, %2
%21 = phi i32 [ %0, %2 ], [ %17, %14 ]
ret i32 %21
}