#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 /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int no;
  int ans;
  const int max_stage = 10;
  int remain = max_stage;
  srand(time(NULL));
  ans = rand() % 1000;
  printf("Please guess a 0~999 integer.\n\n");
  do {
    printf("Have %d chance. What is it: ", remain);
    scanf("%d", &no);
    remain--;
    if (no > ans)
      printf("\aSmaller.\n");
    else if (no < ans)
      printf("\aBigger.\n");
  } while (no != ans && remain > 0);
  if (no != ans)
    printf("\aSorry, the correct answer is %d.\n", ans);
  else {
    printf("Correct.\n");
    printf("You use %d times to hit the answer.\n", max_stage - remain);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x10(%rbp)
movl   $0xa,-0x14(%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    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11e6 <main+0x96>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <main+0xb5>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1200 <main+0xb0>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <main+0xb5>
jmp    120a <main+0xba>
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x15(%rbp)
je     1225 <main+0xd5>
cmpl   $0x0,-0x14(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    119d <main+0x4d>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1252 <main+0x102>
mov    -0xc(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1276 <main+0x126>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xa,%esi
sub    -0x14(%rbp),%esi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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,%r14
imul   $0x10624dd3,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%r14d
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%r12
lea    0x4(%rsp),%r13
lea    0xeda(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xa(%rbx),%ebp
lea    0xe26(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
mov    %r15,%rdi
cmp    %r14d,0x4(%rsp)
jg     1201 <main+0xa1>
lea    0xe91(%rip),%rdi
jge    1206 <main+0xa6>
call   1030 <puts@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%ebx
cmp    $0x2,%ebp
jb     1217 <main+0xb7>
cmp    %r14d,%eax
jne    11d0 <main+0x70>
cmp    %r14d,%eax
je     1228 <main+0xc8>
lea    0xdfd(%rip),%rdi
mov    %r14d,%esi
jmp    123f <main+0xdf>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
neg    %ebx
lea    0xe06(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Please guess a 0~999 integer.\0A\0A\00"
@.str.1 = [29 x i8] c"Have %d chance. What is it: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [11 x i8] c"\07Smaller.\0A\00"
@.str.4 = [10 x i8] c"\07Bigger.\0A\00"
@.str.5 = [35 x i8] c"\07Sorry, the correct answer is %d.\0A\00"
@.str.6 = [10 x i8] c"Correct.\0A\00"
@.str.7 = [37 x i8] c"You use %d times to hit the answer.\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
store i32 10, i32* %4
store i32 10, i32* %5
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 1000
store i32 %9, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %37, %0
%12 = load i32, i32* %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %5
%16 = add nsw i32 %15, -1
store i32 %16, i32* %5
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %29
22: ; preds = %11
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
br label %29
29: ; preds = %28, %20
br label %30
30: ; preds = %29
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %5
%36 = icmp sgt i32 %35, 0
br label %37
37: ; preds = %34, %30
%38 = phi i1 [ false, %30 ], [ %36, %34 ]
br i1 %38, label %11, label %39
39: ; preds = %37
%40 = load i32, i32* %2
%41 = load i32, i32* %3
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* %3
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %44)
br label %51
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32, i32* %5
%49 = sub nsw i32 10, %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %46, %43
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [29 x i8] c"Have %d chance. What is it: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [35 x i8] c"\07Sorry, the correct answer is %d.\0A\00"
@.str.7 = [37 x i8] c"You use %d times to hit the answer.\0A\00"
@str = [31 x i8] c"Please guess a 0~999 integer.\0A\00"
@str.8 = [9 x i8] c"Correct.\00"
@str.9 = [9 x i8] c"\07Bigger.\00"
@str.10 = [10 x i8] c"\07Smaller.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 1000
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %20, %0
%9 = phi i32 [ 10, %0 ], [ %12, %20 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = add nsw i32 %9, -1
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, %6
br i1 %14, label %17, label %15
15: ; preds = %8
%16 = icmp slt i32 %13, %6
br i1 %16, label %17, label %20
17: ; preds = %15, %8
%18 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0), %8 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.9, i64 0, i64 0), %15 ]
%19 = call i32 @puts(i8* dereferenceable(1) %18)
br label %20
20: ; preds = %17, %15
%21 = load i32, i32* %1
%22 = icmp ne i32 %21, %6
%23 = icmp ugt i32 %9, 1
%24 = and i1 %23, %22
br i1 %24, label %8, label %25
25: ; preds = %20
br i1 %22, label %26, label %28
26: ; preds = %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %6)
br label %32
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
%30 = sub nsw i32 11, %9
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %26
ret i32 0
}