#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 human;
  int comp;
  int judge;
  int retry;
  char *hd[] = {"石头", "剪刀", "布"};
  srand(time(NULL));
  printf("Game start!!\n");
  do {
    comp = rand() % 3;
    do {
      printf("\n\a Stone Scissor Cloth...");
      for (i = 0; i < 3; i++)
        printf(" (%d)%s", i, hd[i]);
      printf(":");
      scanf("%d", &human);
    } while (human < 0 || human > 2);
    printf("I choose %s, you choose %s.\n", hd[comp], hd[human]);
    judge = (human - comp + 3) % 3;
    switch (judge) {
    case 0:
      puts("Same.");
      break;
    case 1:
      puts("You lose.");
      break;
    case 2:
      puts("You win.");
      break;
    }
    printf("Again ...(0)NO  (1)YES: ");
    scanf("%d", &retry);
  } while (retry == 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c8a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c87(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c84(%rip),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1207 <main+0xa7>
mov    -0x8(%rbp),%esi
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d5 <main+0x75>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe28(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    $0x1,%al
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x31(%rbp)
jl     123e <main+0xde>
cmpl   $0x2,-0xc(%rbp)
setg   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11c0 <main+0x60>
movslq -0x10(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdx
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    %ecx,%eax
add    $0x3,%eax
movslq %eax,%rcx
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     12ca <main+0x16a>
jmp    12a8 <main+0x148>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     12db <main+0x17b>
jmp    12b9 <main+0x159>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     12ec <main+0x18c>
jmp    12f8 <main+0x198>
lea    0xd93(%rip),%rdi
call   1030 <puts@plt>
jmp    12f8 <main+0x198>
lea    0xd88(%rip),%rdi
call   1030 <puts@plt>
jmp    12f8 <main+0x198>
lea    0xd81(%rip),%rdi
call   1030 <puts@plt>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd37(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
je     11ae <main+0x4e>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    0xef3(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8d(%rip),%rbx
lea    0xe8e(%rip),%r15
jmp    11d6 <main+0x66>
nopl   0x0(%rax,%rax,1)
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
lea    0x14(%rsp),%rsi
call   1080 <scanf@plt>
cmpl   $0x1,0x14(%rsp)
jne    12e6 <main+0x176>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,0x10(%rsp)
lea    0xe18(%rip),%r12
lea    0xe18(%rip),%r13
lea    0xe18(%rip),%r14
lea    0xc(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
lea    0xe0b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3a,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%rax
ja     1200 <main+0x90>
movslq 0x10(%rsp),%rcx
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rdx
add    %esi,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%ecx
movslq %ecx,%r14
lea    0x2b78(%rip),%rcx
mov    (%rcx,%r14,8),%rsi
mov    (%rcx,%rax,8),%rdx
lea    0xda0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
sub    %r14d,%eax
add    $0x3,%eax
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x2,%eax
ja     11b0 <main+0x40>
cltq
lea    0xdbf(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1040 <puts@plt>
jmp    11b0 <main+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\E7\9F\B3\E5\A4\B4\00"
@.str.1 = [7 x i8] c"\E5\89\AA\E5\88\80\00"
@.str.2 = [4 x i8] c"\E5\B8\83\00"
@__const.main.hd = [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [14 x i8] c"Game start!!\0A\00"
@.str.4 = [26 x i8] c"\0A\07 Stone Scissor Cloth...\00"
@.str.5 = [8 x i8] c" (%d)%s\00"
@.str.6 = [2 x i8] c":\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [29 x i8] c"I choose %s, you choose %s.\0A\00"
@.str.9 = [6 x i8] c"Same.\00"
@.str.10 = [10 x i8] c"You lose.\00"
@.str.11 = [9 x i8] c"You win.\00"
@.str.12 = [25 x i8] c"Again ...(0)NO (1)YES: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [3 x i8*]
store i32 0, i32* %1
%8 = bitcast [3 x i8*]* %7 to i8*
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %66, %0
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 3
store i32 %14, i32* %4
br label %15
15: ; preds = %39, %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %17
17: ; preds = %27, %15
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i32, i32* %2
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %21, i8* %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %17
30: ; preds = %17
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %3)
br label %33
33: ; preds = %30
%34 = load i32, i32* %3
%35 = icmp slt i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* %3
%38 = icmp sgt i32 %37, 2
br label %39
39: ; preds = %36, %33
%40 = phi i1 [ true, %33 ], [ %38, %36 ]
br i1 %40, label %15, label %41
41: ; preds = %39
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %45, i8* %49)
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = sub nsw i32 %51, %52
%54 = add nsw i32 %53, 3
%55 = srem i32 %54, 3
store i32 %55, i32* %5
%56 = load i32, i32* %5
switch i32 %56, label %63 [
i32 0, label %57
i32 1, label %59
i32 2, label %61
]
57: ; preds = %41
%58 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %63
59: ; preds = %41
%60 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
br label %63
61: ; preds = %41
%62 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %63
63: ; preds = %41, %61, %59, %57
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
%65 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %6)
br label %66
66: ; preds = %63
%67 = load i32, i32* %6
%68 = icmp eq i32 %67, 1
br i1 %68, label %12, label %69
69: ; preds = %66
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"\E7\9F\B3\E5\A4\B4\00"
@.str.1 = [7 x i8] c"\E5\89\AA\E5\88\80\00"
@.str.2 = [4 x i8] c"\E5\B8\83\00"
@__const.main.hd = [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0)]
@.str.4 = [26 x i8] c"\0A\07 Stone Scissor Cloth...\00"
@.str.5 = [8 x i8] c" (%d)%s\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [29 x i8] c"I choose %s, you choose %s.\0A\00"
@.str.9 = [6 x i8] c"Same.\00"
@.str.10 = [10 x i8] c"You lose.\00"
@.str.11 = [9 x i8] c"You win.\00"
@.str.12 = [25 x i8] c"Again ...(0)NO (1)YES: \00"
@str = [13 x i8] c"Game start!!\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.9 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.10 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.11 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %38, %0
%9 = call i32 (...) @rand()
br label %10
10: ; preds = %10, %8
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @putchar(i32 58)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = icmp ugt i32 %17, 2
br i1 %18, label %10, label %19
19: ; preds = %10
%20 = srem i32 %9, 3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.main.hd, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = zext i32 %17 to i64
%25 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.main.hd, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %23, i8* %26)
%28 = load i32, i32* %1
%29 = sub nsw i32 3, %20
%30 = add i32 %29, %28
%31 = srem i32 %30, 3
%32 = icmp ult i32 %31, 3
br i1 %32, label %33, label %38
33: ; preds = %19
%34 = sext i32 %31 to i64
%35 = shl i64 %34, 2
%36 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %35)
%37 = call i32 @puts(i8* dereferenceable(1) %36)
br label %38
38: ; preds = %19, %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %2)
%41 = load i32, i32* %2
%42 = icmp eq i32 %41, 1
br i1 %42, label %8, label %43
43: ; preds = %38
ret i32 0
}