#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 *);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  char command[17];
  int condition = 0;
  int is_valid = 1;
  printf("Door: CLOSED\n");
  while (scanf("%s", command) != EOF) {
    if (!strcmp(command, "button_clicked")) {
      if (condition == 0) {
        condition = 1;
      } else if (condition == 1) {
        condition = 2;
      } else if (condition == 2) {
        condition = 3;
      } else if (condition == 3) {
        condition = 4;
      } else if (condition == 4) {
        condition = 1;
      } else if (condition == 5) {
        condition = 3;
      }
      is_valid = 1;
    } else if (!strcmp(command, "cycle_complete")) {
      if (condition == 1) {
        condition = 5;
        is_valid = 1;
      } else if (condition == 3) {
        condition = 0;
        is_valid = 1;
      } else {
        is_valid = 0;
      }
    } else {
      is_valid = 0;
    }
    if (is_valid) {
      if (condition == 0) {
        printf("Door: CLOSED\n");
      }
      if (condition == 1) {
        printf("Door: OPENING\n");
      }
      if (condition == 2) {
        printf("Door: STOPED_WHILE_OPENING\n");
      }
      if (condition == 3) {
        printf("Door: CLOSING\n");
      }
      if (condition == 4) {
        printf("Door: STOPED_WHILE_CLOSING\n");
      }
      if (condition == 5) {
        printf("Door: OPEN\n");
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xeaa(%rip),%rdi
call   1050 <scanf@plt>
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%rax
je     133e <main+0x20e>
lea    -0x20(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1236 <main+0x106>
cmpl   $0x0,-0x24(%rbp)
jne    11a8 <main+0x78>
movl   $0x1,-0x24(%rbp)
jmp    122a <main+0xfa>
cmpl   $0x1,-0x24(%rbp)
jne    11be <main+0x8e>
movl   $0x2,-0x24(%rbp)
jmp    1225 <main+0xf5>
cmpl   $0x2,-0x24(%rbp)
jne    11d4 <main+0xa4>
movl   $0x3,-0x24(%rbp)
jmp    1220 <main+0xf0>
cmpl   $0x3,-0x24(%rbp)
jne    11ea <main+0xba>
movl   $0x4,-0x24(%rbp)
jmp    121b <main+0xeb>
cmpl   $0x4,-0x24(%rbp)
jne    1200 <main+0xd0>
movl   $0x1,-0x24(%rbp)
jmp    1216 <main+0xe6>
cmpl   $0x5,-0x24(%rbp)
jne    1211 <main+0xe1>
movl   $0x3,-0x24(%rbp)
jmp    1216 <main+0xe6>
jmp    121b <main+0xeb>
jmp    1220 <main+0xf0>
jmp    1225 <main+0xf5>
jmp    122a <main+0xfa>
movl   $0x1,-0x28(%rbp)
jmp    12a6 <main+0x176>
lea    -0x20(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    129a <main+0x16a>
cmpl   $0x1,-0x24(%rbp)
jne    126c <main+0x13c>
movl   $0x5,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1295 <main+0x165>
cmpl   $0x3,-0x24(%rbp)
jne    1289 <main+0x159>
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1290 <main+0x160>
movl   $0x0,-0x28(%rbp)
jmp    1295 <main+0x165>
jmp    12a1 <main+0x171>
movl   $0x0,-0x28(%rbp)
jmp    12a6 <main+0x176>
cmpl   $0x0,-0x28(%rbp)
je     1339 <main+0x209>
cmpl   $0x0,-0x24(%rbp)
jne    12c6 <main+0x196>
lea    0xd3f(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x24(%rbp)
jne    12dc <main+0x1ac>
lea    0xd58(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x24(%rbp)
jne    12f2 <main+0x1c2>
lea    0xd51(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x3,-0x24(%rbp)
jne    1308 <main+0x1d8>
lea    0xd57(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x4,-0x24(%rbp)
jne    131e <main+0x1ee>
lea    0xd50(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x5,-0x24(%rbp)
jne    1334 <main+0x204>
lea    0xd56(%rip),%rdi
call   1030 <printf@plt>
jmp    1339 <main+0x209>
jmp    1159 <main+0x29>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf49(%rip),%rdi
call   1030 <puts@plt>
lea    0xebf(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    0x2e98(%rip),%r12
cmp    (%r12),%rax
jne    1167 <main+0x47>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
movabs $0x64656b63696c63,%rbp
lea    0xe85(%rip),%r15
mov    %rsp,%rbx
jmp    11a9 <main+0x89>
xor    %r14d,%r14d
lea    0xef4(%rip),%rdi
nopw   0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    %r14d,%r13d
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
cmp    (%r12),%rax
je     1156 <main+0x36>
mov    (%rsp),%rax
movabs $0x635f6e6f74747562,%rcx
6e 5f 63
xor    %rcx,%rax
mov    0x7(%rsp),%rcx
xor    %rbp,%rcx
or     %rax,%rcx
je     1210 <main+0xf0>
mov    (%rsp),%rax
movabs $0x6f635f656c637963,%rcx
5f 63 6f
xor    %rcx,%rax
mov    0x7(%rsp),%rcx
movabs $0x6574656c706d6f,%rdx
xor    %rdx,%rcx
or     %rax,%rcx
jne    1198 <main+0x78>
cmp    $0x3,%r13d
je     1180 <main+0x60>
cmp    $0x1,%r13d
jne    1198 <main+0x78>
mov    $0x5,%r14d
lea    0xe19(%rip),%rdi
jmp    1190 <main+0x70>
nopw   0x0(%rax,%rax,1)
mov    $0x3,%r14d
lea    0xe2a(%rip),%rdi
cmp    $0x5,%r13d
jae    1190 <main+0x70>
movslq %r13d,%rax
lea    0xe5b(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
lea    0xe61(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
jmp    1190 <main+0x70>

LLVM IR (-O0):
@.str = [14 x i8] c"Door: CLOSED\0A\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"cycle_complete\00"
@.str.4 = [15 x i8] c"Door: OPENING\0A\00"
@.str.5 = [28 x i8] c"Door: STOPED_WHILE_OPENING\0A\00"
@.str.6 = [15 x i8] c"Door: CLOSING\0A\00"
@.str.7 = [28 x i8] c"Door: STOPED_WHILE_CLOSING\0A\00"
@.str.8 = [12 x i8] c"Door: OPEN\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 1, i32* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %96, %0
%7 = getelementptr inbounds [17 x i8], [17 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 %97
11: ; preds = %6
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %45, label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 1, i32* %3
br label %44
19: ; preds = %15
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 2, i32* %3
br label %43
23: ; preds = %19
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 3, i32* %3
br label %42
27: ; preds = %23
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 4, i32* %3
br label %41
31: ; preds = %27
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 1, i32* %3
br label %40
35: ; preds = %31
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 5
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 3, i32* %3
br label %39
39: ; preds = %38, %35
br label %40
40: ; preds = %39, %34
br label %41
41: ; preds = %40, %30
br label %42
42: ; preds = %41, %26
br label %43
43: ; preds = %42, %22
br label %44
44: ; preds = %43, %18
store i32 1, i32* %4
br label %62
45: ; preds = %11
%46 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %60, label %49
49: ; preds = %45
%50 = load i32, i32* %3
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %53
52: ; preds = %49
store i32 5, i32* %3
store i32 1, i32* %4
br label %59
53: ; preds = %49
%54 = load i32, i32* %3
%55 = icmp eq i32 %54, 3
br i1 %55, label %56, label %57
56: ; preds = %53
store i32 0, i32* %3
store i32 1, i32* %4
br label %58
57: ; preds = %53
store i32 0, i32* %4
br label %58
58: ; preds = %57, %56
br label %59
59: ; preds = %58, %52
br label %61
60: ; preds = %45
store i32 0, i32* %4
br label %61
61: ; preds = %60, %59
br label %62
62: ; preds = %61, %44
%63 = load i32, i32* %4
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %96
65: ; preds = %62
%66 = load i32, i32* %3
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %70
70: ; preds = %68, %65
%71 = load i32, i32* %3
%72 = icmp eq i32 %71, 1
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %75
75: ; preds = %73, %70
%76 = load i32, i32* %3
%77 = icmp eq i32 %76, 2
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %80
80: ; preds = %78, %75
%81 = load i32, i32* %3
%82 = icmp eq i32 %81, 3
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %85
85: ; preds = %83, %80
%86 = load i32, i32* %3
%87 = icmp eq i32 %86, 4
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %90
90: ; preds = %88, %85
%91 = load i32, i32* %3
%92 = icmp eq i32 %91, 5
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %95
95: ; preds = %93, %90
br label %96
96: ; preds = %95, %62
br label %6
97: ; 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.3 = [15 x i8] c"cycle_complete\00"
@str.9 = [11 x i8] c"Door: OPEN\00"
@str.10 = [27 x i8] c"Door: STOPED_WHILE_CLOSING\00"
@str.11 = [14 x i8] c"Door: CLOSING\00"
@str.12 = [27 x i8] c"Door: STOPED_WHILE_OPENING\00"
@str.13 = [14 x i8] c"Door: OPENING\00"
@str.14 = [13 x i8] c"Door: CLOSED\00"
@reltable.main = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.13 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @str.12 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.11 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @str.10 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.13 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32)]
@switch.table.main.15 = [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 1]
define i32 @main() {
%1 = alloca [17 x i8]
%2 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.14, 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 %34, label %7
7: ; preds = %0, %29
%8 = phi i32 [ %30, %29 ], [ 0, %0 ]
%9 = call i32 @bcmp(i8* dereferenceable(15) %2, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 15)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = icmp ult i32 %8, 5
br i1 %12, label %18, label %25
13: ; preds = %7
%14 = call i32 @bcmp(i8* dereferenceable(15) %2, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 15)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
switch i32 %8, label %29 [
i32 1, label %17
i32 3, label %25
]
17: ; preds = %16
br label %25
18: ; preds = %11
%19 = sext i32 %8 to i64
%20 = shl i64 %19, 2
%21 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.main to i8*), i64 %20)
%22 = sext i32 %8 to i64
%23 = getelementptr inbounds [5 x i32], [5 x i32]* @switch.table.main.15, i64 0, i64 %22
%24 = load i32, i32* %23
br label %25
25: ; preds = %11, %18, %16, %17
%26 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0), %17 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.14, i64 0, i64 0), %16 ], [ %21, %18 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0), %11 ]
%27 = phi i32 [ 5, %17 ], [ 0, %16 ], [ %24, %18 ], [ 3, %11 ]
%28 = call i32 @puts(i8* dereferenceable(1) %26)
br label %29
29: ; preds = %25, %16, %13
%30 = phi i32 [ %8, %13 ], [ %8, %16 ], [ %27, %25 ]
%31 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%32 = load i64, i64* @EOF
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %7
34: ; preds = %29, %0
ret i32 0
}