#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*/ printf(char *);
scalar_t__ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main() {
  char input[30] = {'\0'};
  int command[20] = {2};
  int state = 0;
  int counter = 0;
  int counter2 = 0;
  while (scanf("%s", input) != EOF) {
    if (strcmp(input, "button_clicked") == 0) {
      command[counter] = 0;
    }
    if (strcmp(input, "cycle_complete") == 0) {
      command[counter] = 1;
    }
    counter++;
  }
  counter2 = 0;
  while (counter2 <= counter) {
    switch (state) {
    case 0:
      printf("\nDoor: CLOSED");
      break;
    case 1:
      printf("\nDoor: OPENING");
      break;
    case 2:
      printf("\nDoor: OPEN");
      break;
    case 3:
      printf("\nDoor: CLOSING");
      break;
    case 4:
      printf("\nDoor: STOPPED_WHILE_CLOSING");
      break;
    case 5:
      printf("\nDoor: STOPPED_WHILE_OPENING");
      break;
    default:
      return 1;
      break;
    }
    if (command[counter2] == 0) {
      switch (state) {
      case 0:
        state = 1;
        break;
      case 1:
        state = 5;
        break;
      case 2:
        state = 3;
        break;
      case 3:
        state = 4;
        break;
      case 4:
        state = 1;
        break;
      case 5:
        state = 3;
        break;
      default:
        return 1;
        break;
      }
    }
    if (command[counter2] == 1) {
      switch (state) {
      case 0:
        state = 0;
        break;
      case 1:
        state = 2;
        break;
      case 2:
        state = 2;
        break;
      case 3:
        state = 0;
        break;
      case 4:
        return 1;
        break;
      case 5:
        return 1;
        break;
      default:
        return 1;
        break;
      }
    }
    counter2++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1040 <memset@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
movl   $0x2,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
movl   $0x0,-0x88(%rbp)
movl   $0x0,-0x8c(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
je     121d <main+0xdd>
lea    -0x30(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e0 <main+0xa0>
movslq -0x88(%rbp),%rax
movl   $0x0,-0x80(%rbp,%rax,4)
lea    -0x30(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1209 <main+0xc9>
movslq -0x88(%rbp),%rax
movl   $0x1,-0x80(%rbp,%rax,4)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1197 <main+0x57>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x88(%rbp),%eax
jg     143d <main+0x2fd>
mov    -0x84(%rbp),%eax
mov    %rax,-0x98(%rbp)
sub    $0x5,%rax
ja     12cd <main+0x18d>
mov    -0x98(%rbp),%rax
lea    0xda2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
jmp    12d9 <main+0x199>
lea    0xdf8(%rip),%rdi
call   1030 <printf@plt>
jmp    12d9 <main+0x199>
lea    0xdf6(%rip),%rdi
call   1030 <printf@plt>
jmp    12d9 <main+0x199>
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
jmp    12d9 <main+0x199>
lea    0xdef(%rip),%rdi
call   1030 <printf@plt>
jmp    12d9 <main+0x199>
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
jmp    12d9 <main+0x199>
movl   $0x1,-0x4(%rbp)
jmp    1444 <main+0x304>
movslq -0x8c(%rbp),%rax
cmpl   $0x0,-0x80(%rbp,%rax,4)
jne    1384 <main+0x244>
mov    -0x84(%rbp),%eax
mov    %rax,-0xa0(%rbp)
sub    $0x5,%rax
ja     1373 <main+0x233>
mov    -0xa0(%rbp),%rax
lea    0xd08(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x84(%rbp)
jmp    137f <main+0x23f>
movl   $0x5,-0x84(%rbp)
jmp    137f <main+0x23f>
movl   $0x3,-0x84(%rbp)
jmp    137f <main+0x23f>
movl   $0x4,-0x84(%rbp)
jmp    137f <main+0x23f>
movl   $0x1,-0x84(%rbp)
jmp    137f <main+0x23f>
movl   $0x3,-0x84(%rbp)
jmp    137f <main+0x23f>
movl   $0x1,-0x4(%rbp)
jmp    1444 <main+0x304>
jmp    1384 <main+0x244>
movslq -0x8c(%rbp),%rax
cmpl   $0x1,-0x80(%rbp,%rax,4)
jne    1429 <main+0x2e9>
mov    -0x84(%rbp),%eax
mov    %rax,-0xa8(%rbp)
sub    $0x5,%rax
ja     1418 <main+0x2d8>
mov    -0xa8(%rbp),%rax
lea    0xc75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x84(%rbp)
jmp    1424 <main+0x2e4>
movl   $0x2,-0x84(%rbp)
jmp    1424 <main+0x2e4>
movl   $0x2,-0x84(%rbp)
jmp    1424 <main+0x2e4>
movl   $0x0,-0x84(%rbp)
jmp    1424 <main+0x2e4>
movl   $0x1,-0x4(%rbp)
jmp    1444 <main+0x304>
movl   $0x1,-0x4(%rbp)
jmp    1444 <main+0x304>
movl   $0x1,-0x4(%rbp)
jmp    1444 <main+0x304>
jmp    1429 <main+0x2e9>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    1227 <main+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0xe(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x2,0x20(%rsp)
lea    0xe8e(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    0x2e67(%rip),%r13
mov    $0x1,%r14d
cmp    0x0(%r13),%rax
je     11fa <main+0xca>
mov    $0x1,%ebp
lea    0xe6a(%rip),%r14
mov    %rsp,%rbx
lea    0xe6f(%rip),%r15
lea    0xe56(%rip),%r12
jmp    11c5 <main+0x95>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbp
cmp    0x0(%r13),%rax
je     11f7 <main+0xc7>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11dd <main+0xad>
movl   $0x0,0x1c(%rsp,%rbp,4)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11b0 <main+0x80>
movl   $0x1,0x1c(%rsp,%rbp,4)
jmp    11b0 <main+0x80>
mov    %ebp,%r14d
xor    %ebx,%ebx
lea    0xe91(%rip),%r15
xor    %r12d,%r12d
mov    $0x1,%ebp
jmp    1220 <main+0xf0>
nopl   (%rax)
lea    (%rax,%r13,4),%rax
mov    (%rax),%r12d
add    $0x1,%rbx
cmp    %rbx,%r14
je     126f <main+0x13f>
cmp    $0x5,%r12d
ja     1271 <main+0x141>
movslq %r12d,%r13
movslq (%r15,%r13,4),%rdi
add    %r15,%rdi
call   1030 <printf@plt>
mov    0x20(%rsp,%rbx,4),%eax
cmp    $0x1,%eax
je     1260 <main+0x130>
test   %eax,%eax
jne    1217 <main+0xe7>
cmp    $0x6,%r12d
jae    1271 <main+0x141>
lea    0xe5d(%rip),%rax
jmp    1210 <main+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x4,%r12d
jae    1271 <main+0x141>
lea    0xe57(%rip),%rax
jmp    1210 <main+0xe0>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x78,%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"
@.str.3 = [14 x i8] c"\0ADoor: CLOSED\00"
@.str.4 = [15 x i8] c"\0ADoor: OPENING\00"
@.str.5 = [12 x i8] c"\0ADoor: OPEN\00"
@.str.6 = [15 x i8] c"\0ADoor: CLOSING\00"
@.str.7 = [29 x i8] c"\0ADoor: STOPPED_WHILE_CLOSING\00"
@.str.8 = [29 x i8] c"\0ADoor: STOPPED_WHILE_OPENING\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca [20 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [30 x i8]* %2 to i8*
%8 = bitcast [20 x i32]* %3 to i8*
%9 = bitcast i8* %8 to <{ i32, [19 x i32] }>*
%10 = getelementptr inbounds <{ i32, [19 x i32] }>, <{ i32, [19 x i32] }>* %9, i32 0, i32 0
store i32 2, i32* %10
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %32, %0
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%13 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i64, i64* @EOF
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %35
16: ; preds = %11
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %22
store i32 0, i32* %23
br label %24
24: ; preds = %20, %16
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %30
store i32 1, i32* %31
br label %32
32: ; preds = %28, %24
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %11
35: ; preds = %11
store i32 0, i32* %6
br label %36
36: ; preds = %87, %35
%37 = load i32, i32* %6
%38 = load i32, i32* %5
%39 = icmp sle i32 %37, %38
br i1 %39, label %40, label %90
40: ; preds = %36
%41 = load i32, i32* %4
switch i32 %41, label %54 [
i32 0, label %42
i32 1, label %44
i32 2, label %46
i32 3, label %48
i32 4, label %50
i32 5, label %52
]
42: ; preds = %40
%43 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %55
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %55
46: ; preds = %40
%47 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %55
48: ; preds = %40
%49 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %55
50: ; preds = %40
%51 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
br label %55
52: ; preds = %40
%53 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
br label %55
54: ; preds = %40
store i32 1, i32* %1
br label %91
55: ; preds = %52, %50, %48, %46, %44, %42
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %71
61: ; preds = %55
%62 = load i32, i32* %4
switch i32 %62, label %69 [
i32 0, label %63
i32 1, label %64
i32 2, label %65
i32 3, label %66
i32 4, label %67
i32 5, label %68
]
63: ; preds = %61
store i32 1, i32* %4
br label %70
64: ; preds = %61
store i32 5, i32* %4
br label %70
65: ; preds = %61
store i32 3, i32* %4
br label %70
66: ; preds = %61
store i32 4, i32* %4
br label %70
67: ; preds = %61
store i32 1, i32* %4
br label %70
68: ; preds = %61
store i32 3, i32* %4
br label %70
69: ; preds = %61
store i32 1, i32* %1
br label %91
70: ; preds = %68, %67, %66, %65, %64, %63
br label %71
71: ; preds = %70, %55
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %73
%75 = load i32, i32* %74
%76 = icmp eq i32 %75, 1
br i1 %76, label %77, label %87
77: ; preds = %71
%78 = load i32, i32* %4
switch i32 %78, label %85 [
i32 0, label %79
i32 1, label %80
i32 2, label %81
i32 3, label %82
i32 4, label %83
i32 5, label %84
]
79: ; preds = %77
store i32 0, i32* %4
br label %86
80: ; preds = %77
store i32 2, i32* %4
br label %86
81: ; preds = %77
store i32 2, i32* %4
br label %86
82: ; preds = %77
store i32 0, i32* %4
br label %86
83: ; preds = %77
store i32 1, i32* %1
br label %91
84: ; preds = %77
store i32 1, i32* %1
br label %91
85: ; preds = %77
store i32 1, i32* %1
br label %91
86: ; preds = %82, %81, %80, %79
br label %87
87: ; preds = %86, %71
%88 = load i32, i32* %6
%89 = add nsw i32 %88, 1
store i32 %89, i32* %6
br label %36
90: ; preds = %36
store i32 0, i32* %1
br label %91
91: ; preds = %90, %85, %84, %83, %69, %54
%92 = load i32, i32* %1
ret i32 %92
}

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"
@.str.3 = [14 x i8] c"\0ADoor: CLOSED\00"
@.str.4 = [15 x i8] c"\0ADoor: OPENING\00"
@.str.5 = [12 x i8] c"\0ADoor: OPEN\00"
@.str.6 = [15 x i8] c"\0ADoor: CLOSING\00"
@.str.7 = [29 x i8] c"\0ADoor: STOPPED_WHILE_CLOSING\00"
@.str.8 = [29 x i8] c"\0ADoor: STOPPED_WHILE_OPENING\00"
@reltable.main = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.6 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str.7 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str.8 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32)]
@switch.table.main.9 = [6 x i32] [i32 1, i32 5, i32 3, i32 4, i32 1, i32 3]
@switch.table.main.10 = [4 x i32] [i32 0, i32 2, i32 2, i32 0]
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [20 x i32]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = bitcast [20 x i32]* %2 to i8*
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
store i32 2, i32* %5
%6 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %12, label %14
9: ; preds = %25
%10 = add i64 %15, 2
%11 = and i64 %10, 4294967295
br label %12
12: ; preds = %9, %0
%13 = phi i64 [ 1, %0 ], [ %11, %9 ]
br label %30
14: ; preds = %0, %25
%15 = phi i64 [ %26, %25 ], [ 0, %0 ]
%16 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %15
store i32 0, i32* %19
br label %20
20: ; preds = %18, %14
%21 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %15
store i32 1, i32* %24
br label %25
25: ; preds = %23, %20
%26 = add nuw i64 %15, 1
%27 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %27, %28
br i1 %29, label %9, label %14
30: ; preds = %12, %54
%31 = phi i64 [ 0, %12 ], [ %56, %54 ]
%32 = phi i32 [ 0, %12 ], [ %55, %54 ]
%33 = icmp ult i32 %32, 6
br i1 %33, label %34, label %58
34: ; preds = %30
%35 = sext i32 %32 to i64
%36 = shl i64 %35, 2
%37 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.main to i8*), i64 %36)
%38 = call i32 @printf(i8* dereferenceable(1) %37)
%39 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %31
%40 = load i32, i32* %39
switch i32 %40, label %54 [
i32 0, label %41
i32 1, label %43
]
41: ; preds = %34
%42 = icmp ult i32 %32, 6
br i1 %42, label %45, label %58
43: ; preds = %34
%44 = icmp ult i32 %32, 4
br i1 %44, label %48, label %58
45: ; preds = %41
%46 = sext i32 %32 to i64
%47 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.main.9, i64 0, i64 %46
br label %51
48: ; preds = %43
%49 = sext i32 %32 to i64
%50 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.main.10, i64 0, i64 %49
br label %51
51: ; preds = %45, %48
%52 = phi i32* [ %50, %48 ], [ %47, %45 ]
%53 = load i32, i32* %52
br label %54
54: ; preds = %51, %34
%55 = phi i32 [ %32, %34 ], [ %53, %51 ]
%56 = add nuw nsw i64 %31, 1
%57 = icmp eq i64 %56, %13
br i1 %57, label %58, label %30
58: ; preds = %43, %41, %30, %54
%59 = phi i32 [ 1, %30 ], [ 1, %41 ], [ 1, %43 ], [ 0, %54 ]
ret i32 %59
}