#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 scanf(char *, unsigned int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  unsigned int ans = rand() % 100;
  unsigned int user = 100;
  unsigned int left = 0;
  unsigned int right = 99;
  printf("Hello, droid!  Let's play a number guessing game!\n");
  while (user != ans) {
    printf("Please input a number [%d-%d]:\n", left, right);
    if (scanf("%u", &user) != 1) {
      break;
    }
    if (user < left || user > right) {
      continue;
    } else if (user == ans) {
      printf("You got it!\n");
      break;
    } else if (user < ans) {
      left = user;
    } else {
      right = user;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x63,-0x14(%rbp)
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     124a <main+0xfa>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     11e2 <main+0x92>
jmp    124a <main+0xfa>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jb     11fa <main+0xaa>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    11ff <main+0xaf>
jmp    11a4 <main+0x54>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    121e <main+0xce>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124a <main+0xfa>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1235 <main+0xe5>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    123b <main+0xeb>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1240 <main+0xf0>
jmp    1245 <main+0xf5>
jmp    11a4 <main+0x54>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%r13
imul   $0x51eb851f,%r13,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%r13d
movl   $0x64,0x4(%rsp)
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    $0x63,%ebx
mov    $0x64,%eax
lea    0xe3e(%rip),%r14
lea    0xe57(%rip),%r15
lea    0x4(%rsp),%r12
xor    %ebp,%ebp
cmp    %r13d,%eax
je     1218 <main+0xb8>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1218 <main+0xb8>
mov    0x4(%rsp),%eax
cmp    %ebp,%eax
jb     11d0 <main+0x70>
cmp    %ebx,%eax
ja     11d0 <main+0x70>
cmp    %r13d,%eax
je     120c <main+0xac>
cmovb  %eax,%ebp
cmovae %eax,%ebx
jmp    11d0 <main+0x70>
lea    0xe42(%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 = [51 x i8] c"Hello, droid! Let's play a number guessing game!\0A\00"
@.str.1 = [32 x i8] c"Please input a number [%d-%d]:\0A\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [13 x i8] c"You got it!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 100
store i32 %9, i32* %2
store i32 100, i32* %3
store i32 0, i32* %4
store i32 99, i32* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %47, %30, %0
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %48
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %15
br label %48
22: ; preds = %15
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp ult i32 %23, %24
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = icmp ugt i32 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26, %22
br label %11
31: ; preds = %26
%32 = load i32, i32* %3
%33 = load i32, i32* %2
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %48
37: ; preds = %31
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = icmp ult i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = load i32, i32* %3
store i32 %42, i32* %4
br label %45
43: ; preds = %37
%44 = load i32, i32* %3
store i32 %44, i32* %5
br label %45
45: ; preds = %43, %41
br label %46
46: ; preds = %45
br label %47
47: ; preds = %46
br label %11
48: ; preds = %35, %21, %11
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [32 x i8] c"Please input a number [%d-%d]:\0A\00"
@.str.2 = [3 x i8] c"%u\00"
@str = [50 x i8] c"Hello, droid! Let's play a number guessing game!\00"
@str.4 = [12 x i8] c"You got it!\00"
define i32 @main() {
%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, 100
%6 = bitcast i32* %1 to i8*
store i32 100, i32* %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %28, %0
%9 = phi i32 [ %20, %28 ], [ 100, %0 ]
%10 = phi i32 [ %30, %28 ], [ 0, %0 ]
%11 = phi i32 [ %31, %28 ], [ 99, %0 ]
br label %12
12: ; preds = %8, %19
%13 = phi i32 [ %9, %8 ], [ %20, %19 ]
%14 = icmp eq i32 %13, %5
br i1 %14, label %32, label %15
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %11)
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32, i32* %1
%21 = icmp ult i32 %20, %10
%22 = icmp ugt i32 %20, %11
%23 = select i1 %21, i1 true, i1 %22
br i1 %23, label %12, label %24
24: ; preds = %19
%25 = icmp eq i32 %20, %5
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
br label %32
28: ; preds = %24
%29 = icmp ult i32 %20, %5
%30 = select i1 %29, i32 %20, i32 %10
%31 = select i1 %29, i32 %11, i32 %20
br label %8
32: ; preds = %15, %12, %26
ret i32 0
}