#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 */
scalar_t__ EOF;
int /*<<< orphan*/ printf(char *, ...);
int rrange(int, int);
scalar_t__ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int guess = 1;
  int num = rrange(2, 500);
  printf("Welcome to the guessing game!\n");
  printf(
      "In this game, you have 7 guesses to try and figure out what number I'm");
  printf("thinking of.\n");
  printf("The number will be between 2 and 500.\n");
  printf("====================================================\n");
  printf("What number am I thinking of?\n");
  do {
    int input = 0;
    do {
      printf("Please enter guess %i: ", guess);
      if (scanf("%i", &input) != EOF)
        break;
      printf("Please enter a number.\n");
    } while (1);
    if (input < num) {
      printf("You'll have to guess higher!\n");
    } else if (input > num) {
      printf("You'll have to guess lower!\n");
    } else if (input == num) {
      printf("You got it!\n");
      return 0;
    }
    guess++;
  } while (guess <= 7);
  printf("You lost.\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x1,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x1f4,%esi
call   1060 <rrange@plt>
mov    %eax,-0xc(%rbp)
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xf03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0d(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%rax
je     1219 <main+0xc9>
jmp    1236 <main+0xe6>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11e3 <main+0x93>
jmp    1236 <main+0xe6>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1255 <main+0x105>
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a4 <main+0x154>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1274 <main+0x124>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <main+0x14f>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    129a <main+0x14a>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c5 <main+0x175>
jmp    129f <main+0x14f>
jmp    12a4 <main+0x154>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x7,-0x8(%rbp)
jle    11dc <main+0x8c>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%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   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x2,%edi
mov    $0x1f4,%esi
call   1070 <rrange@plt>
mov    %eax,0x4(%rsp)
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
lea    0xeee(%rip),%rdi
call   1030 <puts@plt>
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
lea    0xe65(%rip),%r15
lea    0xe76(%rip),%r12
mov    %rsp,%rbx
mov    0x2df5(%rip),%r14
lea    0xf0c(%rip),%r13
jmp    120d <main+0xad>
nopl   0x0(%rax)
call   1030 <puts@plt>
add    $0x1,%ebp
cmp    $0x8,%ebp
je     1274 <main+0x114>
movl   $0x0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
cmp    (%r14),%rax
jne    1250 <main+0xf0>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    1220 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%eax
lea    0xef5(%rip),%rdi
cmp    0x4(%rsp),%eax
jl     1200 <main+0xa0>
lea    0xecc(%rip),%rdi
jg     1200 <main+0xa0>
jne    1205 <main+0xa5>
lea    0xeb5(%rip),%rdi
jmp    127b <main+0x11b>
lea    0xea2(%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 = [31 x i8] c"Welcome to the guessing game!\0A\00"
@.str.1 = [71 x i8] c"In this game, you have 7 guesses to try and figure out what number I'm\00"
@.str.2 = [14 x i8] c"thinking of.\0A\00"
@.str.3 = [39 x i8] c"The number will be between 2 and 500.\0A\00"
@.str.4 = [54 x i8] c"====================================================\0A\00"
@.str.5 = [31 x i8] c"What number am I thinking of?\0A\00"
@.str.6 = [24 x i8] c"Please enter guess %i: \00"
@.str.7 = [3 x i8] c"%i\00"
@EOF = global i64 0
@.str.8 = [24 x i8] c"Please enter a number.\0A\00"
@.str.9 = [30 x i8] c"You'll have to guess higher!\0A\00"
@.str.10 = [29 x i8] c"You'll have to guess lower!\0A\00"
@.str.11 = [13 x i8] c"You got it!\0A\00"
@.str.12 = [11 x i8] c"You lost.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
store i32 1, i32* %2
%7 = call i32 @rrange(i32 2, i32 500)
store i32 %7, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %48, %0
store i32 0, i32* %4
br label %15
15: ; preds = %24, %14
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %16)
%18 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %4)
%19 = load i64, i64* @EOF
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
br label %25
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
br label %24
24: ; preds = %22
br i1 true, label %15, label %25
25: ; preds = %24, %21
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
br label %45
31: ; preds = %25
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
br label %44
37: ; preds = %31
%38 = load i32, i32* %4
%39 = load i32, i32* %3
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %1
br label %53
43: ; preds = %37
br label %44
44: ; preds = %43, %35
br label %45
45: ; preds = %44, %29
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
br label %48
48: ; preds = %45
%49 = load i32, i32* %2
%50 = icmp sle i32 %49, 7
br i1 %50, label %14, label %51
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0))
br label %53
53: ; preds = %51, %41
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [71 x i8] c"In this game, you have 7 guesses to try and figure out what number I'm\00"
@.str.6 = [24 x i8] c"Please enter guess %i: \00"
@.str.7 = [3 x i8] c"%i\00"
@EOF = global i64 0
@str = [30 x i8] c"Welcome to the guessing game!\00"
@str.13 = [13 x i8] c"thinking of.\00"
@str.14 = [38 x i8] c"The number will be between 2 and 500.\00"
@str.15 = [53 x i8] c"====================================================\00"
@str.16 = [30 x i8] c"What number am I thinking of?\00"
@str.17 = [23 x i8] c"Please enter a number.\00"
@str.18 = [10 x i8] c"You lost.\00"
@str.19 = [12 x i8] c"You got it!\00"
@str.20 = [28 x i8] c"You'll have to guess lower!\00"
@str.21 = [29 x i8] c"You'll have to guess higher!\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 @rrange(i32 2, i32 500)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.13, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.14, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.15, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.16, i64 0, i64 0))
%11 = bitcast i32* %1 to i8*
br label %12
12: ; preds = %36, %0
%13 = phi i32 [ 1, %0 ], [ %37, %36 ]
store i32 0, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %13)
%15 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %12, %18
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.17, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %13)
%21 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %18, label %24
24: ; preds = %18, %12
%25 = load i32, i32* %1
%26 = icmp slt i32 %25, %4
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = icmp sgt i32 %25, %4
br i1 %28, label %33, label %29
29: ; preds = %27
%30 = icmp eq i32 %25, %4
br i1 %30, label %31, label %36
31: ; preds = %29
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.19, i64 0, i64 0))
br label %41
33: ; preds = %27, %24
%34 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.21, i64 0, i64 0), %24 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.20, i64 0, i64 0), %27 ]
%35 = call i32 @puts(i8* dereferenceable(1) %34)
br label %36
36: ; preds = %33, %29
%37 = add nuw nsw i32 %13, 1
%38 = icmp eq i32 %37, 8
br i1 %38, label %39, label %12
39: ; preds = %36
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.18, i64 0, i64 0))
br label %41
41: ; preds = %31, %39
ret i32 0
}