#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*/ PrintState(char, char);
int /*<<< orphan*/ printf(char *);
scalar_t__ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main() {
  char state = -2, stopped = 1;
  char command[20];
  PrintState(state, stopped);
  while (scanf("%[^\n]%*c", command) != EOF) {
    if (strcmp(command, "button_clicked") == 0) {
      if (stopped == 1) {
        if (state == -2) {
          state = 1;
        } else if (state == -1) {
          state = 1;
        } else if (state == 1) {
          state = -1;
        } else if (state == 2) {
          state = -1;
        }
        stopped = 0;
      } else {
        stopped = 1;
      }
    } else if (strcmp(command, "cycle_complete") == 0) {
      if (stopped == 0) {
        if (state == 1) {
          state = 2;
        } else if (state == -1) {
          state = -2;
        }
        stopped = 1;
      }
    }
    printf("\n");
    PrintState(state, stopped);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0xfe,-0x5(%rbp)
movb   $0x1,-0x6(%rbp)
mov    -0x5(%rbp),%al
movsbl %al,%edi
movsbl -0x6(%rbp),%esi
call   1040 <PrintState@plt>
lea    -0x20(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
je     12a2 <main+0x162>
lea    -0x20(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1221 <main+0xe1>
movsbl -0x6(%rbp),%eax
cmp    $0x1,%eax
jne    1218 <main+0xd8>
movsbl -0x5(%rbp),%eax
cmp    $0xfffffffe,%eax
jne    11c3 <main+0x83>
movb   $0x1,-0x5(%rbp)
jmp    120f <main+0xcf>
movsbl -0x5(%rbp),%eax
cmp    $0xffffffff,%eax
jne    11d9 <main+0x99>
movb   $0x1,-0x5(%rbp)
jmp    120a <main+0xca>
movsbl -0x5(%rbp),%eax
cmp    $0x1,%eax
jne    11ef <main+0xaf>
movb   $0xff,-0x5(%rbp)
jmp    1205 <main+0xc5>
movsbl -0x5(%rbp),%eax
cmp    $0x2,%eax
jne    1200 <main+0xc0>
movb   $0xff,-0x5(%rbp)
jmp    1205 <main+0xc5>
jmp    120a <main+0xca>
jmp    120f <main+0xcf>
movb   $0x0,-0x6(%rbp)
jmp    121c <main+0xdc>
movb   $0x1,-0x6(%rbp)
jmp    1282 <main+0x142>
lea    -0x20(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    127d <main+0x13d>
movsbl -0x6(%rbp),%eax
cmp    $0x0,%eax
jne    1278 <main+0x138>
movsbl -0x5(%rbp),%eax
cmp    $0x1,%eax
jne    125e <main+0x11e>
movb   $0x2,-0x5(%rbp)
jmp    1274 <main+0x134>
movsbl -0x5(%rbp),%eax
cmp    $0xffffffff,%eax
jne    126f <main+0x12f>
movb   $0xfe,-0x5(%rbp)
jmp    1274 <main+0x134>
movb   $0x1,-0x6(%rbp)
jmp    127d <main+0x13d>
jmp    1282 <main+0x142>
lea    0xd9e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x5(%rbp),%al
movsbl %al,%edi
movsbl -0x6(%rbp),%esi
call   1040 <PrintState@plt>
jmp    1166 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xfffffffe,%edi
mov    $0x1,%esi
call   1040 <PrintState@plt>
lea    0xe9c(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    0x2e75(%rip),%r13
cmp    0x0(%r13),%rax
jne    118a <main+0x4a>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xfe,%bpl
mov    $0x1,%r12b
lea    0xe72(%rip),%r14
mov    %rsp,%rbx
lea    0xe5f(%rip),%r15
jmp    11e1 <main+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x1,%r12b
je     1228 <main+0xe8>
mov    $0x1,%r12b
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl %bpl,%edi
movsbl %r12b,%esi
call   1040 <PrintState@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    0x0(%r13),%rax
je     1179 <main+0x39>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b0 <main+0x70>
mov    %rbx,%rdi
lea    0xe1d(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b9 <main+0x79>
test   %r12b,%r12b
jne    11b9 <main+0x79>
cmp    $0xff,%bpl
movzbl %bpl,%eax
mov    %eax,%ebp
mov    $0xfe,%ecx
cmove  %ecx,%ebp
cmp    $0x1,%al
mov    $0x2,%eax
cmove  %eax,%ebp
jmp    11b6 <main+0x76>
lea    0x2(%rbp),%eax
cmp    $0x2,%al
jae    1237 <main+0xf7>
mov    $0x1,%bpl
xor    %r12d,%r12d
jmp    11b9 <main+0x79>
cmp    $0x1,%bpl
jne    1248 <main+0x108>
mov    $0xff,%bpl
xor    %r12d,%r12d
jmp    11b9 <main+0x79>
cmp    $0x2,%bpl
movzbl %bpl,%ebp
mov    $0xff,%eax
cmove  %eax,%ebp
xor    %r12d,%r12d
jmp    11b9 <main+0x79>

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

LLVM IR (-O2):
@.str = [9 x i8] c"%[^\0A]%*c\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 [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @PrintState(i8 signext -2, i8 signext 1)
%4 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %37, label %7
7: ; preds = %0, %29
%8 = phi i8 [ %31, %29 ], [ 1, %0 ]
%9 = phi i8 [ %30, %29 ], [ -2, %0 ]
%10 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %7
%13 = icmp eq i8 %8, 1
br i1 %13, label %14, label %29
14: ; preds = %12
switch i8 %9, label %16 [
i8 -2, label %29
i8 -1, label %29
i8 1, label %15
]
15: ; preds = %14
br label %29
16: ; preds = %14
%17 = icmp eq i8 %9, 2
%18 = select i1 %17, i8 -1, i8 %9
br label %29
19: ; preds = %7
%20 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = icmp eq i8 %8, 0
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = icmp eq i8 %9, 1
%26 = icmp eq i8 %9, -1
%27 = select i1 %26, i8 -2, i8 %9
%28 = select i1 %25, i8 2, i8 %27
br label %29
29: ; preds = %12, %15, %16, %14, %14, %19, %24
%30 = phi i8 [ %28, %24 ], [ %9, %19 ], [ -1, %15 ], [ %18, %16 ], [ 1, %14 ], [ 1, %14 ], [ %9, %12 ]
%31 = phi i8 [ 1, %24 ], [ %8, %19 ], [ 0, %15 ], [ 0, %16 ], [ 0, %14 ], [ 0, %14 ], [ 1, %12 ]
%32 = call i32 @putchar(i32 10)
%33 = call i32 @PrintState(i8 signext %30, i8 signext %31)
%34 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2)
%35 = load i64, i64* @EOF
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %7
37: ; preds = %29, %0
ret i32 0
}