#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 flag = 0;
  printf("Door: CLOSED");
  while (scanf("%s", input) != EOF) {
    if (strcmp(input, "button_clicked") == 0) {
      switch (flag) {
      case 0:
        printf("Door: OPENING\n");
        flag = 1;
        break;
      case 1:
        printf("Door: STOPPED_WHILE_OPENING\n");
        flag = 2;
        break;
      case 2:
        printf("Door: CLOSING\n");
        flag = 3;
        break;
      case 3:
        printf("Door: STOPPED_WHILE_CLOSING\n");
        flag = 4;
        break;
      case 4:
        printf("Door: OPENING\n");
        flag = 5;
        break;
      case 5:
        printf("Door: CLOSING\n");
        flag = 6;
        break;
      default:
        break;
      }
    }
    if (strcmp(input, "cycle_complete") == 0) {
      switch (flag) {
      case 0:
        printf("Door: CLOSED\n");
        flag = 0;
        break;
      case 3:
        printf("Door: CLOSED\n");
        flag = 0;
        break;
      case 1:
        printf("Door: OPEN\n");
        flag = 5;
        break;
      case 5:
        printf("Door: OPEN\n");
        flag = 5;
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1040 <memset@plt>
movl   $0x0,-0x34(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xec0(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
je     130f <main+0x1cf>
lea    -0x30(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    126b <main+0x12b>
mov    -0x34(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0x5,%rax
ja     1261 <main+0x121>
mov    -0x40(%rbp),%rax
lea    0xe38(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x34(%rbp)
jmp    1266 <main+0x126>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x34(%rbp)
jmp    1266 <main+0x126>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x34(%rbp)
jmp    1266 <main+0x126>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,-0x34(%rbp)
jmp    1266 <main+0x126>
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x34(%rbp)
jmp    1266 <main+0x126>
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x6,-0x34(%rbp)
jmp    1266 <main+0x126>
jmp    1266 <main+0x126>
jmp    126b <main+0x12b>
lea    -0x30(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    130a <main+0x1ca>
mov    -0x34(%rbp),%eax
mov    %rax,-0x48(%rbp)
sub    $0x5,%rax
ja     1305 <main+0x1c5>
mov    -0x48(%rbp),%rax
lea    0xd77(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe05(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    1305 <main+0x1c5>
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    1305 <main+0x1c5>
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x34(%rbp)
jmp    1305 <main+0x1c5>
lea    0xdcb(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x34(%rbp)
jmp    130a <main+0x1ca>
jmp    1172 <main+0x32>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0xe(%rsp)
movaps %xmm0,(%rsp)
lea    0xecb(%rip),%rdi
call   1040 <printf@plt>
lea    0xe93(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    0x2e6c(%rip),%r13
cmp    0x0(%r13),%rax
jne    1193 <main+0x53>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
mov    %rsp,%rbx
lea    0xef0(%rip),%rbp
lea    0xe6b(%rip),%r15
lea    0xe52(%rip),%r12
jmp    11c1 <main+0x81>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    0x0(%r13),%rax
je     1182 <main+0x42>
mov    %rbx,%rdi
lea    0xe38(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11ef <main+0xaf>
cmp    $0x5,%r14d
ja     11ef <main+0xaf>
movslq %r14d,%rax
movslq 0x0(%rbp,%rax,4),%rdi
add    %rbp,%rdi
add    $0x1,%r14d
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
cmp    $0x5,%r14d
ja     11b0 <main+0x70>
mov    $0x2b,%eax
bt     %r14d,%eax
jae    11b0 <main+0x70>
movslq %r14d,%rax
lea    0xe8e(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
lea    0xe98(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
call   1030 <puts@plt>
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [13 x i8] c"Door: CLOSED\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [15 x i8] c"button_clicked\00"
@.str.3 = [15 x i8] c"Door: OPENING\0A\00"
@.str.4 = [29 x i8] c"Door: STOPPED_WHILE_OPENING\0A\00"
@.str.5 = [15 x i8] c"Door: CLOSING\0A\00"
@.str.6 = [29 x i8] c"Door: STOPPED_WHILE_CLOSING\0A\00"
@.str.7 = [15 x i8] c"cycle_complete\00"
@.str.8 = [14 x i8] c"Door: CLOSED\0A\00"
@.str.9 = [12 x i8] c"Door: OPEN\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [30 x i8]* %2 to i8*
store i32 0, i32* %3
%5 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %46, %0
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %47
11: ; preds = %6
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i32, i32* %3
switch i32 %16, label %29 [
i32 0, label %17
i32 1, label %19
i32 2, label %21
i32 3, label %23
i32 4, label %25
i32 5, label %27
]
17: ; preds = %15
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %30
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %30
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 3, i32* %3
br label %30
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
store i32 4, i32* %3
br label %30
25: ; preds = %15
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 5, i32* %3
br label %30
27: ; preds = %15
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 6, i32* %3
br label %30
29: ; preds = %15
br label %30
30: ; preds = %29, %27, %25, %23, %21, %19, %17
br label %31
31: ; preds = %30, %11
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i32, i32* %3
switch i32 %36, label %45 [
i32 0, label %37
i32 3, label %39
i32 1, label %41
i32 5, label %43
]
37: ; preds = %35
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %45
39: ; preds = %35
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %45
41: ; preds = %35
%42 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
store i32 5, i32* %3
br label %45
43: ; preds = %35
%44 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
store i32 5, i32* %3
br label %45
45: ; preds = %35, %43, %41, %39, %37
br label %46
46: ; preds = %45, %31
br label %6
47: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [15 x i8] c"button_clicked\00"
@.str.7 = [15 x i8] c"cycle_complete\00"
@str.10 = [11 x i8] c"Door: OPEN\00"
@str.12 = [13 x i8] c"Door: CLOSED\00"
@str.15 = [28 x i8] c"Door: STOPPED_WHILE_CLOSING\00"
@str.16 = [14 x i8] c"Door: CLOSING\00"
@str.17 = [28 x i8] c"Door: STOPPED_WHILE_OPENING\00"
@str.18 = [14 x i8] c"Door: OPENING\00"
@reltable.main = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.18 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @str.17 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.16 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @str.15 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.18 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.16 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32)]
@reltable.main.21 = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.21 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.10 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.21 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.21 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.21 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.21 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.10 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.21 to i64)) to i32)]
@switch.table.main.20 = [6 x i32] [i32 0, i32 5, i32 0, i32 0, i32 0, i32 5]
define i32 @main() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%4 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %43, label %7
7: ; preds = %0, %38
%8 = phi i32 [ %39, %38 ], [ 0, %0 ]
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = icmp ult i32 %8, 6
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = sext i32 %8 to i64
%15 = shl i64 %14, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.main to i8*), i64 %15)
%17 = add i32 %8, 1
%18 = call i32 @puts(i8* dereferenceable(1) %16)
br label %19
19: ; preds = %13, %7
%20 = phi i32 [ %8, %7 ], [ %17, %13 ]
%21 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = icmp ult i32 %20, 6
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = trunc i32 %20 to i8
%27 = lshr i8 43, %26
%28 = and i8 %27, 1
%29 = icmp eq i8 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %25
%31 = sext i32 %20 to i64
%32 = shl i64 %31, 2
%33 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.main.21 to i8*), i64 %32)
%34 = sext i32 %20 to i64
%35 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.main.20, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 @puts(i8* dereferenceable(1) %33)
br label %38
38: ; preds = %25, %30, %19
%39 = phi i32 [ %20, %19 ], [ %36, %30 ], [ %20, %25 ]
%40 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%41 = load i64, i64* @EOF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %7
43: ; preds = %38, %0
ret i32 0
}