#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*/ *);
void game(void) {
  srand(time(NULL));
  int r = rand() % 10 + 1;
  bool correct = false;
  int guess;
  int counter = 0;
  while (!correct) {
    printf("Guess my number! ");
    scanf("%d", &guess);
    getchar();
    counter++;
    if (guess < r) {
      printf("Your guess is too low. Guess again.\n");
    } else if (guess > r) {
      printf("Your guess is too high. Guess again.\n");
    } else {
      printf("You guessed correctly in %d tries! Congratulations!\n", counter);
      correct = true;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
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,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b1 <game+0x51>
jmp    123f <game+0xdf>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4c(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fe <game+0x9e>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123a <game+0xda>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    121d <game+0xbd>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <game+0xd5>
mov    -0x10(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    123a <game+0xda>
jmp    119b <game+0x3b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<game>:
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   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
mov    %eax,%ebp
sub    %ecx,%ebp
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%rsp)
mov    $0x1,%ebx
lea    0xe3b(%rip),%r14
lea    0xe46(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xe97(%rip),%r13
jmp    11e8 <game+0x78>
nopw   0x0(%rax,%rax,1)
call   1030 <puts@plt>
add    $0x1,%ebx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x4(%rsp),%eax
mov    %r13,%rdi
cmp    %ebp,%eax
jle    11e0 <game+0x70>
lea    0xe34(%rip),%rdi
cmp    (%rsp),%eax
jg     11e0 <game+0x70>
lea    0xdf3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Guess my number! \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [37 x i8] c"Your guess is too low. Guess again.\0A\00"
@.str.3 = [38 x i8] c"Your guess is too high. Guess again.\0A\00"
@.str.4 = [53 x i8] c"You guessed correctly in %d tries! Congratulations!\0A\00"
define void @game() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 10
%9 = add nsw i32 %8, 1
store i32 %9, i32* %1
store i32 0, i32* %2
store i32 0, i32* %4
br label %10
10: ; preds = %35, %0
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%17 = call i32 (...) @getchar()
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = load i32, i32* %3
%21 = load i32, i32* %1
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %35
25: ; preds = %14
%26 = load i32, i32* %3
%27 = load i32, i32* %1
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %34
31: ; preds = %25
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %32)
store i32 1, i32* %2
br label %34
34: ; preds = %31, %29
br label %35
35: ; preds = %34, %23
br label %10
36: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"Guess my number! \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [53 x i8] c"You guessed correctly in %d tries! Congratulations!\0A\00"
@str = [37 x i8] c"Your guess is too high. Guess again.\00"
@str.5 = [36 x i8] c"Your guess is too low. Guess again.\00"
define void @game() {
%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*
br label %8
8: ; preds = %18, %0
%9 = phi i32 [ 0, %0 ], [ %13, %18 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = call i32 (...) @getchar()
%13 = add nuw nsw i32 %9, 1
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, %5
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = icmp sgt i32 %14, %6
br i1 %17, label %18, label %21
18: ; preds = %16, %8
%19 = phi i8* [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0), %8 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0), %16 ]
%20 = call i32 @puts(i8* dereferenceable(1) %19)
br label %8
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %13)
ret void
}