#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 *);
unsigned char strlen(char *);
int main() {
  unsigned char door_state = 1, i = 1, l;
  char input[15], output[100];
  output[0] = 1;
  while (!feof(stdin)) {
    scanf("%s", input);
    if (strcmp(input, "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(input, "cycle_complete") == 0)
      switch (door_state) {
      case 3:
        door_state = 1;
        break;
      case 4:
        door_state = 2;
        break;
      default:
        continue;
      }
    else
      continue;
    output[i] = door_state;
    i++;
  }
  l = strlen(output);
  for (i = 0; i < l - 1; i++) {
    printf("Door: ");
    switch (output[i]) {
    case 1:
      printf("CLOSED\n");
      break;
    case 2:
      printf("OPEN\n");
      break;
    case 3:
      printf("CLOSING\n");
      break;
    case 4:
      printf("OPENING\n");
      break;
    case 5:
      printf("STOPPED_WHILE_CLOSING\n");
      break;
    case 6:
      printf("STOPPED_WHILE_OPENING\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x1,-0x5(%rbp)
movb   $0x1,-0x6(%rbp)
movb   $0x1,-0x80(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1191 <main+0x41>
jmp    12a5 <main+0x155>
lea    -0x16(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x16(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1221 <main+0xd1>
movzbl -0x5(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x88(%rbp)
sub    $0x5,%eax
ja     121c <main+0xcc>
mov    -0x88(%rbp),%rax
lea    0xe36(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x4,-0x5(%rbp)
jmp    121c <main+0xcc>
movb   $0x3,-0x5(%rbp)
jmp    121c <main+0xcc>
movb   $0x5,-0x5(%rbp)
jmp    121c <main+0xcc>
movb   $0x6,-0x5(%rbp)
jmp    121c <main+0xcc>
movb   $0x4,-0x5(%rbp)
jmp    121c <main+0xcc>
movb   $0x3,-0x5(%rbp)
jmp    128d <main+0x13d>
lea    -0x16(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1283 <main+0x133>
movzbl -0x5(%rbp),%eax
mov    %eax,-0x8c(%rbp)
sub    $0x3,%eax
je     1267 <main+0x117>
jmp    1253 <main+0x103>
mov    -0x8c(%rbp),%eax
sub    $0x4,%eax
je     1270 <main+0x120>
jmp    1279 <main+0x129>
movb   $0x1,-0x5(%rbp)
jmp    127e <main+0x12e>
movb   $0x2,-0x5(%rbp)
jmp    127e <main+0x12e>
jmp    116e <main+0x1e>
jmp    1288 <main+0x138>
jmp    116e <main+0x1e>
jmp    128d <main+0x13d>
mov    -0x5(%rbp),%cl
movzbl -0x6(%rbp),%eax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x6(%rbp),%al
add    $0x1,%al
mov    %al,-0x6(%rbp)
jmp    116e <main+0x1e>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    %al,-0x7(%rbp)
movb   $0x0,-0x6(%rbp)
movzbl -0x6(%rbp),%eax
movzbl -0x7(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    137c <main+0x22c>
lea    0xd82(%rip),%rdi
call   1040 <printf@plt>
movzbl -0x6(%rbp),%eax
movsbl -0x80(%rbp,%rax,1),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x98(%rbp)
sub    $0x5,%eax
ja     136a <main+0x21a>
mov    -0x98(%rbp),%rax
lea    0xd00(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xd48(%rip),%rdi
call   1040 <printf@plt>
jmp    136a <main+0x21a>
lea    0xd3f(%rip),%rdi
call   1040 <printf@plt>
jmp    136a <main+0x21a>
lea    0xd42(%rip),%rdi
call   1040 <printf@plt>
jmp    136a <main+0x21a>
lea    0xd48(%rip),%rdi
call   1040 <printf@plt>
jmp    136a <main+0x21a>
lea    0xd12(%rip),%rdi
call   1040 <printf@plt>
jmp    136a <main+0x21a>
lea    0xd18(%rip),%rdi
call   1040 <printf@plt>
jmp    136f <main+0x21f>
mov    -0x6(%rbp),%al
add    $0x1,%al
mov    %al,-0x6(%rbp)
jmp    12b5 <main+0x165>
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    0x2e6e(%rip),%r13
mov    0x0(%r13),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     11ef <main+0x8f>
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%al
jb     11de <main+0x7e>
movzbl %al,%ebp
add    $0xffffffff,%ebp
xor    %ebx,%ebx
lea    0xe7d(%rip),%r14
lea    0xeb5(%rip),%r15
jmp    11b9 <main+0x59>
nopl   (%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11de <main+0x7e>
mov    %r14,%rdi
call   1050 <printf@plt>
movsbq 0x10(%rsp,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
cmp    $0x5,%eax
ja     11b0 <main+0x50>
movslq (%r15,%rax,4),%rdi
add    %r15,%rdi
call   1030 <puts@plt>
jmp    11b0 <main+0x50>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%bpl
lea    0x1(%rsp),%rbx
lea    0xe05(%rip),%r15
lea    0xe0d(%rip),%r12
mov    $0x1,%r14b
jmp    1231 <main+0xd1>
mov    $0x1,%r14b
movzbl %bpl,%ebp
mov    %r14b,0x10(%rsp,%rbp,1)
add    $0x1,%bpl
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    1187 <main+0x27>
lea    0xdc8(%rip),%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1271 <main+0x111>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1220 <main+0xc0>
cmp    $0x3,%r14b
je     120a <main+0xaa>
cmp    $0x4,%r14b
jne    1220 <main+0xc0>
mov    $0x2,%r14b
jmp    120d <main+0xad>
lea    -0x1(%r14),%eax
cmp    $0x6,%al
jae    120d <main+0xad>
movzbl %al,%ecx
shl    $0x3,%ecx
movabs $0x30406050304,%r14
shr    %cl,%r14
jmp    120d <main+0xad>

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 = [7 x i8] c"Door: \00"
@.str.4 = [8 x i8] c"CLOSED\0A\00"
@.str.5 = [6 x i8] c"OPEN\0A\00"
@.str.6 = [9 x i8] c"CLOSING\0A\00"
@.str.7 = [9 x i8] c"OPENING\0A\00"
@.str.8 = [23 x i8] c"STOPPED_WHILE_CLOSING\0A\00"
@.str.9 = [23 x i8] c"STOPPED_WHILE_OPENING\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
%5 = alloca [15 x i8]
%6 = alloca [100 x i8]
store i32 0, i32* %1
store i8 1, i8* %2
store i8 1, i8* %3
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
store i8 1, i8* %7
br label %8
8: ; preds = %42, %40, %38, %0
%9 = load i32, i32* @stdin
%10 = call i32 @feof(i32 %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %49
13: ; preds = %8
%14 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %13
%20 = load i8, i8* %2
%21 = zext i8 %20 to i32
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 = %19
store i8 4, i8* %2
br label %28
23: ; preds = %19
store i8 3, i8* %2
br label %28
24: ; preds = %19
store i8 5, i8* %2
br label %28
25: ; preds = %19
store i8 6, i8* %2
br label %28
26: ; preds = %19
store i8 4, i8* %2
br label %28
27: ; preds = %19
store i8 3, i8* %2
br label %28
28: ; preds = %19, %27, %26, %25, %24, %23, %22
br label %42
29: ; preds = %13
%30 = getelementptr inbounds [15 x i8], [15 x i8]* %5, 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 %40
33: ; preds = %29
%34 = load i8, i8* %2
%35 = zext i8 %34 to i32
switch i32 %35, label %38 [
i32 3, label %36
i32 4, label %37
]
36: ; preds = %33
store i8 1, i8* %2
br label %39
37: ; preds = %33
store i8 2, i8* %2
br label %39
38: ; preds = %33
br label %8
39: ; preds = %37, %36
br label %41
40: ; preds = %29
br label %8
41: ; preds = %39
br label %42
42: ; preds = %41, %28
%43 = load i8, i8* %2
%44 = load i8, i8* %3
%45 = zext i8 %44 to i64
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %45
store i8 %43, i8* %46
%47 = load i8, i8* %3
%48 = add i8 %47, 1
store i8 %48, i8* %3
br label %8
49: ; preds = %8
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%51 = call zeroext i8 @strlen(i8* %50)
store i8 %51, i8* %4
store i8 0, i8* %3
br label %52
52: ; preds = %79, %49
%53 = load i8, i8* %3
%54 = zext i8 %53 to i32
%55 = load i8, i8* %4
%56 = zext i8 %55 to i32
%57 = sub nsw i32 %56, 1
%58 = icmp slt i32 %54, %57
br i1 %58, label %59, label %82
59: ; preds = %52
%60 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%61 = load i8, i8* %3
%62 = zext i8 %61 to i64
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
switch i32 %65, label %78 [
i32 1, label %66
i32 2, label %68
i32 3, label %70
i32 4, label %72
i32 5, label %74
i32 6, label %76
]
66: ; preds = %59
%67 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %78
68: ; preds = %59
%69 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %78
70: ; preds = %59
%71 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %78
72: ; preds = %59
%73 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %78
74: ; preds = %59
%75 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %78
76: ; preds = %59
%77 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
br label %78
78: ; preds = %59, %76, %74, %72, %70, %68, %66
br label %79
79: ; preds = %78
%80 = load i8, i8* %3
%81 = add i8 %80, 1
store i8 %81, i8* %3
br label %52
82: ; preds = %52
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.3 = [7 x i8] c"Door: \00"
@str = [22 x i8] c"STOPPED_WHILE_OPENING\00"
@str.10 = [22 x i8] c"STOPPED_WHILE_CLOSING\00"
@str.11 = [8 x i8] c"OPENING\00"
@str.12 = [8 x i8] c"CLOSING\00"
@str.13 = [5 x i8] c"OPEN\00"
@str.14 = [7 x i8] c"CLOSED\00"
@reltable.main = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @str.14 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @str.13 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @str.11 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @str.10 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 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 %8, label %40
8: ; preds = %0, %32
%9 = phi i8 [ %36, %32 ], [ 1, %0 ]
%10 = phi i8 [ %33, %32 ], [ 1, %0 ]
br label %11
11: ; preds = %8, %22
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%13 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = add i8 %10, -1
%17 = icmp ult i8 %16, 6
br i1 %17, label %26, label %32
18: ; preds = %11
%19 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
switch i8 %10, label %22 [
i8 3, label %31
i8 4, label %32
]
22: ; preds = %21, %18
%23 = load i32, i32* @stdin
%24 = call i32 @feof(i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %11, label %40
26: ; preds = %15
%27 = zext i8 %16 to i48
%28 = shl nuw nsw i48 %27, 3
%29 = lshr i48 3315815744260, %28
%30 = trunc i48 %29 to i8
br label %32
31: ; preds = %21
br label %32
32: ; preds = %21, %31, %26, %15
%33 = phi i8 [ %10, %15 ], [ %30, %26 ], [ 1, %31 ], [ 2, %21 ]
%34 = zext i8 %9 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %34
store i8 %33, i8* %35
%36 = add i8 %9, 1
%37 = load i32, i32* @stdin
%38 = call i32 @feof(i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %8, label %40
40: ; preds = %32, %22, %0
%41 = call zeroext i8 @strlen(i8* %4)
%42 = icmp ugt i8 %41, 1
br i1 %42, label %43, label %63
43: ; preds = %40
%44 = zext i8 %41 to i64
%45 = add nuw nsw i64 %44, 4294967295
%46 = and i64 %45, 4294967295
br label %47
47: ; preds = %43, %60
%48 = phi i64 [ 0, %43 ], [ %61, %60 ]
%49 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %48
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = add nsw i32 %52, -1
%54 = icmp ult i32 %53, 6
br i1 %54, label %55, label %60
55: ; preds = %47
%56 = sext i32 %53 to i64
%57 = shl i64 %56, 2
%58 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.main to i8*), i64 %57)
%59 = call i32 @puts(i8* dereferenceable(1) %58)
br label %60
60: ; preds = %47, %55
%61 = add nuw nsw i64 %48, 1
%62 = icmp eq i64 %61, %46
br i1 %62, label %63, label %47
63: ; preds = %60, %40
ret i32 0
}