#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*/ scanf(char *, int *);
int main(void) {
  int last = 21;
  int user;
  int computer;
  for (;;) {
    printf("还剩%d根火柴!\n", last);
    printf("用户取几根? ");
    scanf("%d", &user);
    if (user < 1 || user > 4 || user > last)
      continue;
    printf("你取了%d根火柴!\n", user);
    last -= user;
    if (last == 0) {
      printf("你取走了最后一支火柴,你失败!\n");
      break;
    }
    computer = 5 - user;
    printf("计算机取了%d根火柴!\n", computer);
    last -= computer;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x15,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0xc(%rbp)
jl     1185 <main+0x65>
cmpl   $0x4,-0xc(%rbp)
jg     1185 <main+0x65>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    118a <main+0x6a>
jmp    1136 <main+0x16>
mov    -0xc(%rbp),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11c3 <main+0xa3>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ef <main+0xcf>
mov    $0x5,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
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
mov    $0x15,%ebx
lea    0xeb9(%rip),%r14
lea    0xec6(%rip),%r15
lea    0xed1(%rip),%r12
lea    0x4(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%esi
lea    -0x5(%rsi),%eax
cmp    %ebx,%esi
jg     1160 <main+0x30>
cmp    $0xfffffffc,%eax
jb     1160 <main+0x30>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%eax
sub    %eax,%ebx
je     11c2 <main+0x92>
mov    $0x5,%ebp
sub    %eax,%ebp
lea    0xe8b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
sub    %ebp,%ebx
jmp    1160 <main+0x30>
lea    0xe94(%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 = [20 x i8] c"\E8\BF\98\E5\89\A9%d\E6\A0\B9\E7\81\AB\E6\9F\B4!\0A\00"
@.str.1 = [18 x i8] c"\E7\94\A8\E6\88\B7\E5\8F\96\E5\87\A0\E6\A0\B9? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"\E4\BD\A0\E5\8F\96\E4\BA\86%d\E6\A0\B9\E7\81\AB\E6\9F\B4!\0A\00"
@.str.4 = [43 x i8] c"\E4\BD\A0\E5\8F\96\E8\B5\B0\E4\BA\86\E6\9C\80\E5\90\8E\E4\B8\80\E6\94\AF\E7\81\AB\E6\9F\B4,\E4\BD\A0\E5\A4\B1\E8\B4\A5!\0A\00"
@.str.5 = [29 x i8] c"\E8\AE\A1\E7\AE\97\E6\9C\BA\E5\8F\96\E4\BA\86%d\E6\A0\B9\E7\81\AB\E6\9F\B4!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 21, i32* %2
br label %5
5: ; preds = %30, %19, %0
%6 = load i32, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 1
br i1 %11, label %19, label %12
12: ; preds = %5
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 4
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15, %12, %5
br label %5
20: ; preds = %15
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = load i32, i32* %2
%25 = sub nsw i32 %24, %23
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %38
30: ; preds = %20
%31 = load i32, i32* %3
%32 = sub nsw i32 5, %31
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %4
%36 = load i32, i32* %2
%37 = sub nsw i32 %36, %35
store i32 %37, i32* %2
br label %5
38: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"\E8\BF\98\E5\89\A9%d\E6\A0\B9\E7\81\AB\E6\9F\B4!\0A\00"
@.str.1 = [18 x i8] c"\E7\94\A8\E6\88\B7\E5\8F\96\E5\87\A0\E6\A0\B9? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [23 x i8] c"\E4\BD\A0\E5\8F\96\E4\BA\86%d\E6\A0\B9\E7\81\AB\E6\9F\B4!\0A\00"
@.str.5 = [29 x i8] c"\E8\AE\A1\E7\AE\97\E6\9C\BA\E5\8F\96\E4\BA\86%d\E6\A0\B9\E7\81\AB\E6\9F\B4!\0A\00"
@str = [42 x i8] c"\E4\BD\A0\E5\8F\96\E8\B5\B0\E4\BA\86\E6\9C\80\E5\90\8E\E4\B8\80\E6\94\AF\E7\81\AB\E6\9F\B4,\E4\BD\A0\E5\A4\B1\E8\B4\A5!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %21, %0
%4 = phi i32 [ %24, %21 ], [ 21, %0 ]
br label %5
5: ; preds = %3, %5
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = add i32 %9, -5
%11 = icmp ult i32 %10, -4
%12 = icmp sgt i32 %9, %4
%13 = or i1 %12, %11
br i1 %13, label %5, label %14
14: ; preds = %5
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%16 = load i32, i32* %1
%17 = sub nsw i32 %4, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
ret i32 0
21: ; preds = %14
%22 = sub nsw i32 5, %16
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = sub nsw i32 %17, %22
br label %3
}