#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*/ fgets(char *, int, int /*<<< orphan*/);
int inputYOrN(int /*<<< orphan*/);
scalar_t__ isdigit(int);
int /*<<< orphan*/ lineBreak();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
unsigned short rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, unsigned short *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void guessGame(void) {
  char buffer[7];
  unsigned short guess, rNumber, limit;
  int cont;
  srand(time(NULL));
  puts("The Guessing Game");
  lineBreak();
  cont = inputYOrN(0);
  while (cont) {
    guess = 0;
    lineBreak();
    printf("Enter the maximum limit(1 to 65535): ");
    fgets(buffer, 7, stdin);
    sscanf(buffer, "%hu", &limit);
    rNumber = (rand() % limit) + 1;
    while (guess != rNumber) {
      printf("\nGuess the random number(1 to %d): ", limit);
      fgets(buffer, 7, stdin);
      if (isdigit((int)buffer[0])) {
        sscanf(buffer, "%hu", &guess);
        if (guess == rNumber) {
          printf("Congratulations! You found the number!\n");
        } else {
          printf("Sorry, your guess was %s. Try again!\n",
                 ((guess > rNumber) ? "too high" : "too low"));
        }
      } else {
        printf("Invalid input. Try again.\n");
      }
    }
    cont = inputYOrN(0);
  }
}


