#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*/ pr(char);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  char state = 0;
  char c[200] = {0};
  pr(0);
  while (scanf("%s", c) != EOF) {
    if (!strcmp(c, "cycle_complete")) {
      switch (state) {
      case 1:
        state = 2;
        pr(2);
        break;
      case 3:
        state = 0;
        pr(0);
        break;
      case 0:
        state = 0;
        pr(0);
        break;
      case 2:
        state = 2;
        pr(2);
        break;
      case 4:
        break;
      case 5:
        break;
      }
    }
    if (!strcmp(c, "button_clicked")) {
      switch (state) {
      case 1:
        state = 5;
        pr(state);
        break;
      case 3:
        state = 4;
        pr(state);
        break;
      case 0:
        state = 1;
        pr(state);
        break;
      case 2:
        state = 3;
        pr(state);
        break;
      case 4:
        state = 1;
        pr(state);
        break;
      case 5:
        state = 3;
        pr(state);
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1040 <memset@plt>
xor    %edi,%edi
call   1030 <pr@plt>
lea    -0xd0(%rbp),%rsi
lea    0xeb2(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%rax
je     12eb <main+0x1ab>
lea    -0xd0(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1231 <main+0xf1>
movsbl -0x5(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0xd8(%rbp)
sub    $0x5,%eax
ja     122c <main+0xec>
mov    -0xd8(%rbp),%rax
lea    0xe2d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x2,-0x5(%rbp)
mov    $0x2,%edi
call   1030 <pr@plt>
jmp    122c <main+0xec>
movb   $0x0,-0x5(%rbp)
xor    %edi,%edi
call   1030 <pr@plt>
jmp    122c <main+0xec>
movb   $0x0,-0x5(%rbp)
xor    %edi,%edi
call   1030 <pr@plt>
jmp    122c <main+0xec>
movb   $0x2,-0x5(%rbp)
mov    $0x2,%edi
call   1030 <pr@plt>
jmp    122c <main+0xec>
jmp    122c <main+0xec>
jmp    122c <main+0xec>
jmp    1231 <main+0xf1>
lea    -0xd0(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12e6 <main+0x1a6>
movsbl -0x5(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0xe0(%rbp)
sub    $0x5,%eax
ja     12e1 <main+0x1a1>
mov    -0xe0(%rbp),%rax
lea    0xda7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x5,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <pr@plt>
jmp    12e1 <main+0x1a1>
movb   $0x4,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <pr@plt>
jmp    12e1 <main+0x1a1>
movb   $0x1,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <pr@plt>
jmp    12e1 <main+0x1a1>
movb   $0x3,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <pr@plt>
jmp    12e1 <main+0x1a1>
movb   $0x1,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <pr@plt>
jmp    12e1 <main+0x1a1>
movb   $0x3,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <pr@plt>
jmp    12e6 <main+0x1a6>
jmp    1170 <main+0x30>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
xorps  %xmm0,%xmm0
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)
movaps %xmm0,(%rsp)
movq   $0x0,0xc0(%rsp)
xor    %edi,%edi
call   1030 <pr@plt>
lea    0xe6b(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    0x2e44(%rip),%r15
cmp    (%r15),%rax
jne    11bd <main+0x9d>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
movabs $0x635f6e6f74747562,%rbp
6e 5f 63
movabs $0x64656b63696c63,%r12
lea    0xe25(%rip),%r14
mov    %rsp,%rbx
jmp    11f0 <main+0xd0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
cmp    (%r15),%rax
je     11a9 <main+0x89>
mov    (%rsp),%rax
movabs $0x6f635f656c637963,%rcx
5f 63 6f
xor    %rcx,%rax
mov    0x7(%rsp),%rcx
movabs $0x6574656c706d6f,%rdx
xor    %rdx,%rcx
or     %rax,%rcx
jne    1237 <main+0x117>
cmp    $0x3,%r13b
ja     1237 <main+0x117>
movzbl %r13b,%ecx
shl    $0x3,%ecx
mov    $0x20200,%r13d
shr    %cl,%r13d
movsbl %r13b,%edi
call   1030 <pr@plt>
mov    (%rsp),%rax
xor    %rbp,%rax
mov    0x7(%rsp),%rcx
xor    %r12,%rcx
or     %rax,%rcx
jne    11e0 <main+0xc0>
cmp    $0x5,%r13b
ja     11e0 <main+0xc0>
movzbl %r13b,%ecx
shl    $0x3,%ecx
movabs $0x30104030501,%r13
shr    %cl,%r13
movsbl %r13b,%edi
call   1030 <pr@plt>
jmp    11e0 <main+0xc0>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.1 = [15 x i8] c"cycle_complete\00"
@.str.2 = [15 x i8] c"button_clicked\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [200 x i8]
store i32 0, i32* %1
store i8 0, i8* %2
%4 = bitcast [200 x i8]* %3 to i8*
%5 = call i32 @pr(i8 signext 0)
br label %6
6: ; preds = %55, %0
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%8 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %56
11: ; preds = %6
%12 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %11
%16 = load i8, i8* %2
%17 = sext i8 %16 to i32
switch i32 %17, label %28 [
i32 1, label %18
i32 3, label %20
i32 0, label %22
i32 2, label %24
i32 4, label %26
i32 5, label %27
]
18: ; preds = %15
store i8 2, i8* %2
%19 = call i32 @pr(i8 signext 2)
br label %28
20: ; preds = %15
store i8 0, i8* %2
%21 = call i32 @pr(i8 signext 0)
br label %28
22: ; preds = %15
store i8 0, i8* %2
%23 = call i32 @pr(i8 signext 0)
br label %28
24: ; preds = %15
store i8 2, i8* %2
%25 = call i32 @pr(i8 signext 2)
br label %28
26: ; preds = %15
br label %28
27: ; preds = %15
br label %28
28: ; preds = %15, %27, %26, %24, %22, %20, %18
br label %29
29: ; preds = %28, %11
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %55, label %33
33: ; preds = %29
%34 = load i8, i8* %2
%35 = sext i8 %34 to i32
switch i32 %35, label %54 [
i32 1, label %36
i32 3, label %39
i32 0, label %42
i32 2, label %45
i32 4, label %48
i32 5, label %51
]
36: ; preds = %33
store i8 5, i8* %2
%37 = load i8, i8* %2
%38 = call i32 @pr(i8 signext %37)
br label %54
39: ; preds = %33
store i8 4, i8* %2
%40 = load i8, i8* %2
%41 = call i32 @pr(i8 signext %40)
br label %54
42: ; preds = %33
store i8 1, i8* %2
%43 = load i8, i8* %2
%44 = call i32 @pr(i8 signext %43)
br label %54
45: ; preds = %33
store i8 3, i8* %2
%46 = load i8, i8* %2
%47 = call i32 @pr(i8 signext %46)
br label %54
48: ; preds = %33
store i8 1, i8* %2
%49 = load i8, i8* %2
%50 = call i32 @pr(i8 signext %49)
br label %54
51: ; preds = %33
store i8 3, i8* %2
%52 = load i8, i8* %2
%53 = call i32 @pr(i8 signext %52)
br label %54
54: ; preds = %33, %51, %48, %45, %42, %39, %36
br label %55
55: ; preds = %54, %29
br label %6
56: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.1 = [15 x i8] c"cycle_complete\00"
@.str.2 = [15 x i8] c"button_clicked\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @pr(i8 signext 0)
%4 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %36, label %7
7: ; preds = %0, %31
%8 = phi i8 [ %32, %31 ], [ 0, %0 ]
%9 = call i32 @bcmp(i8* dereferenceable(15) %2, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 15)
%10 = icmp eq i32 %9, 0
%11 = icmp ult i8 %8, 4
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = zext i8 %8 to i32
%15 = shl nuw nsw i32 %14, 3
%16 = lshr i32 131584, %15
%17 = trunc i32 %16 to i8
%18 = call i32 @pr(i8 signext %17)
br label %19
19: ; preds = %13, %7
%20 = phi i8 [ %8, %7 ], [ %17, %13 ]
%21 = call i32 @bcmp(i8* dereferenceable(15) %2, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 15)
%22 = icmp eq i32 %21, 0
%23 = icmp ult i8 %20, 6
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = zext i8 %20 to i48
%27 = shl nuw nsw i48 %26, 3
%28 = lshr i48 3302897157377, %27
%29 = trunc i48 %28 to i8
%30 = call i32 @pr(i8 signext %29)
br label %31
31: ; preds = %25, %19
%32 = phi i8 [ %20, %19 ], [ %29, %25 ]
%33 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%34 = load i64, i64* @EOF
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %7
36: ; preds = %31, %0
ret i32 0
}