#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();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int number, guess, down = 0, up = 100;
  srand((unsigned)time(NULL));
  number = rand() % 100 + 1;
  printf("Guess a number (1-100) :: ");
  int done = 0;
  do {
    scanf("%d", &guess);
    if (guess < 1 || guess > 100) {
      printf("\nERROR: Out of bounds");
      printf("\nGuess a number (1-100) :: ");
    } else {
      if (guess == number) {
        printf("\nGood guess - you win!");
        done = !done;
      } else if (guess <= down) {
        printf("\nTHINK! - I already told you that the number is > %d", guess);
        printf("\nGuess a number (1-100) :: ");
      } else if (guess >= up) {
        printf("\nTHINK! - I already told you that the number is < %d", guess);
        printf("\nGuess a number (1-100) :: ");
      } else if (guess > number) {
        printf("\nLower than %d; guess again :: ", guess);
        up = guess;
      } else {
        printf("\nHigher than %d; guess again :: ", guess);
        down = guess;
      }
    }
  } while (!done);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
lea    0xf02(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x1,-0xc(%rbp)
jl     11cb <main+0x7b>
cmpl   $0x64,-0xc(%rbp)
jle    11ec <main+0x9c>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12cf <main+0x17f>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    121c <main+0xcc>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
jmp    12ca <main+0x17a>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     124c <main+0xfc>
mov    -0xc(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c5 <main+0x175>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     127c <main+0x12c>
mov    -0xc(%rbp),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c0 <main+0x170>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    12a4 <main+0x154>
mov    -0xc(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12bb <main+0x16b>
mov    -0xc(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    12c0 <main+0x170>
jmp    12c5 <main+0x175>
jmp    12ca <main+0x17a>
jmp    12cf <main+0x17f>
jmp    12d4 <main+0x184>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a7 <main+0x57>
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
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x64,%r13d
lea    0xf04(%rip),%r14
lea    0x4(%rsp),%rbx
lea    0xe5e(%rip),%r12
xor    %r15d,%r15d
jmp    11d8 <main+0x88>
nopl   (%rax)
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
lea    -0x65(%rsi),%eax
cmp    $0xffffff9b,%eax
jbe    11c0 <main+0x70>
cmp    %ebp,%esi
je     124e <main+0xfe>
cmp    %r15d,%esi
jle    1210 <main+0xc0>
cmp    %r13d,%esi
jl     1220 <main+0xd0>
lea    0xe7a(%rip),%rdi
jmp    1217 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11ce <main+0x7e>
cmp    %ebp,%esi
jle    1239 <main+0xe9>
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%r13d
jmp    11d8 <main+0x88>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%r15d
jmp    11d8 <main+0x88>
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1030 <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 = [27 x i8] c"Guess a number (1-100) :: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"\0AERROR: Out of bounds\00"
@.str.3 = [28 x i8] c"\0AGuess a number (1-100) :: \00"
@.str.4 = [23 x i8] c"\0AGood guess - you win!\00"
@.str.5 = [53 x i8] c"\0ATHINK! - I already told you that the number is > %d\00"
@.str.6 = [53 x i8] c"\0ATHINK! - I already told you that the number is < %d\00"
@.str.7 = [32 x i8] c"\0ALower than %d; guess again :: \00"
@.str.8 = [33 x i8] c"\0AHigher than %d; guess again :: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
store i32 100, i32* %5
%7 = call i64 @time(i32* null)
%8 = trunc i64 %7 to i32
%9 = call i32 @srand(i32 %8)
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = add nsw i32 %11, 1
store i32 %12, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %14
14: ; preds = %67, %0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 1
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 100
br i1 %20, label %21, label %24
21: ; preds = %18, %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %66
24: ; preds = %18
%25 = load i32, i32* %3
%26 = load i32, i32* %2
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
%33 = zext i1 %32 to i32
store i32 %33, i32* %6
br label %65
34: ; preds = %24
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %3
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %64
42: ; preds = %34
%43 = load i32, i32* %3
%44 = load i32, i32* %5
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* %3
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %63
50: ; preds = %42
%51 = load i32, i32* %3
%52 = load i32, i32* %2
%53 = icmp sgt i32 %51, %52
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* %3
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %3
store i32 %57, i32* %5
br label %62
58: ; preds = %50
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %3
store i32 %61, i32* %4
br label %62
62: ; preds = %58, %54
br label %63
63: ; preds = %62, %46
br label %64
64: ; preds = %63, %38
br label %65
65: ; preds = %64, %28
br label %66
66: ; preds = %65, %21
br label %67
67: ; preds = %66
%68 = load i32, i32* %6
%69 = icmp ne i32 %68, 0
%70 = xor i1 %69, true
br i1 %70, label %14, label %71
71: ; preds = %67
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Guess a number (1-100) :: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"\0AERROR: Out of bounds\00"
@.str.3 = [28 x i8] c"\0AGuess a number (1-100) :: \00"
@.str.4 = [23 x i8] c"\0AGood guess - you win!\00"
@.str.5 = [53 x i8] c"\0ATHINK! - I already told you that the number is > %d\00"
@.str.6 = [53 x i8] c"\0ATHINK! - I already told you that the number is < %d\00"
@.str.7 = [32 x i8] c"\0ALower than %d; guess again :: \00"
@.str.8 = [33 x i8] c"\0AHigher than %d; guess again :: \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 100
%8 = add nsw i32 %7, 1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %41, %0
%11 = phi i32 [ %43, %41 ], [ 0, %0 ]
%12 = phi i32 [ %14, %41 ], [ 100, %0 ]
br label %13
13: ; preds = %10, %38
%14 = phi i32 [ %12, %10 ], [ %40, %38 ]
br label %15
15: ; preds = %23, %13
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = add i32 %17, -101
%19 = icmp ult i32 %18, -100
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %20, %28, %33
br label %15
24: ; preds = %15
%25 = icmp eq i32 %17, %8
br i1 %25, label %44, label %26
26: ; preds = %24
%27 = icmp sgt i32 %17, %11
br i1 %27, label %31, label %28
28: ; preds = %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %23
31: ; preds = %26
%32 = icmp slt i32 %17, %14
br i1 %32, label %36, label %33
33: ; preds = %31
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %23
36: ; preds = %31
%37 = icmp sgt i32 %17, %8
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %17)
%40 = load i32, i32* %1
br label %13
41: ; preds = %36
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %17)
%43 = load i32, i32* %1
br label %10
44: ; preds = %24
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}