#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 *, ...);
int rand();
char readChar();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  char replay;
  int numGuesses = 0, numGames = 0;
  do {
    numGames++;
    printf("I have thought about a number between 1 and 100 (both "
           "inclusive).\nYou can guess my number now..\n");
    srand(time(NULL));
    int number = (rand() % 100) + 1;
    int guess = -1;
    while (guess != number) {
      numGuesses++;
      scanf("%d", &guess);
      if (guess < number)
        printf("Too low.\n");
      if (guess > number)
        printf("Too high.\n");
    }
    printf("Yes it was %d - Good job!\nDo you want to play again (y/n) ? ",
           guess);
    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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     121e <main+0xbe>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe85(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ff <main+0x9f>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1219 <main+0xb9>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c0 <main+0x60>
mov    -0x18(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <readChar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x6e,%eax
jne    117d <main+0x1d>
cvtsi2ssl -0xc(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe57(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%r12
lea    0x4(%rsp),%rbx
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    11b4 <main+0x44>
xchg   %ax,%ax
add    $0x1,%r13d
lea    0xe68(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <readChar@plt>
cmp    $0x6e,%al
je     1257 <main+0xe7>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%r14d
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
mov    %eax,%ecx
neg    %ecx
lea    (%r14,%rcx,1),%r15d
add    $0x1,%r15d
movl   $0xffffffff,0x4(%rsp)
ff
cmp    $0xffffffff,%r15d
je     1190 <main+0x20>
sub    %eax,%r14d
jmp    121c <main+0xac>
add    $0x1,%ebp
cmp    %r15d,%eax
je     1190 <main+0x20>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %r14d,%eax
jg     1240 <main+0xd0>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%eax
cmp    %r15d,%eax
jle    1210 <main+0xa0>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%eax
jmp    1210 <main+0xa0>
cvtsi2ss %ebp,%xmm0
cvtsi2ss %r13d,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd1(%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 = [97 x i8] c"I have thought about a number between 1 and 100 (both inclusive).\0AYou can guess my number now..\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"Too low.\0A\00"
@.str.3 = [11 x i8] c"Too high.\0A\00"
@.str.4 = [61 x i8] c"Yes it was %d - Good job!\0ADo 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
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %40, %0
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
store i32 %9, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @time(i32* null)
%12 = call i32 @srand(i32 %11)
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 100
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
store i32 -1, i32* %6
br label %16
16: ; preds = %35, %7
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %20
%30 = load i32, i32* %6
%31 = load i32, i32* %5
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
br label %16
36: ; preds = %16
%37 = load i32, i32* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = call signext i8 (...) @readChar()
store i8 %39, i8* %2
br label %40
40: ; preds = %36
%41 = load i8, i8* %2
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 110
br i1 %43, label %7, label %44
44: ; preds = %40
%45 = load i32, i32* %3
%46 = sitofp i32 %45 to float
%47 = load i32, i32* %4
%48 = sitofp i32 %47 to float
%49 = fdiv float %46, %48
%50 = fpext float %49 to double
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), double %50)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [61 x i8] c"Yes it was %d - Good job!\0ADo you want to play again (y/n) ? \00"
@.str.5 = [38 x i8] c"The average number of guesses was %f\0A\00"
@str = [96 x i8] c"I have thought about a number between 1 and 100 (both inclusive).\0AYou can guess my number now..\00"
@str.6 = [10 x i8] c"Too high.\00"
@str.7 = [9 x i8] c"Too low.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %32, %0
%4 = phi i32 [ 0, %0 ], [ %33, %32 ]
%5 = phi i32 [ 0, %0 ], [ %6, %32 ]
%6 = add nuw nsw i32 %5, 1
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @str, i64 0, i64 0))
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = add nsw i32 %11, 1
store i32 -1, i32* %1
%13 = icmp eq i32 %12, -1
br i1 %13, label %32, label %14
14: ; preds = %3, %29
%15 = phi i32 [ %16, %29 ], [ %4, %3 ]
%16 = add nsw i32 %15, 1
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, %11
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
%22 = load i32, i32* %1
br label %23
23: ; preds = %20, %14
%24 = phi i32 [ %22, %20 ], [ %18, %14 ]
%25 = icmp sgt i32 %24, %12
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
%28 = load i32, i32* %1
br label %29
29: ; preds = %26, %23
%30 = phi i32 [ %28, %26 ], [ %24, %23 ]
%31 = icmp eq i32 %30, %12
br i1 %31, label %32, label %14
32: ; preds = %29, %3
%33 = phi i32 [ %4, %3 ], [ %16, %29 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%35 = call signext i8 (...) @readChar()
%36 = icmp eq i8 %35, 110
br i1 %36, label %37, label %3
37: ; preds = %32
%38 = sitofp i32 %33 to float
%39 = sitofp i32 %6 to float
%40 = fdiv float %38, %39
%41 = fpext float %40 to double
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), double %41)
ret i32 0
}