#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 getRandomNum(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void guessTheNumber() {
  int n, guess;
  int correct = 0;
  n = getRandomNum(1, 1000);
  printf("\nI have a number between 1 and 1000\n");
  printf("Can you guess my number?\n");
  printf("Please type your first guess: ");
  scanf("%d", &guess);
  while (!correct) {
    if (guess == n) {
      printf("Excellent! You guessed the number!\n");
      correct++;
    } else if (guess < n) {
      printf("Too low. Try again: ");
      scanf("%d", &guess);
    } else {
      printf("Too high. Try again: ");
      scanf("%d", &guess);
    }
  }
}


x86 assembly (clang, -O0):
<guessTheNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
mov    $0x1,%edi
mov    $0x3e8,%esi
call   1030 <getRandomNum@plt>
mov    %eax,-0x4(%rbp)
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
call   1040 <printf@plt>
lea    0xee2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119b <guessTheNumber+0x6b>
jmp    1214 <guessTheNumber+0xe4>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11c1 <guessTheNumber+0x91>
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    120f <guessTheNumber+0xdf>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ee <guessTheNumber+0xbe>
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    120a <guessTheNumber+0xda>
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
lea    0xe5d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    120f <guessTheNumber+0xdf>
jmp    1185 <guessTheNumber+0x55>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guessTheNumber>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
mov    $0x3e8,%esi
call   1040 <getRandomNum@plt>
mov    %eax,%ebx
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xf00(%rip),%rdi
call   1030 <puts@plt>
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
jne    11b5 <guessTheNumber+0x75>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe66(%rip),%r12
lea    0xe74(%rip),%r13
lea    0xe55(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11f8 <guessTheNumber+0xb8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
je     119b <guessTheNumber+0x5b>
mov    %r12,%rdi
cmp    %ebx,%eax
jl     11e0 <guessTheNumber+0xa0>
mov    %r13,%rdi
jmp    11e0 <guessTheNumber+0xa0>

LLVM IR (-O0):
@.str = [37 x i8] c"\0AI have a number between 1 and 1000\0A\00"
@.str.1 = [26 x i8] c"Can you guess my number?\0A\00"
@.str.2 = [31 x i8] c"Please type your first guess: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [36 x i8] c"Excellent! You guessed the number!\0A\00"
@.str.5 = [21 x i8] c"Too low. Try again: \00"
@.str.6 = [22 x i8] c"Too high. Try again: \00"
define void @guessTheNumber() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 @getRandomNum(i32 1, i32 1000)
store i32 %4, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %32, %0
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %33
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %1
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %32
21: ; preds = %13
%22 = load i32, i32* %2
%23 = load i32, i32* %1
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %31
28: ; preds = %21
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31, %17
br label %9
33: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str.2 = [31 x i8] c"Please type your first guess: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [21 x i8] c"Too low. Try again: \00"
@.str.6 = [22 x i8] c"Too high. Try again: \00"
@str = [36 x i8] c"\0AI have a number between 1 and 1000\00"
@str.7 = [25 x i8] c"Can you guess my number?\00"
@str.8 = [35 x i8] c"Excellent! You guessed the number!\00"
define void @guessTheNumber() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @getRandomNum(i32 1, i32 1000)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, %3
br i1 %9, label %18, label %10
10: ; preds = %0, %10
%11 = phi i32 [ %16, %10 ], [ %8, %0 ]
%12 = icmp slt i32 %11, %3
%13 = select i1 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0)
%14 = call i32 @printf(i8* dereferenceable(1) %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
%17 = icmp eq i32 %16, %3
br i1 %17, label %18, label %10
18: ; preds = %10, %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
ret void
}