#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 /*<<< orphan*/ puts(char *);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int i;
  int stage;
  int no;
  int ans;
  int num[10];
  srand(time(NULL));
  ans = rand() % 1000;
  printf("Please guess a 0~999 integer.\n\n");
  stage = 0;
  do {
    printf("Last %d chance. Wat is it: ", 10 - stage);
    scanf("%d", &no);
    num[stage++] = no;
    if (no > ans)
      printf("\aSmaller.\n");
    else if (no < ans)
      printf("\aBigger.\n");
  } while (no != ans && stage < 10);
  if (no != ans)
    printf("\aSorry, the correct answer is %d .\n", ans);
  else {
    printf("Correct.\n");
    printf("You use %d hit the correct answer.\n", stage);
  }
  puts("\n------ Input record ------");
  for (i = 0; i < stage; i++)
    printf("  %2d : %4d %+4d\n", i + 1, num[i], num[i] - ans);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    $0xa,%esi
sub    -0xc(%rbp),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe79(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
cltq
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11ff <main+0x9f>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121e <main+0xbe>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1219 <main+0xb9>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121e <main+0xbe>
jmp    1223 <main+0xc3>
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x41(%rbp)
je     123e <main+0xde>
cmpl   $0xa,-0xc(%rbp)
setl   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11a6 <main+0x46>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     126b <main+0x10b>
mov    -0x14(%rbp),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    128a <main+0x12a>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12de <main+0x17e>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
movslq -0x8(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
movslq -0x8(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
sub    -0x14(%rbp),%ecx
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    129d <main+0x13d>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
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    0xeeb(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%ebp
lea    0xc(%rsp),%r13
lea    0xf06(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe29(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe35(%rip),%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x10(%rsp,%rbx,4)
mov    %r15,%rdi
cmp    %r14d,%eax
jg     1208 <main+0xa8>
lea    0xeb7(%rip),%rdi
jge    120d <main+0xad>
call   1030 <puts@plt>
mov    0xc(%rsp),%eax
lea    0x1(%rbx),%r12
cmp    %r14d,%eax
je     1226 <main+0xc6>
add    $0xffffffff,%ebp
cmp    $0x9,%rbx
mov    %r12,%rbx
jb     11d0 <main+0x70>
cmp    %r14d,%eax
je     1237 <main+0xd7>
lea    0xded(%rip),%rdi
mov    %r14d,%esi
jmp    124d <main+0xed>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf9(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r12
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffffffffffff,%rbx
lea    0xe11(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x14(%rsp,%rbx,4),%edx
mov    %edx,%ecx
sub    %r14d,%ecx
lea    0x2(%rbx),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1280 <main+0x120>
xor    %eax,%eax
add    $0x38,%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 = [28 x i8] c"Last %d chance. Wat 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 = [36 x i8] c"\07Sorry, the correct answer is %d .\0A\00"
@.str.6 = [10 x i8] c"Correct.\0A\00"
@.str.7 = [36 x i8] c"You use %d hit the correct answer.\0A\00"
@.str.8 = [28 x i8] c"\0A------ Input record ------\00"
@.str.9 = [18 x i8] c" %2d : %4d %+4d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i32]
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 1000
store i32 %10, i32* %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %12
12: ; preds = %42, %0
%13 = load i32, i32* %3
%14 = sub nsw i32 10, %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %20
store i32 %17, i32* %21
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %12
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %34
27: ; preds = %12
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
br label %34
34: ; preds = %33, %25
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = load i32, i32* %5
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %3
%41 = icmp slt i32 %40, 10
br label %42
42: ; preds = %39, %35
%43 = phi i1 [ false, %35 ], [ %41, %39 ]
br i1 %43, label %12, label %44
44: ; preds = %42
%45 = load i32, i32* %4
%46 = load i32, i32* %5
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %49)
br label %55
51: ; preds = %44
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%53 = load i32, i32* %3
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %51, %48
%56 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %2
br label %57
57: ; preds = %75, %55
%58 = load i32, i32* %2
%59 = load i32, i32* %3
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %78
61: ; preds = %57
%62 = load i32, i32* %2
%63 = add nsw i32 %62, 1
%64 = load i32, i32* %2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %65
%67 = load i32, i32* %66
%68 = load i32, i32* %2
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = load i32, i32* %5
%73 = sub nsw i32 %71, %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32 %63, i32 %67, i32 %73)
br label %75
75: ; preds = %61
%76 = load i32, i32* %2
%77 = add nsw i32 %76, 1
store i32 %77, i32* %2
br label %57
78: ; preds = %57
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"Last %d chance. Wat is it: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [36 x i8] c"\07Sorry, the correct answer is %d .\0A\00"
@.str.7 = [36 x i8] c"You use %d hit the correct answer.\0A\00"
@.str.8 = [28 x i8] c"\0A------ Input record ------\00"
@.str.9 = [18 x i8] c" %2d : %4d %+4d\0A\00"
@str = [31 x i8] c"Please guess a 0~999 integer.\0A\00"
@str.10 = [9 x i8] c"Correct.\00"
@str.11 = [9 x i8] c"\07Bigger.\00"
@str.12 = [10 x i8] c"\07Smaller.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [10 x i32]* %2 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 1000
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %25, %0
%11 = phi i64 [ %17, %25 ], [ 0, %0 ]
%12 = trunc i64 %11 to i32
%13 = sub nuw nsw i32 10, %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
%17 = add nuw nsw i64 %11, 1
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %11
store i32 %16, i32* %18
%19 = icmp sgt i32 %16, %8
br i1 %19, label %22, label %20
20: ; preds = %10
%21 = icmp slt i32 %16, %8
br i1 %21, label %22, label %25
22: ; preds = %20, %10
%23 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.12, i64 0, i64 0), %10 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.11, i64 0, i64 0), %20 ]
%24 = call i32 @puts(i8* dereferenceable(1) %23)
br label %25
25: ; preds = %22, %20
%26 = load i32, i32* %1
%27 = icmp ne i32 %26, %8
%28 = icmp ult i64 %11, 9
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %10, label %30
30: ; preds = %25
br i1 %27, label %31, label %33
31: ; preds = %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %8)
br label %37
33: ; preds = %30
%34 = trunc i64 %17 to i32
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.10, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %34)
br label %37
37: ; preds = %33, %31
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %39
39: ; preds = %37, %39
%40 = phi i64 [ 0, %37 ], [ %41, %39 ]
%41 = add nuw nsw i64 %40, 1
%42 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %40
%43 = load i32, i32* %42
%44 = sub nsw i32 %43, %8
%45 = trunc i64 %41 to i32
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32 %45, i32 %43, i32 %44)
%47 = icmp eq i64 %40, %11
br i1 %47, label %48, label %39
48: ; preds = %39
ret i32 0
}