#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 */
scalar_t__ EOF;
int /*<<< orphan*/ print(int);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  int j = 1;
  int command[50] = {0};
  char text[14] = {0};
  while (scanf("%s", text) != EOF) {
    if (!strcmp(text, "button_clicked")) {
      command[j++] = 1;
    }
    if (!strcmp(text, "cycle_complete")) {
      command[j++] = 2;
    }
  }
  int state = 0;
  for (int i = 1; i <= j; i++) {
    print(state);
    if (command[i] == 1 && state == 0) {
      state = 1;
      continue;
    }
    if (command[i] == 1 && state == 2) {
      state = 3;
      continue;
    }
    if (command[i] == 1 && state == 5) {
      state = 3;
      continue;
    }
    if (command[i] == 1 && state == 4) {
      state = 1;
      continue;
    }
    if (command[i] == 1 && state == 1) {
      state = 5;
      continue;
    }
    if (command[i] == 1 && state == 3) {
      state = 4;
      continue;
    }
    if (command[i] == 2 && state == 3) {
      state = 0;
      continue;
    }
    if (command[i] == 2 && state == 1) {
      state = 2;
      continue;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1030 <memset@plt>
lea    -0xde(%rbp),%rdi
xor    %esi,%esi
mov    $0xe,%edx
call   1030 <memset@plt>
lea    -0xde(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
je     120f <main+0xcf>
lea    -0xde(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11d6 <main+0x96>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
movl   $0x1,-0xd0(%rbp,%rax,4)
lea    -0xde(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    120a <main+0xca>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
movl   $0x2,-0xd0(%rbp,%rax,4)
jmp    117f <main+0x3f>
movl   $0x0,-0xe4(%rbp)
movl   $0x1,-0xe8(%rbp)
mov    -0xe8(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     13de <main+0x29e>
mov    -0xe4(%rbp),%edi
call   1040 <print@plt>
movslq -0xe8(%rbp),%rax
cmpl   $0x1,-0xd0(%rbp,%rax,4)
01
jne    126e <main+0x12e>
cmpl   $0x0,-0xe4(%rbp)
jne    126e <main+0x12e>
movl   $0x1,-0xe4(%rbp)
jmp    13ca <main+0x28a>
movslq -0xe8(%rbp),%rax
cmpl   $0x1,-0xd0(%rbp,%rax,4)
01
jne    129f <main+0x15f>
cmpl   $0x2,-0xe4(%rbp)
jne    129f <main+0x15f>
movl   $0x3,-0xe4(%rbp)
jmp    13ca <main+0x28a>
movslq -0xe8(%rbp),%rax
cmpl   $0x1,-0xd0(%rbp,%rax,4)
01
jne    12d0 <main+0x190>
cmpl   $0x5,-0xe4(%rbp)
jne    12d0 <main+0x190>
movl   $0x3,-0xe4(%rbp)
jmp    13ca <main+0x28a>
movslq -0xe8(%rbp),%rax
cmpl   $0x1,-0xd0(%rbp,%rax,4)
01
jne    1301 <main+0x1c1>
cmpl   $0x4,-0xe4(%rbp)
jne    1301 <main+0x1c1>
movl   $0x1,-0xe4(%rbp)
jmp    13ca <main+0x28a>
movslq -0xe8(%rbp),%rax
cmpl   $0x1,-0xd0(%rbp,%rax,4)
01
jne    1332 <main+0x1f2>
cmpl   $0x1,-0xe4(%rbp)
jne    1332 <main+0x1f2>
movl   $0x5,-0xe4(%rbp)
jmp    13ca <main+0x28a>
movslq -0xe8(%rbp),%rax
cmpl   $0x1,-0xd0(%rbp,%rax,4)
01
jne    1363 <main+0x223>
cmpl   $0x3,-0xe4(%rbp)
jne    1363 <main+0x223>
movl   $0x4,-0xe4(%rbp)
jmp    13ca <main+0x28a>
movslq -0xe8(%rbp),%rax
cmpl   $0x2,-0xd0(%rbp,%rax,4)
02
jne    1394 <main+0x254>
cmpl   $0x3,-0xe4(%rbp)
jne    1394 <main+0x254>
movl   $0x0,-0xe4(%rbp)
jmp    13ca <main+0x28a>
movslq -0xe8(%rbp),%rax
cmpl   $0x2,-0xd0(%rbp,%rax,4)
02
jne    13c5 <main+0x285>
cmpl   $0x1,-0xe4(%rbp)
jne    13c5 <main+0x285>
movl   $0x2,-0xe4(%rbp)
jmp    13ca <main+0x28a>
jmp    13ca <main+0x28a>
mov    -0xe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe8(%rbp)
jmp    1223 <main+0xe3>
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0xd0(%rsp)
movq   $0x0,0x6(%rsp)
movq   $0x0,(%rsp)
lea    0xe4d(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    0x2e26(%rip),%rbp
mov    $0x1,%r13d
cmp    0x0(%rbp),%rax
je     1248 <main+0x118>
mov    $0x1,%r13d
lea    0xe28(%rip),%r14
mov    %rsp,%rbx
lea    0xe2d(%rip),%r15
lea    0xe14(%rip),%r12
jmp    1201 <main+0xd1>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    0x0(%rbp),%rax
je     123f <main+0x10f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    121f <main+0xef>
movslq %r13d,%rax
add    $0x1,%r13d
movl   $0x1,0x10(%rsp,%rax,4)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    11f0 <main+0xc0>
movslq %r13d,%rax
add    $0x1,%r13d
movl   $0x2,0x10(%rsp,%rax,4)
jmp    11f0 <main+0xc0>
test   %r13d,%r13d
jle    12f7 <main+0x1c7>
add    $0x1,%r13d
xor    %ebp,%ebp
mov    $0x1,%ebx
jmp    126f <main+0x13f>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
mov    %ecx,%ebp
cmp    %rbx,%r13
je     12f7 <main+0x1c7>
mov    %ebp,%edi
call   1030 <print@plt>
mov    0x10(%rsp,%rbx,4),%eax
mov    $0x1,%ecx
cmp    $0x1,%eax
jne    1288 <main+0x158>
test   %ebp,%ebp
je     1260 <main+0x130>
cmp    $0x2,%ebp
sete   %cl
cmp    $0x5,%ebp
sete   %dl
cmp    $0x1,%eax
jne    12a2 <main+0x172>
or     %dl,%cl
mov    $0x3,%ecx
jne    1260 <main+0x130>
cmp    $0x1,%eax
jne    12b1 <main+0x181>
mov    $0x1,%ecx
cmp    $0x4,%ebp
je     1260 <main+0x130>
cmp    $0x1,%eax
jne    12c0 <main+0x190>
mov    $0x5,%ecx
cmp    $0x1,%ebp
je     1260 <main+0x130>
cmp    $0x1,%eax
jne    12cf <main+0x19f>
mov    $0x4,%ecx
cmp    $0x3,%ebp
je     1260 <main+0x130>
cmp    $0x2,%eax
jne    12db <main+0x1ab>
xor    %ecx,%ecx
cmp    $0x3,%ebp
je     1260 <main+0x130>
xor    $0x2,%eax
mov    %ebp,%ecx
xor    $0x1,%ecx
or     %eax,%ecx
mov    $0x2,%ecx
je     1260 <main+0x130>
mov    %ebp,%ecx
jmp    1260 <main+0x130>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.1 = [15 x i8] c"button_clicked\00"
@.str.2 = [15 x i8] c"cycle_complete\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i32]
%4 = alloca [14 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%7 = bitcast [50 x i32]* %3 to i8*
%8 = bitcast [14 x i8]* %4 to i8*
br label %9
9: ; preds = %32, %0
%10 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%11 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i64, i64* @EOF
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %9
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %21
store i32 1, i32* %22
br label %23
23: ; preds = %18, %14
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %30
store i32 2, i32* %31
br label %32
32: ; preds = %27, %23
br label %9
33: ; preds = %9
store i32 0, i32* %5
store i32 1, i32* %6
br label %34
34: ; preds = %121, %33
%35 = load i32, i32* %6
%36 = load i32, i32* %2
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %124
38: ; preds = %34
%39 = load i32, i32* %5
%40 = call i32 @print(i32 %39)
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %50
46: ; preds = %38
%47 = load i32, i32* %5
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 1, i32* %5
br label %121
50: ; preds = %46, %38
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %60
56: ; preds = %50
%57 = load i32, i32* %5
%58 = icmp eq i32 %57, 2
br i1 %58, label %59, label %60
59: ; preds = %56
store i32 3, i32* %5
br label %121
60: ; preds = %56, %50
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = icmp eq i32 %64, 1
br i1 %65, label %66, label %70
66: ; preds = %60
%67 = load i32, i32* %5
%68 = icmp eq i32 %67, 5
br i1 %68, label %69, label %70
69: ; preds = %66
store i32 3, i32* %5
br label %121
70: ; preds = %66, %60
%71 = load i32, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = icmp eq i32 %74, 1
br i1 %75, label %76, label %80
76: ; preds = %70
%77 = load i32, i32* %5
%78 = icmp eq i32 %77, 4
br i1 %78, label %79, label %80
79: ; preds = %76
store i32 1, i32* %5
br label %121
80: ; preds = %76, %70
%81 = load i32, i32* %6
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %82
%84 = load i32, i32* %83
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %90
86: ; preds = %80
%87 = load i32, i32* %5
%88 = icmp eq i32 %87, 1
br i1 %88, label %89, label %90
89: ; preds = %86
store i32 5, i32* %5
br label %121
90: ; preds = %86, %80
%91 = load i32, i32* %6
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %92
%94 = load i32, i32* %93
%95 = icmp eq i32 %94, 1
br i1 %95, label %96, label %100
96: ; preds = %90
%97 = load i32, i32* %5
%98 = icmp eq i32 %97, 3
br i1 %98, label %99, label %100
99: ; preds = %96
store i32 4, i32* %5
br label %121
100: ; preds = %96, %90
%101 = load i32, i32* %6
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %102
%104 = load i32, i32* %103
%105 = icmp eq i32 %104, 2
br i1 %105, label %106, label %110
106: ; preds = %100
%107 = load i32, i32* %5
%108 = icmp eq i32 %107, 3
br i1 %108, label %109, label %110
109: ; preds = %106
store i32 0, i32* %5
br label %121
110: ; preds = %106, %100
%111 = load i32, i32* %6
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [50 x i32], [50 x i32]* %3, i64 0, i64 %112
%114 = load i32, i32* %113
%115 = icmp eq i32 %114, 2
br i1 %115, label %116, label %120
116: ; preds = %110
%117 = load i32, i32* %5
%118 = icmp eq i32 %117, 1
br i1 %118, label %119, label %120
119: ; preds = %116
store i32 2, i32* %5
br label %121
120: ; preds = %116, %110
br label %121
121: ; preds = %120, %119, %109, %99, %89, %79, %69, %59, %49
%122 = load i32, i32* %6
%123 = add nsw i32 %122, 1
store i32 %123, i32* %6
br label %34
124: ; preds = %34
%125 = load i32, i32* %1
ret i32 %125
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.1 = [15 x i8] c"button_clicked\00"
@.str.2 = [15 x i8] c"cycle_complete\00"
define i32 @main() {
%1 = alloca [50 x i32]
%2 = alloca [14 x i8]
%3 = bitcast [50 x i32]* %1 to i8*
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %10, label %14
8: ; preds = %30
%9 = icmp slt i32 %31, 1
br i1 %9, label %35, label %10
10: ; preds = %0, %8
%11 = phi i32 [ %31, %8 ], [ 1, %0 ]
%12 = add nuw i32 %11, 1
%13 = zext i32 %12 to i64
br label %36
14: ; preds = %0, %30
%15 = phi i32 [ %31, %30 ], [ 1, %0 ]
%16 = call i32 @strcmp(i8* %4, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = add nsw i32 %15, 1
%20 = sext i32 %15 to i64
%21 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %20
store i32 1, i32* %21
br label %22
22: ; preds = %18, %14
%23 = phi i32 [ %15, %14 ], [ %19, %18 ]
%24 = call i32 @strcmp(i8* %4, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = add nsw i32 %23, 1
%28 = sext i32 %23 to i64
%29 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %28
store i32 2, i32* %29
br label %30
30: ; preds = %26, %22
%31 = phi i32 [ %23, %22 ], [ %27, %26 ]
%32 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %8, label %14
35: ; preds = %65, %8
ret i32 0
36: ; preds = %10, %65
%37 = phi i64 [ 1, %10 ], [ %67, %65 ]
%38 = phi i32 [ 0, %10 ], [ %66, %65 ]
%39 = call i32 @print(i32 %38)
%40 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %37
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 1
%43 = icmp eq i32 %38, 0
%44 = and i1 %42, %43
br i1 %44, label %65, label %45
45: ; preds = %36
%46 = icmp eq i32 %38, 2
%47 = icmp eq i32 %38, 5
%48 = or i1 %46, %47
%49 = and i1 %42, %48
br i1 %49, label %65, label %50
50: ; preds = %45
%51 = icmp eq i32 %38, 4
%52 = and i1 %42, %51
br i1 %52, label %65, label %53
53: ; preds = %50
%54 = icmp eq i32 %38, 1
%55 = and i1 %42, %54
br i1 %55, label %65, label %56
56: ; preds = %53
%57 = icmp eq i32 %38, 3
%58 = and i1 %42, %57
br i1 %58, label %65, label %59
59: ; preds = %56
%60 = icmp eq i32 %41, 2
%61 = and i1 %60, %57
br i1 %61, label %65, label %62
62: ; preds = %59
%63 = and i1 %60, %54
%64 = select i1 %63, i32 2, i32 %38
br label %65
65: ; preds = %59, %56, %53, %50, %45, %36, %62
%66 = phi i32 [ %64, %62 ], [ 1, %36 ], [ 3, %45 ], [ 1, %50 ], [ 5, %53 ], [ 4, %56 ], [ 0, %59 ]
%67 = add nuw nsw i64 %37, 1
%68 = icmp eq i64 %67, %13
br i1 %68, label %35, label %36
}