#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*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main() {
  char command[15];
  char routine[101];
  int position = 1;
  int counter = 1;
  routine[0] = 1;
  while (!feof(stdin)) {
    scanf("%s", command);
    if (strcmp(command, "button_clicked") == 0) {
      switch (position) {
      case 1:
        position = 2;
        break;
      case 2:
        position = 6;
        break;
      case 3:
        position = 4;
        break;
      case 4:
        position = 5;
        break;
      case 5:
        position = 2;
        break;
      case 6:
        position = 4;
        break;
      }
    } else if (strcmp(command, "cycle_complete") == 0) {
      switch (position) {
      case 4:
        position = 1;
        break;
      case 2:
        position = 3;
        break;
      }
    }
    routine[counter] = position;
    counter++;
  }
  counter = 0;
  for (; counter < (strlen(routine) - 1); counter++) {
    switch (routine[counter]) {
    case 1:
      printf("Door: CLOSED\n");
      break;
    case 2:
      printf("Door: OPENING\n");
      break;
    case 3:
      printf("Door: OPEN\n");
      break;
    case 4:
      printf("Door: CLOSING\n");
      break;
    case 5:
      printf("Door: STOPPED_WHILE_CLOSING\n");
      break;
    case 6:
      printf("Door: STOPPED_WHILE_OPENING\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
movl   $0x1,-0x88(%rbp)
movb   $0x1,-0x80(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119d <main+0x4d>
jmp    12e5 <main+0x195>
lea    -0x13(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x13(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1253 <main+0x103>
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x90(%rbp)
sub    $0x5,%eax
ja     124e <main+0xfe>
mov    -0x90(%rbp),%rax
lea    0xe28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x84(%rbp)
jmp    124e <main+0xfe>
movl   $0x6,-0x84(%rbp)
jmp    124e <main+0xfe>
movl   $0x4,-0x84(%rbp)
jmp    124e <main+0xfe>
movl   $0x5,-0x84(%rbp)
jmp    124e <main+0xfe>
movl   $0x2,-0x84(%rbp)
jmp    124e <main+0xfe>
movl   $0x4,-0x84(%rbp)
jmp    12be <main+0x16e>
lea    -0x13(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12b9 <main+0x169>
mov    -0x84(%rbp),%eax
mov    %eax,-0x94(%rbp)
sub    $0x2,%eax
je     12aa <main+0x15a>
jmp    1287 <main+0x137>
mov    -0x94(%rbp),%eax
sub    $0x4,%eax
jne    12b4 <main+0x164>
jmp    129b <main+0x14b>
movl   $0x1,-0x84(%rbp)
jmp    12b4 <main+0x164>
movl   $0x3,-0x84(%rbp)
jmp    12b9 <main+0x169>
jmp    12be <main+0x16e>
mov    -0x84(%rbp),%eax
mov    %al,%cl
movslq -0x88(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    117a <main+0x2a>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0x98(%rbp)
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13c9 <main+0x279>
movslq -0x88(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0xa0(%rbp)
sub    $0x5,%eax
ja     13b0 <main+0x260>
mov    -0xa0(%rbp),%rax
lea    0xcba(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xcfb(%rip),%rdi
call   1040 <printf@plt>
jmp    13b0 <main+0x260>
lea    0xcf8(%rip),%rdi
call   1040 <printf@plt>
jmp    13b0 <main+0x260>
lea    0xcf6(%rip),%rdi
call   1040 <printf@plt>
jmp    13b0 <main+0x260>
lea    0xcf1(%rip),%rdi
call   1040 <printf@plt>
jmp    13b0 <main+0x260>
lea    0xcef(%rip),%rdi
call   1040 <printf@plt>
jmp    13b0 <main+0x260>
lea    0xcfb(%rip),%rdi
call   1040 <printf@plt>
jmp    13b5 <main+0x265>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    12ef <main+0x19f>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movb   $0x1,0x10(%rsp)
mov    0x2e7e(%rip),%r13
mov    0x0(%r13),%edi
call   1060 <feof@plt>
test   %eax,%eax
je     11e4 <main+0x94>
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11d3 <main+0x83>
xor    %ebp,%ebp
lea    0xf19(%rip),%r14
lea    0x10(%rsp),%rbx
jmp    11b6 <main+0x66>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jge    11d3 <main+0x83>
movsbq 0x10(%rsp,%rbp,1),%rax
add    $0xffffffffffffffff,%rax
cmp    $0x5,%eax
ja     11a0 <main+0x50>
movslq (%r14,%rax,4),%rdi
add    %r14,%rdi
call   1030 <puts@plt>
jmp    11a0 <main+0x50>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x11(%rsp),%rbp
mov    $0x1,%r12d
lea    0xe0a(%rip),%r14
lea    0x1(%rsp),%rbx
lea    0xe01(%rip),%r15
jmp    1229 <main+0xd9>
mov    $0x3,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r12b,0x0(%rbp)
mov    0x0(%r13),%edi
call   1060 <feof@plt>
add    $0x1,%rbp
test   %eax,%eax
jne    1177 <main+0x27>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1270 <main+0x120>
mov    %rbx,%rdi
lea    0xdc4(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1210 <main+0xc0>
cmp    $0x2,%r12d
je     1204 <main+0xb4>
cmp    $0x4,%r12d
jne    1210 <main+0xc0>
mov    $0x1,%r12d
jmp    1210 <main+0xc0>
nopl   0x0(%rax)
lea    -0x1(%r12),%eax
cmp    $0x6,%eax
jae    1210 <main+0xc0>
cltq
lea    0xe0d(%rip),%rcx
mov    (%rcx,%rax,4),%r12d
jmp    1210 <main+0xc0>

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

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