#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() {
  int door_state = 1, counter = 1;
  char cmd[15], door_states[100];
  door_states[0] = door_state;
  while (!feof(stdin)) {
    scanf("%s", cmd);
    if (strcmp(cmd, "button_clicked") == 0) {
      switch (door_state) {
      case 1:
        door_state = 4;
        break;
      case 2:
        door_state = 3;
        break;
      case 3:
        door_state = 5;
        break;
      case 4:
        door_state = 6;
        break;
      case 5:
        door_state = 4;
        break;
      case 6:
        door_state = 3;
        break;
      }
    } else if (strcmp(cmd, "cycle_complete") == 0) {
      switch (door_state) {
      case 3:
        door_state = 1;
        break;
      case 4:
        door_state = 2;
        break;
      }
    }
    door_states[counter] = door_state;
    counter++;
  }
  for (counter = 0; counter < strlen(door_states) - 1; counter++) {
    switch (door_states[counter]) {
    case 1:
      printf("Door: CLOSED\n");
      break;
    case 2:
      printf("Door: OPEN\n");
      break;
    case 3:
      printf("Door: CLOSING\n");
      break;
    case 4:
      printf("Door: OPENING\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,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x80(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1199 <main+0x49>
jmp    12b7 <main+0x167>
lea    -0x1b(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x1b(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    123a <main+0xea>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x88(%rbp)
sub    $0x5,%eax
ja     1235 <main+0xe5>
mov    -0x88(%rbp),%rax
lea    0xe2f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x4,-0x8(%rbp)
jmp    1235 <main+0xe5>
movl   $0x3,-0x8(%rbp)
jmp    1235 <main+0xe5>
movl   $0x5,-0x8(%rbp)
jmp    1235 <main+0xe5>
movl   $0x6,-0x8(%rbp)
jmp    1235 <main+0xe5>
movl   $0x4,-0x8(%rbp)
jmp    1235 <main+0xe5>
movl   $0x3,-0x8(%rbp)
jmp    129c <main+0x14c>
lea    -0x1b(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1297 <main+0x147>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
sub    $0x3,%eax
je     127f <main+0x12f>
jmp    126b <main+0x11b>
mov    -0x8c(%rbp),%eax
sub    $0x4,%eax
je     128b <main+0x13b>
jmp    1292 <main+0x142>
movl   $0x1,-0x8(%rbp)
jmp    1292 <main+0x142>
movl   $0x2,-0x8(%rbp)
jmp    1297 <main+0x147>
jmp    129c <main+0x14c>
mov    -0x8(%rbp),%eax
mov    %al,%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <main+0x26>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    138c <main+0x23c>
movslq -0xc(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x98(%rbp)
sub    $0x5,%eax
ja     1379 <main+0x229>
mov    -0x98(%rbp),%rax
lea    0xcf1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd32(%rip),%rdi
call   1040 <printf@plt>
jmp    1379 <main+0x229>
lea    0xd2f(%rip),%rdi
call   1040 <printf@plt>
jmp    1379 <main+0x229>
lea    0xd2a(%rip),%rdi
call   1040 <printf@plt>
jmp    1379 <main+0x229>
lea    0xd28(%rip),%rdi
call   1040 <printf@plt>
jmp    1379 <main+0x229>
lea    0xd26(%rip),%rdi
call   1040 <printf@plt>
jmp    1379 <main+0x229>
lea    0xd32(%rip),%rdi
call   1040 <printf@plt>
jmp    137e <main+0x22e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12be <main+0x16e>
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    $0x2,%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    $0x4,%r12d
je     1204 <main+0xb4>
cmp    $0x3,%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 = [12 x i8] c"Door: OPEN\0A\00"
@.str.5 = [15 x i8] c"Door: CLOSING\0A\00"
@.str.6 = [15 x i8] c"Door: OPENING\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 i32
%3 = alloca i32
%4 = alloca [15 x i8]
%5 = alloca [100 x i8]
store i32 0, i32* %1
store i32 1, i32* %2
store i32 1, i32* %3
%6 = load i32, i32* %2
%7 = trunc i32 %6 to i8
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
store i8 %7, i8* %8
br label %9
9: ; preds = %39, %0
%10 = load i32, i32* @stdin
%11 = call i32 @feof(i32 %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %47
14: ; preds = %9
%15 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %4, 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 %29
20: ; preds = %14
%21 = load i32, i32* %2
switch i32 %21, label %28 [
i32 1, label %22
i32 2, label %23
i32 3, label %24
i32 4, label %25
i32 5, label %26
i32 6, label %27
]
22: ; preds = %20
store i32 4, i32* %2
br label %28
23: ; preds = %20
store i32 3, i32* %2
br label %28
24: ; preds = %20
store i32 5, i32* %2
br label %28
25: ; preds = %20
store i32 6, i32* %2
br label %28
26: ; preds = %20
store i32 4, i32* %2
br label %28
27: ; preds = %20
store i32 3, i32* %2
br label %28
28: ; preds = %20, %27, %26, %25, %24, %23, %22
br label %39
29: ; preds = %14
%30 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i32, i32* %2
switch i32 %34, label %37 [
i32 3, label %35
i32 4, label %36
]
35: ; preds = %33
store i32 1, i32* %2
br label %37
36: ; preds = %33
store i32 2, i32* %2
br label %37
37: ; preds = %33, %36, %35
br label %38
38: ; preds = %37, %29
br label %39
39: ; preds = %38, %28
%40 = load i32, i32* %2
%41 = trunc i32 %40 to i8
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %43
store i8 %41, i8* %44
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %9
47: ; preds = %9
store i32 0, i32* %3
br label %48
48: ; preds = %73, %47
%49 = load i32, i32* %3
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
%52 = sub nsw i32 %51, 1
%53 = icmp slt i32 %49, %52
br i1 %53, label %54, label %76
54: ; preds = %48
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
switch i32 %59, label %72 [
i32 1, label %60
i32 2, label %62
i32 3, label %64
i32 4, label %66
i32 5, label %68
i32 6, label %70
]
60: ; preds = %54
%61 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %72
62: ; preds = %54
%63 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %72
64: ; preds = %54
%65 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %72
66: ; preds = %54
%67 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %72
68: ; preds = %54
%69 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
br label %72
70: ; preds = %54
%71 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
br label %72
72: ; preds = %54, %70, %68, %66, %64, %62, %60
br label %73
73: ; preds = %72
%74 = load i32, i32* %3
%75 = add nsw i32 %74, 1
store i32 %75, i32* %3
br label %48
76: ; preds = %48
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: OPENING\00"
@str.11 = [14 x i8] c"Door: CLOSING\00"
@str.12 = [11 x i8] c"Door: OPEN\00"
@str.13 = [13 x i8] c"Door: CLOSED\00"
@switch.table.main = [6 x i32] [i32 4, i32 3, i32 5, i32 6, i32 4, i32 3]
@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 ([11 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 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 [100 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 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 3, label %24
i32 4, 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 ], [ 2, %25 ], [ 1, %24 ], [ %13, %20 ], [ %29, %26 ]
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds [100 x i8], [100 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 [100 x i8], [100 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
}