#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, int, int);
void main() {
  int i, N = 5;
  int ping = 0, gai = 0, shengyu = 0;
  int Ben = 0;
  for (i = 1; i <= N; i++) {
    ping++;
    gai++;
    printf("     瓶 %d  盖:%d 酒:%d\n", ping, gai, N);
    if (ping == 2 && ping > 0) {
      ping = ping - 2;
      N = N + 1;
      printf("兑换:瓶 %d  盖:%d 酒:%d\n", ping, gai, N);
    }
    if (gai == 4 && gai > 0) {
      gai = gai - 4;
      N = N + 1;
      printf("兑换:瓶 %d  盖:%d 酒:%d\n", ping, gai, N);
    }
  }
  while (1) {
    if (ping > 0) {
      N++;
      ping++;
      gai++;
      printf("借瓶:瓶 %d  盖:%d 酒:%d\n", ping, gai, N);
      ping = ping - 2;
      printf("兑换:瓶 %d  盖:%d 酒:%d\n", ping, gai, N);
    } else if (gai >= 2) {
      N = N + gai;
      gai = 4 - gai;
      printf("兑换:瓶 %d  盖:%d 酒:%d\n", ping, gai, N);
    } else {
      break;
    }
  }
  printf("总共喝了 %d 瓶, 剩余 空瓶 %d  瓶盖 %d\n", N, ping, gai);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x5,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11fe <main+0xee>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0xc(%rbp)
jne    11b0 <main+0xa0>
cmpl   $0x0,-0xc(%rbp)
jle    11b0 <main+0xa0>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x4,-0x10(%rbp)
jne    11eb <main+0xdb>
cmpl   $0x0,-0x10(%rbp)
jle    11eb <main+0xdb>
mov    -0x10(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    11f0 <main+0xe0>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1142 <main+0x32>
jmp    1203 <main+0xf3>
cmpl   $0x0,-0xc(%rbp)
jle    1260 <main+0x150>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xdc6(%rip),%rdi
call   1030 <printf@plt>
jmp    12a2 <main+0x192>
cmpl   $0x2,-0x10(%rbp)
jl     1298 <main+0x188>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x4,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xd8e(%rip),%rdi
call   1030 <printf@plt>
jmp    129d <main+0x18d>
jmp    12a7 <main+0x197>
jmp    12a2 <main+0x192>
jmp    1203 <main+0xf3>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xda1(%rip),%rdi
call   1030 <printf@plt>
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
mov    $0x5,%r13d
xor    %r12d,%r12d
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    1153 <main+0x43>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
xor    %ebx,%ebx
lea    0xedf(%rip),%rdi
mov    %r15d,%esi
xor    %edx,%edx
mov    %r13d,%ecx
call   1030 <printf@plt>
add    $0x1,%r12d
cmp    %r13d,%r12d
jge    11a3 <main+0x93>
mov    %r15d,%r14d
lea    0x1(%r14),%r15d
lea    0x1(%rbx),%ebp
lea    0xe9c(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
call   1030 <printf@plt>
cmp    $0x1,%r14d
je     1180 <main+0x70>
cmp    $0x3,%ebx
jne    119f <main+0x8f>
jmp    1130 <main+0x20>
xchg   %ax,%ax
add    $0x1,%r13d
xor    %r15d,%r15d
lea    0xe8e(%rip),%rdi
xor    %esi,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
call   1030 <printf@plt>
cmp    $0x3,%ebx
je     1130 <main+0x20>
mov    %ebp,%ebx
jmp    114a <main+0x3a>
lea    0xe90(%rip),%r14
lea    0xe6b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %r15d,%r15d
jg     11e8 <main+0xd8>
cmp    $0x2,%ebx
jl     1216 <main+0x106>
add    %ebx,%r13d
mov    $0x4,%ebp
sub    %ebx,%ebp
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
call   1030 <printf@plt>
mov    %ebp,%ebx
jmp    11c0 <main+0xb0>
add    $0x1,%r13d
lea    0x1(%r15),%esi
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%edx
mov    %r13d,%ecx
call   1030 <printf@plt>
add    $0xffffffff,%r15d
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
call   1030 <printf@plt>
jmp    11c0 <main+0xb0>
lea    0xe3b(%rip),%rdi
mov    %r13d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [28 x i8] c" \E7\93\B6 %d \E7\9B\96:%d \E9\85\92:%d\0A\00"
@.str.1 = [30 x i8] c"\E5\85\91\E6\8D\A2:\E7\93\B6 %d \E7\9B\96:%d \E9\85\92:%d\0A\00"
@.str.2 = [30 x i8] c"\E5\80\9F\E7\93\B6:\E7\93\B6 %d \E7\9B\96:%d \E9\85\92:%d\0A\00"
@.str.3 = [50 x i8] c"\E6\80\BB\E5\85\B1\E5\96\9D\E4\BA\86 %d \E7\93\B6, \E5\89\A9\E4\BD\99 \E7\A9\BA\E7\93\B6 %d \E7\93\B6\E7\9B\96 %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 5, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 1, i32* %1
br label %7
7: ; preds = %50, %0
%8 = load i32, i32* %1
%9 = load i32, i32* %2
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %53
11: ; preds = %7
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %34
22: ; preds = %11
%23 = load i32, i32* %3
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 2
store i32 %27, i32* %3
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = load i32, i32* %2
%33 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
br label %34
34: ; preds = %25, %22, %11
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %49
37: ; preds = %34
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 4
store i32 %42, i32* %4
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
%45 = load i32, i32* %3
%46 = load i32, i32* %4
%47 = load i32, i32* %2
%48 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 %46, i32 %47)
br label %49
49: ; preds = %40, %37, %34
br label %50
50: ; preds = %49
%51 = load i32, i32* %1
%52 = add nsw i32 %51, 1
store i32 %52, i32* %1
br label %7
53: ; preds = %7
br label %54
54: ; preds = %53, %89
%55 = load i32, i32* %3
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %74
57: ; preds = %54
%58 = load i32, i32* %2
%59 = add nsw i32 %58, 1
store i32 %59, i32* %2
%60 = load i32, i32* %3
%61 = add nsw i32 %60, 1
store i32 %61, i32* %3
%62 = load i32, i32* %4
%63 = add nsw i32 %62, 1
store i32 %63, i32* %4
%64 = load i32, i32* %3
%65 = load i32, i32* %4
%66 = load i32, i32* %2
%67 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %64, i32 %65, i32 %66)
%68 = load i32, i32* %3
%69 = sub nsw i32 %68, 2
store i32 %69, i32* %3
%70 = load i32, i32* %3
%71 = load i32, i32* %4
%72 = load i32, i32* %2
%73 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %70, i32 %71, i32 %72)
br label %89
74: ; preds = %54
%75 = load i32, i32* %4
%76 = icmp sge i32 %75, 2
br i1 %76, label %77, label %87
77: ; preds = %74
%78 = load i32, i32* %2
%79 = load i32, i32* %4
%80 = add nsw i32 %78, %79
store i32 %80, i32* %2
%81 = load i32, i32* %4
%82 = sub nsw i32 4, %81
store i32 %82, i32* %4
%83 = load i32, i32* %3
%84 = load i32, i32* %4
%85 = load i32, i32* %2
%86 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %83, i32 %84, i32 %85)
br label %88
87: ; preds = %74
br label %90
88: ; preds = %77
br label %89
89: ; preds = %88, %57
br label %54
90: ; preds = %87
%91 = load i32, i32* %2
%92 = load i32, i32* %3
%93 = load i32, i32* %4
%94 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %91, i32 %92, i32 %93)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c" \E7\93\B6 %d \E7\9B\96:%d \E9\85\92:%d\0A\00"
@.str.1 = [30 x i8] c"\E5\85\91\E6\8D\A2:\E7\93\B6 %d \E7\9B\96:%d \E9\85\92:%d\0A\00"
@.str.2 = [30 x i8] c"\E5\80\9F\E7\93\B6:\E7\93\B6 %d \E7\9B\96:%d \E9\85\92:%d\0A\00"
@.str.3 = [50 x i8] c"\E6\80\BB\E5\85\B1\E5\96\9D\E4\BA\86 %d \E7\93\B6, \E5\89\A9\E4\BD\99 \E7\A9\BA\E7\93\B6 %d \E7\93\B6\E7\9B\96 %d\0A\00"
define void @main() {
br label %1
1: ; preds = %0, %20
%2 = phi i32 [ 1, %0 ], [ %23, %20 ]
%3 = phi i32 [ 5, %0 ], [ %22, %20 ]
%4 = phi i32 [ 0, %0 ], [ %21, %20 ]
%5 = phi i32 [ 0, %0 ], [ %14, %20 ]
%6 = add nsw i32 %5, 1
%7 = add nsw i32 %4, 1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7, i32 %3)
%9 = icmp eq i32 %5, 1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = add nsw i32 %3, 1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %7, i32 %11)
br label %13
13: ; preds = %10, %1
%14 = phi i32 [ 0, %10 ], [ %6, %1 ]
%15 = phi i32 [ %11, %10 ], [ %3, %1 ]
%16 = icmp eq i32 %4, 3
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = add nsw i32 %15, 1
%19 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 0, i32 %18)
br label %20
20: ; preds = %13, %17
%21 = phi i32 [ 0, %17 ], [ %7, %13 ]
%22 = phi i32 [ %18, %17 ], [ %15, %13 ]
%23 = add nuw nsw i32 %2, 1
%24 = icmp slt i32 %2, %22
br i1 %24, label %1, label %25
25: ; preds = %20, %33
%26 = phi i32 [ %38, %33 ], [ %14, %20 ]
%27 = phi i32 [ %36, %33 ], [ %21, %20 ]
%28 = phi i32 [ %34, %33 ], [ %22, %20 ]
%29 = icmp sgt i32 %26, 0
br label %30
30: ; preds = %25, %42
%31 = phi i32 [ %44, %42 ], [ %27, %25 ]
%32 = phi i32 [ %43, %42 ], [ %28, %25 ]
br i1 %29, label %33, label %40
33: ; preds = %30
%34 = add nsw i32 %32, 1
%35 = add nuw nsw i32 %26, 1
%36 = add nsw i32 %31, 1
%37 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %36, i32 %34)
%38 = add nsw i32 %26, -1
%39 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %36, i32 %34)
br label %25
40: ; preds = %30
%41 = icmp sgt i32 %31, 1
br i1 %41, label %42, label %46
42: ; preds = %40
%43 = add nsw i32 %32, %31
%44 = sub nsw i32 4, %31
%45 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %44, i32 %43)
br label %30
46: ; preds = %40
%47 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %26, i32 %31)
ret void
}