#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*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int r = (rand() % 10) + 1;
  int number;
  int c = 0;
  int count = 5;
  printf("Guess a number from 1 to 10! You have 5 tries.\n");
  do {
    if (count == 0) {
      printf("\nGame over! Press enter to exit...\n");
      c = 1;
    } else {
      scanf("%d", &number);
      if (number == r) {
        printf("\nCorrect! You win!!! Press enter to exit...\n");
        c = 1;
      } else if (number > r) {
        if (count != 2) {
          printf("Too high! %d guesses remaining.\n", count - 1);
        } else {
          printf("Too high! 1 guess remaining.\n");
        }
        count--;
      } else {
        if (count != 2) {
          printf("Too low! %d guesses remaining.\n", count - 1);
        } else {
          printf("Too low! 1 guess remaining.\n");
        }
        count--;
      }
    }
  } while (c == 0);
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11d4 <main+0x74>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
jmp    1299 <main+0x139>
lea    0xe79(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    120a <main+0xaa>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
jmp    1294 <main+0x134>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1255 <main+0xf5>
cmpl   $0x2,-0x14(%rbp)
je     1239 <main+0xd9>
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1247 <main+0xe7>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    128f <main+0x12f>
cmpl   $0x2,-0x14(%rbp)
je     1278 <main+0x118>
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1286 <main+0x126>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1294 <main+0x134>
jmp    1299 <main+0x139>
jmp    129e <main+0x13e>
cmpl   $0x0,-0x10(%rbp)
je     11b0 <main+0x50>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
lea    0xed9(%rip),%rbx
cmp    %ebp,0x4(%rsp)
je     12b2 <main+0x142>
lea    0xe1f(%rip),%r15
lea    0xe39(%rip),%r14
mov    %r14,%rdi
cmovg  %r15,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdfb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
cmp    %ebp,0x4(%rsp)
je     12b2 <main+0x142>
mov    %r14,%rdi
cmovg  %r15,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdcd(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
cmp    %ebp,0x4(%rsp)
je     12b2 <main+0x142>
mov    %r14,%rdi
cmovg  %r15,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xda3(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
cmp    %ebp,0x4(%rsp)
je     12b2 <main+0x142>
lea    0xe1b(%rip),%rax
lea    0xdf8(%rip),%rdi
cmovg  %rax,%rdi
call   1030 <puts@plt>
lea    0xd75(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
cmp    %ebp,0x4(%rsp)
je     12b2 <main+0x142>
cmovg  %r15,%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe26(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Guess a number from 1 to 10! You have 5 tries.\0A\00"
@.str.1 = [36 x i8] c"\0AGame over! Press enter to exit...\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [45 x i8] c"\0ACorrect! You win!!! Press enter to exit...\0A\00"
@.str.4 = [33 x i8] c"Too high! %d guesses remaining.\0A\00"
@.str.5 = [30 x i8] c"Too high! 1 guess remaining.\0A\00"
@.str.6 = [32 x i8] c"Too low! %d guesses remaining.\0A\00"
@.str.7 = [29 x i8] c"Too low! 1 guess remaining.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 10
%10 = add nsw i32 %9, 1
store i32 %10, i32* %2
store i32 0, i32* %4
store i32 5, i32* %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %55, %0
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %54
17: ; preds = %12
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%19 = load i32, i32* %3
%20 = load i32, i32* %2
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %53
24: ; preds = %17
%25 = load i32, i32* %3
%26 = load i32, i32* %2
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 2
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %5
%33 = sub nsw i32 %32, 1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %37
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* %5
%39 = add nsw i32 %38, -1
store i32 %39, i32* %5
br label %52
40: ; preds = %24
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, 2
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* %5
%45 = sub nsw i32 %44, 1
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %45)
br label %49
47: ; preds = %40
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
%50 = load i32, i32* %5
%51 = add nsw i32 %50, -1
store i32 %51, i32* %5
br label %52
52: ; preds = %49, %37
br label %53
53: ; preds = %52, %22
br label %54
54: ; preds = %53, %15
br label %55
55: ; preds = %54
%56 = load i32, i32* %4
%57 = icmp eq i32 %56, 0
br i1 %57, label %12, label %58
58: ; preds = %55
%59 = call i32 (...) @getchar()
%60 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [33 x i8] c"Too high! %d guesses remaining.\0A\00"
@.str.6 = [32 x i8] c"Too low! %d guesses remaining.\0A\00"
@str = [47 x i8] c"Guess a number from 1 to 10! You have 5 tries.\00"
@str.8 = [28 x i8] c"Too low! 1 guess remaining.\00"
@str.9 = [29 x i8] c"Too high! 1 guess remaining.\00"
@str.10 = [44 x i8] c"\0ACorrect! You win!!! Press enter to exit...\00"
@str.11 = [35 x i8] c"\0AGame over! Press enter to exit...\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 10
%6 = add nsw i32 %5, 1
%7 = bitcast i32* %1 to i8*
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, %6
br i1 %11, label %44, label %12
12: ; preds = %0
%13 = icmp sgt i32 %10, %6
%14 = select i1 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %14, i32 4)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, %6
br i1 %18, label %44, label %19
19: ; preds = %12
%20 = icmp sgt i32 %17, %6
%21 = select i1 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %21, i32 3)
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, %6
br i1 %25, label %44, label %26
26: ; preds = %19
%27 = icmp sgt i32 %24, %6
%28 = select i1 %27, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %28, i32 2)
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%31 = load i32, i32* %1
%32 = icmp eq i32 %31, %6
br i1 %32, label %44, label %33
33: ; preds = %26
%34 = icmp sgt i32 %31, %6
%35 = select i1 %34, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0)
%36 = call i32 @puts(i8* dereferenceable(1) %35)
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%38 = load i32, i32* %1
%39 = icmp eq i32 %38, %6
br i1 %39, label %44, label %40
40: ; preds = %33
%41 = icmp sgt i32 %38, %6
%42 = select i1 %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %42, i32 0)
br label %44
44: ; preds = %0, %12, %19, %26, %33, %40
%45 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.11, i64 0, i64 0), %40 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0), %33 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0), %26 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0), %19 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0), %12 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0), %0 ]
%46 = call i32 @puts(i8* dereferenceable(1) %45)
%47 = call i32 (...) @getchar()
%48 = call i32 (...) @getchar()
ret i32 0
}