x86 assembly (clang, -O0):
<guessGame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    0xe41(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1070 <lineBreak@plt>
xor    %edi,%edi
call   1040 <inputYOrN@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1314 <guessGame+0x174>
movw   $0x0,-0xa(%rbp)
mov    $0x0,%al
call   1070 <lineBreak@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x7(%rbp),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    $0x7,%esi
call   1090 <fgets@plt>
lea    -0x7(%rbp),%rdi
lea    0xe1c(%rip),%rsi
lea    -0xe(%rbp),%rdx
call   10b0 <sscanf@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
movzwl %ax,%eax
movzwl -0xe(%rbp),%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %dx,%ax
mov    %ax,-0xc(%rbp)
movzwl -0xa(%rbp),%eax
movzwl -0xc(%rbp),%ecx
cmp    %ecx,%eax
je     1305 <guessGame+0x165>
movzwl -0xe(%rbp),%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x7(%rbp),%rdi
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
mov    $0x7,%esi
call   1090 <fgets@plt>
movsbl -0x7(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12f2 <guessGame+0x152>
lea    -0x7(%rbp),%rdi
lea    0xda1(%rip),%rsi
lea    -0xa(%rbp),%rdx
call   10b0 <sscanf@plt>
movzwl -0xa(%rbp),%eax
movzwl -0xc(%rbp),%ecx
cmp    %ecx,%eax
jne    12c3 <guessGame+0x123>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ed <guessGame+0x14d>
movzwl -0xa(%rbp),%ecx
movzwl -0xc(%rbp),%edx
lea    0xde5(%rip),%rsi
lea    0xdd5(%rip),%rax
cmp    %edx,%ecx
cmovg  %rax,%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1300 <guessGame+0x160>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1240 <guessGame+0xa0>
xor    %edi,%edi
call   1040 <inputYOrN@plt>
mov    %eax,-0x14(%rbp)
jmp    11d5 <guessGame+0x35>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guessGame>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    0xe3d(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <lineBreak@plt>
xor    %edi,%edi
call   1040 <inputYOrN@plt>
test   %eax,%eax
je     1316 <guessGame+0x176>
mov    0x2e03(%rip),%rbp
lea    0x11(%rsp),%rbx
lea    0xe47(%rip),%r15
lea    0xe44(%rip),%r13
lea    0xc(%rsp),%r14
jmp    120f <guessGame+0x6f>
nop
xor    %edi,%edi
call   1040 <inputYOrN@plt>
test   %eax,%eax
je     1316 <guessGame+0x176>
movw   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1070 <lineBreak@plt>
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1090 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
lea    0xe(%rsp),%rdx
call   10b0 <sscanf@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
movzwl 0xe(%rsp),%ecx
xor    %edx,%edx
div    %cx
mov    %edx,%r12d
add    $0x1,%r12d
cmp    %r12w,0xc(%rsp)
je     1200 <guessGame+0x60>
nopl   0x0(%rax,%rax,1)
movzwl %cx,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1090 <fgets@plt>
movsbl 0x11(%rsp),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     12c0 <guessGame+0x120>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   10b0 <sscanf@plt>
cmp    %r12w,0xc(%rsp)
jne    12e0 <guessGame+0x140>
lea    0xdf8(%rip),%rdi
jmp    12c7 <guessGame+0x127>
nopl   0x0(%rax,%rax,1)
lea    0xdd0(%rip),%rdi
call   1050 <puts@plt>
cmp    %r12w,0xc(%rsp)
jne    130c <guessGame+0x16c>
jmp    1200 <guessGame+0x60>
nopl   0x0(%rax)
lea    0xda8(%rip),%rsi
lea    0xd98(%rip),%rax
cmova  %rax,%rsi
lea    0xd67(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r12w,0xc(%rsp)
je     1200 <guessGame+0x60>
movzwl 0xe(%rsp),%ecx
jmp    1270 <guessGame+0xd0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"The Guessing Game\00"
@.str.1 = [38 x i8] c"Enter the maximum limit(1 to 65535): \00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%hu\00"
@.str.3 = [36 x i8] c"\0AGuess the random number(1 to %d): \00"
@.str.4 = [40 x i8] c"Congratulations! You found the number!\0A\00"
@.str.5 = [38 x i8] c"Sorry, your guess was %s. Try again!\0A\00"
@.str.6 = [9 x i8] c"too high\00"
@.str.7 = [8 x i8] c"too low\00"
@.str.8 = [27 x i8] c"Invalid input. Try again.\0A\00"
define void @guessGame() {
%1 = alloca [7 x i8]
%2 = alloca i16
%3 = alloca i16
%4 = alloca i16
%5 = alloca i32
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @lineBreak()
%10 = call i32 @inputYOrN(i32 0)
store i32 %10, i32* %5
br label %11
11: ; preds = %70, %0
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %72
14: ; preds = %11
store i16 0, i16* %2
%15 = call i32 (...) @lineBreak()
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 7, i32 %18)
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %4)
%22 = call zeroext i16 (...) @rand()
%23 = zext i16 %22 to i32
%24 = load i16, i16* %4
%25 = zext i16 %24 to i32
%26 = srem i32 %23, %25
%27 = add nsw i32 %26, 1
%28 = trunc i32 %27 to i16
store i16 %28, i16* %3
br label %29
29: ; preds = %69, %14
%30 = load i16, i16* %2
%31 = zext i16 %30 to i32
%32 = load i16, i16* %3
%33 = zext i16 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %70
35: ; preds = %29
%36 = load i16, i16* %4
%37 = zext i16 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%40 = load i32, i32* @stdin
%41 = call i32 @fgets(i8* %39, i32 7, i32 %40)
%42 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = call i64 @isdigit(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %67
47: ; preds = %35
%48 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%49 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %2)
%50 = load i16, i16* %2
%51 = zext i16 %50 to i32
%52 = load i16, i16* %3
%53 = zext i16 %52 to i32
%54 = icmp eq i32 %51, %53
br i1 %54, label %55, label %57
55: ; preds = %47
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %66
57: ; preds = %47
%58 = load i16, i16* %2
%59 = zext i16 %58 to i32
%60 = load i16, i16* %3
%61 = zext i16 %60 to i32
%62 = icmp sgt i32 %59, %61
%63 = zext i1 %62 to i64
%64 = select i1 %62, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %57, %55
br label %69
67: ; preds = %35
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
br label %69
69: ; preds = %67, %66
br label %29
70: ; preds = %29
%71 = call i32 @inputYOrN(i32 0)
store i32 %71, i32* %5
br label %11
72: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"The Guessing Game\00"
@.str.1 = [38 x i8] c"Enter the maximum limit(1 to 65535): \00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%hu\00"
@.str.3 = [36 x i8] c"\0AGuess the random number(1 to %d): \00"
@.str.5 = [38 x i8] c"Sorry, your guess was %s. Try again!\0A\00"
@.str.6 = [9 x i8] c"too high\00"
@.str.7 = [8 x i8] c"too low\00"
@str = [26 x i8] c"Invalid input. Try again.\00"
@str.9 = [39 x i8] c"Congratulations! You found the number!\00"
define void @guessGame() {
%1 = alloca [7 x i8]
%2 = alloca i16
%3 = alloca i16
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%5 = bitcast i16* %2 to i8*
%6 = bitcast i16* %3 to i8*
%7 = tail call i32 @time(i32* null)
%8 = tail call i32 @srand(i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 (...) @lineBreak()
%11 = tail call i32 @inputYOrN(i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %55, label %13
13: ; preds = %0, %52
store i16 0, i16* %2
%14 = call i32 (...) @lineBreak()
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %4, i32 7, i32 %16)
%18 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%19 = call zeroext i16 (...) @rand()
%20 = load i16, i16* %3
%21 = urem i16 %19, %20
%22 = add nuw i16 %21, 1
%23 = load i16, i16* %2
%24 = icmp eq i16 %23, %22
br i1 %24, label %52, label %25
25: ; preds = %13, %50
%26 = phi i16 [ %51, %50 ], [ %20, %13 ]
%27 = zext i16 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %4, i32 7, i32 %29)
%31 = load i8, i8* %4
%32 = sext i8 %31 to i32
%33 = call i64 @isdigit(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %45, label %35
35: ; preds = %25
%36 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %2)
%37 = load i16, i16* %2
%38 = icmp eq i16 %37, %22
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
br label %47
41: ; preds = %35
%42 = icmp ugt i16 %37, %22
%43 = select i1 %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %43)
br label %47
45: ; preds = %25
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %39, %41, %45
%48 = load i16, i16* %2
%49 = icmp eq i16 %48, %22
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = load i16, i16* %3
br label %25
52: ; preds = %47, %13
%53 = call i32 @inputYOrN(i32 0)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %13
55: ; preds = %52, %0
ret void
}