#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 /*<<< orphan*/ printf(char *, ...);
char readChar();
int main() {
  char replay;
  int numGuesses = 0, numGames = 0;
  int lowerBound = 1, upperBound = 100, guess = 0;
  do {
    numGames++;
    printf("Guess a number between 1 and 100 (both inclusive) and get ready to "
           "answer a few questions\n");
    int lowerBound = 1, upperBound = 100, guess = 0;
    while (lowerBound < upperBound) {
      numGuesses++;
      guess = (upperBound - lowerBound) / 2 + lowerBound;
      printf("How about %d (<,=,>)? ", guess);
      char response = readChar();
      switch (response) {
      case '=':
        lowerBound = upperBound = guess;
        break;
      case '<':
        upperBound = guess;
        break;
      case '>':
        lowerBound = guess;
        break;
      default:
        printf("That is not a valid response.\n");
      }
      if (upperBound < 1)
        upperBound == 1;
      else if (upperBound > 100)
        upperBound == 100;
      if (lowerBound < 1)
        lowerBound == 1;
      else if (lowerBound > 100)
        lowerBound == 100;
    }
    printf("Your number is %d!\nThat was a good game.", guess);
    printf("Do you want to play again (y/n) ? ");
    replay = readChar();
  } while (replay != 'n');
  printf("The average number of guesses was %f\n",
         numGuesses / (float)numGames);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x64,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x20(%rbp)
movl   $0x64,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1272 <main+0x152>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
add    %edx,%eax
sar    %eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xea8(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <printf@plt>
mov    -0x31(%rbp),%al
call   1040 <readChar@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x3c,%eax
je     120d <main+0xed>
jmp    11dd <main+0xbd>
mov    -0x30(%rbp),%eax
sub    $0x3d,%eax
je     11ff <main+0xdf>
jmp    11ee <main+0xce>
mov    -0x30(%rbp),%eax
sub    $0x3e,%eax
je     1218 <main+0xf8>
jmp    1223 <main+0x103>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    %eax,-0x20(%rbp)
jmp    1231 <main+0x111>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1231 <main+0x111>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1231 <main+0x111>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x24(%rbp)
jge    1240 <main+0x120>
jmp    124f <main+0x12f>
cmpl   $0x64,-0x24(%rbp)
jle    124a <main+0x12a>
jmp    124f <main+0x12f>
cmpl   $0x1,-0x20(%rbp)
jge    125e <main+0x13e>
jmp    126d <main+0x14d>
cmpl   $0x64,-0x20(%rbp)
jle    1268 <main+0x148>
jmp    126d <main+0x14d>
jmp    117e <main+0x5e>
mov    -0x28(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <readChar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x6e,%eax
jne    1152 <main+0x32>
cvtsi2ssl -0xc(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe1c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rbx
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    1181 <main+0x51>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14d
lea    0xebc(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <readChar@plt>
cmp    $0x6e,%al
je     1215 <main+0xe5>
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r15d
mov    $0x1,%r12d
mov    $0x64,%r13d
mov    %r15d,%eax
jmp    11bc <main+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%r13d
lea    0x1(%r15),%eax
cmp    %r12d,%r13d
jle    1150 <main+0x20>
mov    %eax,%r15d
mov    %r13d,%eax
sub    %r12d,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
add    %r12d,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <readChar@plt>
movsbl %al,%eax
cmp    $0x3c,%eax
je     11b0 <main+0x80>
cmp    $0x3e,%eax
je     1210 <main+0xe0>
cmp    $0x3d,%eax
je     1150 <main+0x20>
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
jmp    11b3 <main+0x83>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r12d
jmp    11b3 <main+0x83>
cvtsi2ss %r15d,%xmm0
cvtsi2ss %r14d,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe35(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [91 x i8] c"Guess a number between 1 and 100 (both inclusive) and get ready to answer a few questions\0A\00"
@.str.1 = [23 x i8] c"How about %d (<,=,>)? \00"
@.str.2 = [31 x i8] c"That is not a valid response.\0A\00"
@.str.3 = [41 x i8] c"Your number is %d!\0AThat was a good game.\00"
@.str.4 = [35 x i8] c"Do you want to play again (y/n) ? \00"
@.str.5 = [38 x i8] c"The average number of guesses was %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 1, i32* %5
store i32 100, i32* %6
store i32 0, i32* %7
br label %12
12: ; preds = %78, %0
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %8
store i32 100, i32* %9
store i32 0, i32* %10
br label %16
16: ; preds = %72, %12
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %73
20: ; preds = %16
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = load i32, i32* %9
%24 = load i32, i32* %8
%25 = sub nsw i32 %23, %24
%26 = sdiv i32 %25, 2
%27 = load i32, i32* %8
%28 = add nsw i32 %26, %27
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = call signext i8 (...) @readChar()
store i8 %31, i8* %11
%32 = load i8, i8* %11
%33 = sext i8 %32 to i32
switch i32 %33, label %40 [
i32 61, label %34
i32 60, label %36
i32 62, label %38
]
34: ; preds = %20
%35 = load i32, i32* %10
store i32 %35, i32* %9
store i32 %35, i32* %8
br label %42
36: ; preds = %20
%37 = load i32, i32* %10
store i32 %37, i32* %9
br label %42
38: ; preds = %20
%39 = load i32, i32* %10
store i32 %39, i32* %8
br label %42
40: ; preds = %20
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %38, %36, %34
%43 = load i32, i32* %9
%44 = icmp slt i32 %43, 1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 1
%48 = zext i1 %47 to i32
br label %57
49: ; preds = %42
%50 = load i32, i32* %9
%51 = icmp sgt i32 %50, 100
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, 100
%55 = zext i1 %54 to i32
br label %56
56: ; preds = %52, %49
br label %57
57: ; preds = %56, %45
%58 = load i32, i32* %8
%59 = icmp slt i32 %58, 1
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = load i32, i32* %8
%62 = icmp eq i32 %61, 1
%63 = zext i1 %62 to i32
br label %72
64: ; preds = %57
%65 = load i32, i32* %8
%66 = icmp sgt i32 %65, 100
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = load i32, i32* %8
%69 = icmp eq i32 %68, 100
%70 = zext i1 %69 to i32
br label %71
71: ; preds = %67, %64
br label %72
72: ; preds = %71, %60
br label %16
73: ; preds = %16
%74 = load i32, i32* %10
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%77 = call signext i8 (...) @readChar()
store i8 %77, i8* %2
br label %78
78: ; preds = %73
%79 = load i8, i8* %2
%80 = sext i8 %79 to i32
%81 = icmp ne i32 %80, 110
br i1 %81, label %12, label %82
82: ; preds = %78
%83 = load i32, i32* %3
%84 = sitofp i32 %83 to float
%85 = load i32, i32* %4
%86 = sitofp i32 %85 to float
%87 = fdiv float %84, %86
%88 = fpext float %87 to double
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), double %88)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [23 x i8] c"How about %d (<,=,>)? \00"
@.str.3 = [41 x i8] c"Your number is %d!\0AThat was a good game.\00"
@.str.4 = [35 x i8] c"Do you want to play again (y/n) ? \00"
@.str.5 = [38 x i8] c"The average number of guesses was %f\0A\00"
@str = [90 x i8] c"Guess a number between 1 and 100 (both inclusive) and get ready to answer a few questions\00"
@str.6 = [30 x i8] c"That is not a valid response.\00"
define i32 @main() {
br label %1
1: ; preds = %23, %0
%2 = phi i32 [ 0, %0 ], [ %24, %23 ]
%3 = phi i32 [ 0, %0 ], [ %9, %23 ]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %1, %19
%6 = phi i32 [ 100, %1 ], [ %21, %19 ]
%7 = phi i32 [ 1, %1 ], [ %20, %19 ]
%8 = phi i32 [ %3, %1 ], [ %9, %19 ]
%9 = add nsw i32 %8, 1
%10 = sub nsw i32 %6, %7
%11 = sdiv i32 %10, 2
%12 = add nsw i32 %11, %7
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call signext i8 (...) @readChar()
%15 = sext i8 %14 to i32
switch i32 %15, label %17 [
i32 61, label %23
i32 60, label %19
i32 62, label %16
]
16: ; preds = %5
br label %19
17: ; preds = %5
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
br label %19
19: ; preds = %5, %17, %16
%20 = phi i32 [ %7, %17 ], [ %12, %16 ], [ %7, %5 ]
%21 = phi i32 [ %6, %17 ], [ %6, %16 ], [ %12, %5 ]
%22 = icmp sgt i32 %21, %20
br i1 %22, label %5, label %23
23: ; preds = %5, %19
%24 = add nuw nsw i32 %2, 1
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call signext i8 (...) @readChar()
%28 = icmp eq i8 %27, 110
br i1 %28, label %29, label %1
29: ; preds = %23
%30 = sitofp i32 %9 to float
%31 = sitofp i32 %24 to float
%32 = fdiv float %30, %31
%33 = fpext float %32 to double
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), double %33)
ret i32 0
}