#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 *);
int guessTheNumber() {
  int n, guess;
  int numberOfGuesses = 1;
  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: ");
      numberOfGuesses++;
      scanf("%d", &guess);
    } else {
      printf("Too high. Try again: ");
      numberOfGuesses++;
      scanf("%d", &guess);
    }
  }
  return numberOfGuesses;
}


x86 assembly (clang, -O0):
<guessTheNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%edi
mov    $0x3e8,%esi
call   1030 <getRandomNum@plt>
mov    %eax,-0x4(%rbp)
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a2 <guessTheNumber+0x72>
jmp    122d <guessTheNumber+0xfd>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11c8 <guessTheNumber+0x98>
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1228 <guessTheNumber+0xf8>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fe <guessTheNumber+0xce>
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe6e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1223 <guessTheNumber+0xf3>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe44(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1228 <guessTheNumber+0xf8>
jmp    118c <guessTheNumber+0x5c>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guessTheNumber>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0x3e8,%esi
call   1040 <getRandomNum@plt>
mov    %eax,%ebp
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
lea    0xe93(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebp,%eax
jne    11bb <guessTheNumber+0x7b>
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
lea    0xe5b(%rip),%r12
lea    0xe69(%rip),%r13
lea    0xe4a(%rip),%r14
lea    0x4(%rsp),%r15
jmp    11fb <guessTheNumber+0xbb>
nopl   0x0(%rax)
call   1050 <printf@plt>
add    $0x1,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebp,%eax
je     119e <guessTheNumber+0x5e>
mov    %r12,%rdi
cmp    %ebp,%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 i32 @guessTheNumber() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 1, i32* %3
store i32 0, i32* %4
%5 = call i32 @getRandomNum(i32 1, i32 1000)
store i32 %5, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %10
10: ; preds = %37, %0
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load i32, i32* %2
%16 = load i32, i32* %1
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %37
22: ; preds = %14
%23 = load i32, i32* %2
%24 = load i32, i32* %1
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %36
31: ; preds = %22
%32 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %36
36: ; preds = %31, %26
br label %37
37: ; preds = %36, %18
br label %10
38: ; preds = %10
%39 = load i32, i32* %3
ret i32 %39
}

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 i32 @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 %20, label %10
10: ; preds = %0, %10
%11 = phi i32 [ %18, %10 ], [ %8, %0 ]
%12 = phi i32 [ %16, %10 ], [ 1, %0 ]
%13 = icmp slt i32 %11, %3
%14 = select i1 %13, 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)
%15 = call i32 @printf(i8* dereferenceable(1) %14)
%16 = add nuw nsw i32 %12, 1
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
%19 = icmp eq i32 %18, %3
br i1 %19, label %20, label %10
20: ; preds = %10, %0
%21 = phi i32 [ 1, %0 ], [ %16, %10 ]
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
ret i32 %21
}