#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 command[14];
  int door_state = 0;
  int boolean = 0;
  printf("Door: CLOSED\n");
  while (scanf("%s", command) != EOF) {
    if (strcmp(command, "button_clicked") == 0) {
      if (door_state == 0 && boolean == 0) {
        door_state = 1;
        printf("Door: OPENING\n");
        boolean = 1;
      }
      if (door_state == 1 && boolean == 0) {
        door_state = 5;
        printf("Door: STOPPED_WHILE_OPENING\n");
        boolean = 1;
      }
      if (door_state == 2 && boolean == 0) {
        door_state = 3;
        printf("Door: CLOSING\n");
        boolean = 1;
      }
      if (door_state == 3 && boolean == 0) {
        door_state = 4;
        printf("Door: STOPPED_WHILE_CLOSING\n");
        boolean = 1;
      }
      if (door_state == 4 && boolean == 0) {
        door_state = 1;
        printf("Door: OPENING\n");
        boolean = 1;
      }
      if (door_state == 5 && boolean == 0) {
        door_state = 3;
        printf("Door: CLOSING\n");
        boolean = 1;
      }
      boolean = 0;
    }
    if (strcmp(command, "cycle_complete") == 0) {
      if (door_state == 1 && boolean == 0) {
        door_state = 2;
        printf("Door: OPEN\n");
        boolean = 1;
      }
      if (door_state == 3 && boolean == 0) {
        door_state = 0;
        printf("Door: CLOSED\n");
        boolean = 1;
      }
      boolean = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
lea    -0x12(%rbp),%rsi
lea    0xeaa(%rip),%rdi
call   1050 <scanf@plt>
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%rax
je     1330 <main+0x200>
lea    -0x12(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12ae <main+0x17e>
cmpl   $0x0,-0x18(%rbp)
jne    11c1 <main+0x91>
cmpl   $0x0,-0x1c(%rbp)
jne    11c1 <main+0x91>
movl   $0x1,-0x18(%rbp)
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    11ef <main+0xbf>
cmpl   $0x0,-0x1c(%rbp)
jne    11ef <main+0xbf>
movl   $0x5,-0x18(%rbp)
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x18(%rbp)
jne    121d <main+0xed>
cmpl   $0x0,-0x1c(%rbp)
jne    121d <main+0xed>
movl   $0x3,-0x18(%rbp)
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3,-0x18(%rbp)
jne    124b <main+0x11b>
cmpl   $0x0,-0x1c(%rbp)
jne    124b <main+0x11b>
movl   $0x4,-0x18(%rbp)
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x4,-0x18(%rbp)
jne    1279 <main+0x149>
cmpl   $0x0,-0x1c(%rbp)
jne    1279 <main+0x149>
movl   $0x1,-0x18(%rbp)
lea    0xdb3(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x5,-0x18(%rbp)
jne    12a7 <main+0x177>
cmpl   $0x0,-0x1c(%rbp)
jne    12a7 <main+0x177>
movl   $0x3,-0x18(%rbp)
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x12(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    132b <main+0x1fb>
cmpl   $0x1,-0x18(%rbp)
jne    12f6 <main+0x1c6>
cmpl   $0x0,-0x1c(%rbp)
jne    12f6 <main+0x1c6>
movl   $0x2,-0x18(%rbp)
lea    0xd9d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3,-0x18(%rbp)
jne    1324 <main+0x1f4>
cmpl   $0x0,-0x1c(%rbp)
jne    1324 <main+0x1f4>
movl   $0x0,-0x18(%rbp)
lea    0xce8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    1159 <main+0x29>
xor    %eax,%eax
add    $0x20,%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    0xef4(%rip),%rdi
call   1030 <puts@plt>
lea    0xec7(%rip),%rdi
lea    0xa(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x2e86(%rip),%rbx
cmp    (%rbx),%rax
jne    1178 <main+0x48>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
lea    0xe99(%rip),%r13
lea    0xa(%rsp),%r12
lea    0xe9c(%rip),%r15
lea    0xe83(%rip),%rbp
jmp    11b9 <main+0x89>
mov    $0x2,%r14d
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
cmp    (%rbx),%rax
je     1167 <main+0x37>
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1237 <main+0x107>
cmp    $0x5,%r14d
ja     1237 <main+0x107>
mov    %r15,%r12
mov    $0x1,%r15d
mov    %r14d,%eax
lea    0xe1e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
lea    0xea7(%rip),%rdi
jmp    *%rax
mov    $0x5,%r15d
lea    0xe7c(%rip),%rdi
jmp    1220 <main+0xf0>
mov    $0x3,%r15d
lea    0xe5f(%rip),%rdi
jmp    1220 <main+0xf0>
mov    $0x4,%r15d
lea    0xe34(%rip),%rdi
nopl   (%rax)
call   1030 <puts@plt>
mov    %r15d,%r14d
mov    %r12,%r15
lea    0xde6(%rip),%rbp
lea    0xa(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11a9 <main+0x79>
cmp    $0x1,%r14d
je     1197 <main+0x67>
cmp    $0x3,%r14d
jne    11a9 <main+0x79>
xor    %r14d,%r14d
lea    0xdd0(%rip),%rdi
jmp    11a4 <main+0x74>
lea    0xdf8(%rip),%rdi
call   1030 <puts@plt>
lea    0xa(%rsp),%rdi
mov    %r12,%r15
mov    %rdi,%r12
mov    %r15,%rsi
call   1040 <strcmp@plt>
mov    $0x3,%r14d
test   %rax,%rax
lea    0xd7b(%rip),%rbp
jne    11a9 <main+0x79>
jmp    125f <main+0x12f>

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