#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_line[100];
  int door_state = 0, closeoropen = 0;
  printf("Door: CLOSED\n");
  while (scanf("%s", command_line) != EOF) {
    if (!strcmp(command_line, "button_clicked") && door_state == 1 &&
        closeoropen == 0) {
      door_state = 0;
      closeoropen = 1;
      printf("Door: STOPPED_WHILE_OPENING\n");
      continue;
    }
    if (!strcmp(command_line, "button_clicked") && door_state == 1 &&
        closeoropen == 1) {
      door_state = 0;
      closeoropen = 0;
      printf("Door: STOPPED_WHILE_CLOSING\n");
      continue;
    }
    if (!strcmp(command_line, "button_clicked") && door_state == 0 &&
        closeoropen == 0) {
      door_state = 1;
      printf("Door: OPENING");
    }
    if (!strcmp(command_line, "cycle_complete") && door_state == 1 &&
        closeoropen == 0) {
      door_state = 0;
      closeoropen = 1;
      printf("Door: OPEN");
    }
    if (!strcmp(command_line, "button_clicked") && door_state == 0 &&
        closeoropen == 1) {
      door_state = 1;
      printf("Door: CLOSING");
    }
    if (!strcmp(command_line, "cycle_complete") && door_state == 1 &&
        closeoropen == 1) {
      door_state = 0;
      closeoropen = 0;
      printf("Door: CLOSED");
    }
    printf("\n");
  };
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1050 <scanf@plt>
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
je     1333 <main+0x203>
lea    -0x70(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11c8 <main+0x98>
cmpl   $0x1,-0x74(%rbp)
jne    11c8 <main+0x98>
cmpl   $0x0,-0x78(%rbp)
jne    11c8 <main+0x98>
movl   $0x0,-0x74(%rbp)
movl   $0x1,-0x78(%rbp)
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
jmp    115c <main+0x2c>
lea    -0x70(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1214 <main+0xe4>
cmpl   $0x1,-0x74(%rbp)
jne    1214 <main+0xe4>
cmpl   $0x1,-0x78(%rbp)
jne    1214 <main+0xe4>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
jmp    115c <main+0x2c>
lea    -0x70(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1254 <main+0x124>
cmpl   $0x0,-0x74(%rbp)
jne    1254 <main+0x124>
cmpl   $0x0,-0x78(%rbp)
jne    1254 <main+0x124>
movl   $0x1,-0x74(%rbp)
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    129b <main+0x16b>
cmpl   $0x1,-0x74(%rbp)
jne    129b <main+0x16b>
cmpl   $0x0,-0x78(%rbp)
jne    129b <main+0x16b>
movl   $0x0,-0x74(%rbp)
movl   $0x1,-0x78(%rbp)
lea    0xde1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xd6b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12db <main+0x1ab>
cmpl   $0x0,-0x74(%rbp)
jne    12db <main+0x1ab>
cmpl   $0x1,-0x78(%rbp)
jne    12db <main+0x1ab>
movl   $0x1,-0x74(%rbp)
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xd82(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1322 <main+0x1f2>
cmpl   $0x1,-0x74(%rbp)
jne    1322 <main+0x1f2>
cmpl   $0x1,-0x78(%rbp)
jne    1322 <main+0x1f2>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
lea    0xd73(%rip),%rdi
call   1030 <printf@plt>
lea    0xce3(%rip),%rdi
call   1030 <printf@plt>
jmp    115c <main+0x2c>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xef3(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9f(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    0x2e78(%rip),%r13
cmp    0x0(%r13),%rax
jne    1187 <main+0x47>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0x635f6e6f74747562,%r12
6e 5f 63
xor    %r14d,%r14d
movabs $0x64656b63696c63,%rbp
mov    %rsp,%rbx
xor    %r15d,%r15d
jmp    11d7 <main+0x97>
cs nopw 0x0(%rax,%rax,1)
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
xor    %r15d,%r15d
xor    %r14d,%r14d
lea    0xe37(%rip),%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    0x0(%r13),%rax
je     1176 <main+0x36>
mov    (%rsp),%rcx
xor    %r12,%rcx
mov    0x7(%rsp),%rdx
xor    %rbp,%rdx
xor    %eax,%eax
or     %rcx,%rdx
setne  %al
mov    %r15d,%ecx
xor    $0x1,%ecx
or     %eax,%ecx
sete   %cl
jne    1220 <main+0xe0>
test   %r14d,%r14d
jne    1220 <main+0xe0>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
xor    %r15d,%r15d
jmp    11c2 <main+0x82>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%r14d
sete   %dl
and    %dl,%cl
cmp    $0x1,%cl
je     11b0 <main+0x70>
test   %eax,%eax
jne    124e <main+0x10e>
test   %r15d,%r15d
jne    124e <main+0x10e>
test   %r14d,%r14d
jne    124e <main+0x10e>
lea    0xdcf(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%r15d
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    1296 <main+0x156>
cmp    $0x1,%r15d
jne    1296 <main+0x156>
test   %r14d,%r14d
jne    1296 <main+0x156>
lea    0xda7(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%r14d
xor    %r15d,%r15d
mov    (%rsp),%rax
xor    %r12,%rax
mov    0x7(%rsp),%rcx
xor    %rbp,%rcx
or     %rax,%rcx
jne    12c7 <main+0x187>
test   %r15d,%r15d
jne    12c7 <main+0x187>
cmp    $0x1,%r14d
jne    12c7 <main+0x187>
lea    0xd7e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%r15d
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    130d <main+0x1cd>
cmp    $0x1,%r15d
jne    130d <main+0x1cd>
cmp    $0x1,%r14d
jne    130d <main+0x1cd>
lea    0xd46(%rip),%rdi
call   1050 <printf@plt>
xor    %r15d,%r15d
xor    %r14d,%r14d
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c2 <main+0x82>

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