#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*/ time(int /*<<< orphan*/ *);
void main() {
  int num;
  int guess;
  int i;
  int total = 0;
  srand(time(NULL));
  num = rand() % 1000 + 1;
  i = 0;
  while (i == 0) {
    guess = -1;
    while ((guess < 1) || (guess > 1000)) {
      printf("Guess a number between 1 and 1,000: ");
      scanf("%d", &guess);
      if ((guess < 1) || (guess > 1000))
        printf("Not in number range.\n");
    }
    total += 1;
    if (guess == num) {
      i = 1;
    } else if (num > guess) {
      printf("Higher!\n");
    } else if (num < guess) {
      printf("Lower!\n");
    }
  }
  printf("~~~~~~~\n");
  printf("Correct! The number is %d.\n", num);
  printf("Guesses: %d\n", total);
  if (total <= 10)
    printf("Congratz! You guessed the number in 10 or less guesses.");
  else
    printf("Unfortunately it took you more than 10 guesses to get the correct "
           "number.");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%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    $0x3e8,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1279 <main+0x129>
movl   $0xffffffff,-0x8(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x11(%rbp)
jl     11b8 <main+0x68>
cmpl   $0x3e8,-0x8(%rbp)
setg   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11c8 <main+0x78>
jmp    1210 <main+0xc0>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe48(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jl     11fd <main+0xad>
cmpl   $0x3e8,-0x8(%rbp)
jle    120b <main+0xbb>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119c <main+0x4c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1231 <main+0xe1>
movl   $0x1,-0xc(%rbp)
jmp    1274 <main+0x124>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1250 <main+0x100>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126f <main+0x11f>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126a <main+0x11a>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126f <main+0x11f>
jmp    1274 <main+0x124>
jmp    118b <main+0x3b>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xa,-0x10(%rbp)
jg     12c6 <main+0x176>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d4 <main+0x184>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %edx,0x14(%rsp)
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,0xc(%rsp)
lea    0xe47(%rip),%r15
lea    0xe65(%rip),%rbp
lea    0x10(%rsp),%rbx
lea    0xf1e(%rip),%r12
xor    %r14d,%r14d
jmp    11e8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    %r13d,%r14d
movl   $0xffffffff,0x10(%rsp)
ff
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0x10(%rsp),%eax
lea    -0x3e9(%rax),%ecx
cmp    $0xfffffc17,%ecx
ja     1231 <main+0xd1>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%eax
lea    -0x3e9(%rax),%ecx
cmp    $0xfffffc18,%ecx
jb     11f0 <main+0x90>
lea    0x1(%r14),%r13d
cmp    0xc(%rsp),%eax
je     125a <main+0xfa>
lea    0xea0(%rip),%rdi
cmp    %eax,0x14(%rsp)
jge    11e0 <main+0x80>
mov    %r13d,%r14d
lea    0xe89(%rip),%rdi
cmp    %eax,0xc(%rsp)
jge    11e8 <main+0x88>
jmp    11e0 <main+0x80>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
lea    0xdbb(%rip),%rdi
mov    0xc(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc5(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xa,%r14d
lea    0xdbd(%rip),%rax
lea    0xdee(%rip),%rdi
cmovb  %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Guess a number between 1 and 1,000: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [22 x i8] c"Not in number range.\0A\00"
@.str.3 = [9 x i8] c"Higher!\0A\00"
@.str.4 = [8 x i8] c"Lower!\0A\00"
@.str.5 = [9 x i8] c"~~~~~~~\0A\00"
@.str.6 = [28 x i8] c"Correct! The number is %d.\0A\00"
@.str.7 = [13 x i8] c"Guesses: %d\0A\00"
@.str.8 = [56 x i8] c"Congratz! You guessed the number in 10 or less guesses.\00"
@.str.9 = [74 x i8] c"Unfortunately it took you more than 10 guesses to get the correct number.\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %4
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 1000
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
store i32 0, i32* %3
br label %10
10: ; preds = %54, %0
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %55
13: ; preds = %10
store i32 -1, i32* %2
br label %14
14: ; preds = %32, %13
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %2
%19 = icmp sgt i32 %18, 1000
br label %20
20: ; preds = %17, %14
%21 = phi i1 [ true, %14 ], [ %19, %17 ]
br i1 %21, label %22, label %33
22: ; preds = %20
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 1
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = load i32, i32* %2
%29 = icmp sgt i32 %28, 1000
br i1 %29, label %30, label %32
30: ; preds = %27, %22
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
br label %14
33: ; preds = %20
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
%36 = load i32, i32* %2
%37 = load i32, i32* %1
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 1, i32* %3
br label %54
40: ; preds = %33
%41 = load i32, i32* %1
%42 = load i32, i32* %2
%43 = icmp sgt i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %53
46: ; preds = %40
%47 = load i32, i32* %1
%48 = load i32, i32* %2
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
br label %53
53: ; preds = %52, %44
br label %54
54: ; preds = %53, %39
br label %10
55: ; preds = %10
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* %1
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %4
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %4
%62 = icmp sle i32 %61, 10
br i1 %62, label %63, label %65
63: ; preds = %55
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0))
br label %67
65: ; preds = %55
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.9, i64 0, i64 0))
br label %67
67: ; preds = %65, %63
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Guess a number between 1 and 1,000: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.6 = [28 x i8] c"Correct! The number is %d.\0A\00"
@.str.7 = [13 x i8] c"Guesses: %d\0A\00"
@.str.8 = [56 x i8] c"Congratz! You guessed the number in 10 or less guesses.\00"
@.str.9 = [74 x i8] c"Unfortunately it took you more than 10 guesses to get the correct number.\00"
@str = [8 x i8] c"~~~~~~~\00"
@str.10 = [7 x i8] c"Lower!\00"
@str.11 = [8 x i8] c"Higher!\00"
@str.12 = [21 x i8] c"Not in number range.\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 1000
%7 = add nsw i32 %6, 1
br label %8
8: ; preds = %32, %0
%9 = phi i32 [ 0, %0 ], [ %23, %32 ]
store i32 -1, i32* %1
br label %10
10: ; preds = %8, %16
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = add i32 %13, -1001
%15 = icmp ult i32 %14, -1000
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.12, i64 0, i64 0))
%18 = load i32, i32* %1
%19 = add i32 %18, -1001
%20 = icmp ult i32 %19, -1000
br i1 %20, label %10, label %21
21: ; preds = %10, %16
%22 = phi i32 [ %18, %16 ], [ %13, %10 ]
%23 = add nuw nsw i32 %9, 1
%24 = icmp eq i32 %22, %7
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = icmp slt i32 %6, %22
br i1 %26, label %27, label %29
27: ; preds = %25
%28 = icmp slt i32 %7, %22
br i1 %28, label %29, label %32
29: ; preds = %27, %25
%30 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.11, i64 0, i64 0), %25 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @str.10, i64 0, i64 0), %27 ]
%31 = call i32 @puts(i8* dereferenceable(1) %30)
br label %32
32: ; preds = %29, %27
br label %8
33: ; preds = %21
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %7)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%37 = icmp ult i32 %9, 10
%38 = select i1 %37, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.9, i64 0, i64 0)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %38)
ret void
}