#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(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  srand(time(NULL));
  int x = 0;
  int i = 0;
  int guesses = 0;
  int max = 51;
  int min = 0;
  x = rand() % 51;
  system("clear");
  while (guesses < 5) {
    guesses = ++guesses;
    printf("Is your number %d? Enter 1 for too low, 2 for correct, or 3 for "
           "too high: ",
           x);
    scanf("%i", &i);
    if (i == 1) {
      min = ++x;
      if (max == min) {
        x = min;
        continue;
      }
      x = rand() % (max - min) + min;
    } else if (i == 2) {
      printf("Yay! I guessed right!\n");
      break;
    } else if (i == 3) {
      max = --x;
      if (max == min) {
        x = min;
        continue;
      }
      x = rand() % (max - min) + min;
    } else if (x != (3 | 2 | 1)) {
      printf("You have entered an incorrect value, please try again.\n");
      guesses -= 1;
    }
  }
  if (i != 2) {
    printf("Awww, I lost.\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x33,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x33,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
lea    0xe3e(%rip),%rdi
call   1030 <system@plt>
cmpl   $0x5,-0x1c(%rbp)
jge    12e0 <main+0x180>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5c(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1246 <main+0xe6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    122b <main+0xcb>
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11c7 <main+0x67>
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x20(%rbp),%ecx
sub    -0x24(%rbp),%ecx
cltd
idiv   %ecx
add    -0x24(%rbp),%edx
mov    %edx,-0x14(%rbp)
jmp    12db <main+0x17b>
cmpl   $0x2,-0x18(%rbp)
jne    1263 <main+0x103>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e0 <main+0x180>
cmpl   $0x3,-0x18(%rbp)
jne    12ab <main+0x14b>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1290 <main+0x130>
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11c7 <main+0x67>
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x20(%rbp),%ecx
sub    -0x24(%rbp),%ecx
cltd
idiv   %ecx
add    -0x24(%rbp),%edx
mov    %edx,-0x14(%rbp)
jmp    12d1 <main+0x171>
cmpl   $0x3,-0x14(%rbp)
je     12cc <main+0x16c>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12d1 <main+0x171>
jmp    12d6 <main+0x176>
jmp    12db <main+0x17b>
jmp    11c7 <main+0x67>
cmpl   $0x2,-0x18(%rbp)
je     12f8 <main+0x198>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%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   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rbx
imul   $0xffffffffa0a0a0a1,%rbx,%rax
shr    $0x20,%rax
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x33,%eax,%eax
sub    %eax,%ebx
lea    0xe42(%rip),%rdi
call   1040 <system@plt>
movl   $0x33,(%rsp)
xor    %r14d,%r14d
xor    %r12d,%r12d
mov    %r14d,%eax
cmp    $0x6,%eax
mov    $0x5,%r13d
cmovge %eax,%r13d
mov    %ebx,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %eax,%r13d
je     12df <main+0x16f>
mov    %eax,%r14d
lea    0xe03(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x1,%eax
jne    1260 <main+0xf0>
mov    %r15d,%ebp
add    $0x1,%ebp
lea    0x1(%r14),%eax
mov    (%rsp),%r12d
mov    %r12d,%ebx
mov    %r12d,%r15d
sub    %ebp,%ebx
je     11f0 <main+0x80>
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idiv   %ebx
mov    %edx,%ebx
add    %ebp,%ebx
add    $0x1,%r14d
mov    %r14d,%eax
mov    %ebp,%r12d
jmp    11d3 <main+0x63>
nopl   0x0(%rax)
cmp    $0x2,%eax
je     12d3 <main+0x163>
cmp    $0x3,%eax
je     12a0 <main+0x130>
lea    0x1(%r14),%eax
mov    $0x3,%ebx
cmp    $0x3,%r15d
je     11d3 <main+0x63>
lea    0xdde(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%ebx
jmp    11d0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%r15d
add    $0x1,%r14d
mov    %r15d,%ebp
mov    %r12d,%ebx
mov    %r12d,(%rsp)
sub    %r12d,%ebp
je     11d0 <main+0x60>
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idiv   %ebp
mov    %edx,%ebx
add    %r12d,%ebx
mov    %r15d,(%rsp)
jmp    11d0 <main+0x60>
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x2,0x4(%rsp)
je     12f2 <main+0x182>
lea    0xd67(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clear\00"
@.str.1 = [75 x i8] c"Is your number %d? Enter 1 for too low, 2 for correct, or 3 for too high: \00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [23 x i8] c"Yay! I guessed right!\0A\00"
@.str.4 = [56 x i8] c"You have entered an incorrect value, please try again.\0A\00"
@.str.5 = [15 x i8] c"Awww, I lost.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @time(i32* null)
%12 = call i32 @srand(i32 %11)
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 51, i32* %9
store i32 0, i32* %10
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 51
store i32 %14, i32* %6
%15 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %77, %57, %33, %2
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 5
br i1 %18, label %19, label %78
19: ; preds = %16
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
store i32 %21, i32* %8
store i32 %21, i32* %8
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %43
27: ; preds = %19
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
store i32 %29, i32* %10
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load i32, i32* %10
store i32 %34, i32* %6
br label %16
35: ; preds = %27
%36 = call i32 (...) @rand()
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = sub nsw i32 %37, %38
%40 = srem i32 %36, %39
%41 = load i32, i32* %10
%42 = add nsw i32 %40, %41
store i32 %42, i32* %6
br label %77
43: ; preds = %19
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 2
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %78
48: ; preds = %43
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 3
br i1 %50, label %51, label %67
51: ; preds = %48
%52 = load i32, i32* %6
%53 = add nsw i32 %52, -1
store i32 %53, i32* %6
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = load i32, i32* %10
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = load i32, i32* %10
store i32 %58, i32* %6
br label %16
59: ; preds = %51
%60 = call i32 (...) @rand()
%61 = load i32, i32* %9
%62 = load i32, i32* %10
%63 = sub nsw i32 %61, %62
%64 = srem i32 %60, %63
%65 = load i32, i32* %10
%66 = add nsw i32 %64, %65
store i32 %66, i32* %6
br label %75
67: ; preds = %48
%68 = load i32, i32* %6
%69 = icmp ne i32 %68, 3
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
%72 = load i32, i32* %8
%73 = sub nsw i32 %72, 1
store i32 %73, i32* %8
br label %74
74: ; preds = %70, %67
br label %75
75: ; preds = %74, %59
br label %76
76: ; preds = %75
br label %77
77: ; preds = %76, %35
br label %16
78: ; preds = %46, %16
%79 = load i32, i32* %7
%80 = icmp ne i32 %79, 2
br i1 %80, label %81, label %83
81: ; preds = %78
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %83
83: ; preds = %81, %78
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [6 x i8] c"clear\00"
@.str.1 = [75 x i8] c"Is your number %d? Enter 1 for too low, 2 for correct, or 3 for too high: \00"
@.str.2 = [3 x i8] c"%i\00"
@str = [14 x i8] c"Awww, I lost.\00"
@str.6 = [55 x i8] c"You have entered an incorrect value, please try again.\00"
@str.7 = [22 x i8] c"Yay! I guessed right!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 51
%9 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %47, %2
%11 = phi i32 [ %8, %2 ], [ %48, %47 ]
%12 = phi i32 [ 0, %2 ], [ %26, %47 ]
%13 = phi i32 [ 51, %2 ], [ %49, %47 ]
%14 = phi i32 [ 0, %2 ], [ %23, %47 ]
br label %15
15: ; preds = %38, %10
%16 = phi i32 [ %11, %10 ], [ %39, %38 ]
%17 = phi i32 [ %12, %10 ], [ %40, %38 ]
%18 = phi i32 [ %14, %10 ], [ %41, %38 ]
%19 = call i32 @llvm.smax.i32(i32 %17, i32 5)
br label %20
20: ; preds = %15, %30
%21 = phi i32 [ %13, %30 ], [ %16, %15 ]
%22 = phi i32 [ %26, %30 ], [ %17, %15 ]
%23 = phi i32 [ %13, %30 ], [ %18, %15 ]
%24 = icmp eq i32 %22, %19
br i1 %24, label %59, label %25
25: ; preds = %20
%26 = add i32 %22, 1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%29 = load i32, i32* %3
switch i32 %29, label %55 [
i32 1, label %30
i32 2, label %42
i32 3, label %44
]
30: ; preds = %25
%31 = add nsw i32 %21, 1
%32 = icmp eq i32 %13, %31
br i1 %32, label %20, label %33
33: ; preds = %30
%34 = call i32 (...) @rand()
%35 = sub nsw i32 %13, %31
%36 = srem i32 %34, %35
%37 = add nsw i32 %36, %31
br label %38
38: ; preds = %33, %57, %55
%39 = phi i32 [ %37, %33 ], [ %21, %57 ], [ 3, %55 ]
%40 = phi i32 [ %26, %33 ], [ %22, %57 ], [ %26, %55 ]
%41 = phi i32 [ %31, %33 ], [ %23, %57 ], [ %23, %55 ]
br label %15
42: ; preds = %25
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
br label %59
44: ; preds = %25
%45 = add nsw i32 %21, -1
%46 = icmp eq i32 %45, %23
br i1 %46, label %47, label %50
47: ; preds = %44, %50
%48 = phi i32 [ %54, %50 ], [ %23, %44 ]
%49 = phi i32 [ %45, %50 ], [ %23, %44 ]
br label %10
50: ; preds = %44
%51 = call i32 (...) @rand()
%52 = sub nsw i32 %45, %23
%53 = srem i32 %51, %52
%54 = add nsw i32 %53, %23
br label %47
55: ; preds = %25
%56 = icmp eq i32 %21, 3
br i1 %56, label %38, label %57
57: ; preds = %55
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.6, i64 0, i64 0))
br label %38
59: ; preds = %20, %42
%60 = load i32, i32* %3
%61 = icmp eq i32 %60, 2
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %64
64: ; preds = %62, %59
ret i32 0
}