#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 main() {
  int guess;
  int r = rand() % 20 + 1;
  printf("Enter a whole number between 1 and 20, please. ");
  scanf("%i", &guess);
  do {
    if (guess > r) {
      printf("My number is smaller than your guess\n");
      printf("Please guess again: ");
      scanf("%i", &guess);
    } else if (guess < r) {
      printf("My number is larger than your guess\n");
      printf("Please guess again: ");
      scanf("%i", &guess);
    }
  } while (guess != r);
  if (guess == r) {
    printf("Well done you guessed correctly!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11a9 <main+0x79>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    11e2 <main+0xb2>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <main+0xad>
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
lea    0xe5c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    11e2 <main+0xb2>
jmp    11e7 <main+0xb7>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1170 <main+0x40>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    120b <main+0xdb>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%r13d
sub    %ecx,%r13d
neg    %ecx
lea    (%rax,%rcx,1),%ebx
add    $0x1,%ebx
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
lea    0xea1(%rip),%r14
lea    0x4(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
lea    0xee3(%rip),%rbp
lea    0xe82(%rip),%r12
jmp    11e0 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebx,%eax
je     11f5 <main+0xb5>
mov    %rbp,%rdi
cmp    %ebx,%eax
jg     11c0 <main+0x80>
lea    0xe7b(%rip),%rdi
cmp    %r13d,%eax
jle    11c0 <main+0x80>
jmp    11d8 <main+0x98>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Enter a whole number between 1 and 20, please. \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.2 = [38 x i8] c"My number is smaller than your guess\0A\00"
@.str.3 = [21 x i8] c"Please guess again: \00"
@.str.4 = [37 x i8] c"My number is larger than your guess\0A\00"
@.str.5 = [34 x i8] c"Well done you guessed correctly!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @rand()
%5 = srem i32 %4, 20
%6 = add nsw i32 %5, 1
store i32 %6, i32* %3
%7 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %27, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = icmp sgt i32 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %26
17: ; preds = %9
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, 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)
br label %25
25: ; preds = %21, %17
br label %26
26: ; preds = %25, %13
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = icmp ne i32 %28, %29
br i1 %30, label %9, label %31
31: ; preds = %27
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
ret i32 0
}

LLVM IR (-O2):
@.str = [48 x i8] c"Enter a whole number between 1 and 20, please. \00"
@.str.1 = [3 x i8] c"%i\00"
@.str.3 = [21 x i8] c"Please guess again: \00"
@str = [33 x i8] c"Well done you guessed correctly!\00"
@str.6 = [36 x i8] c"My number is larger than your guess\00"
@str.7 = [37 x i8] c"My number is smaller than your guess\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 20
%5 = add nsw i32 %4, 1
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
br label %9
9: ; preds = %19, %0
%10 = phi i32 [ %20, %19 ], [ %8, %0 ]
%11 = icmp sgt i32 %10, %5
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = icmp sgt i32 %10, %4
br i1 %13, label %19, label %14
14: ; preds = %12, %9
%15 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @str.7, i64 0, i64 0), %9 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0), %12 ]
%16 = call i32 @puts(i8* dereferenceable(1) %15)
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %19
19: ; preds = %14, %12
%20 = load i32, i32* %1
%21 = icmp eq i32 %20, %5
br i1 %21, label %22, label %9
22: ; preds = %19
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
ret i32 0
}