#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 door_state(char *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ scanf(char *, char *);
int main() {
  char command[20];
  int state = 0;
  printf("Door: CLOSED\n");
  while ((scanf("%s", command)) != EOF) {
    state = door_state(command, state);
    if (state == 0)
      printf("Door: CLOSED\n");
    if (state == 1)
      printf("Door: OPENING\n");
    if (state == 2)
      printf("Door: OPEN\n");
    if (state == 3)
      printf("Door: CLOSING\n");
    if (state == 4)
      printf("Door: STOPPED_WHILE_CLOSING\n");
    if (state == 5)
      printf("Door: STOPPED_WHILE_OPENING\n");
    if (state == 6)
      return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xeb1(%rip),%rdi
call   1040 <scanf@plt>
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%rax
je     1220 <main+0xf0>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <door_state@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1197 <main+0x67>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x24(%rbp)
jne    11ad <main+0x7d>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x24(%rbp)
jne    11c3 <main+0x93>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x3,-0x24(%rbp)
jne    11d9 <main+0xa9>
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x4,-0x24(%rbp)
jne    11ef <main+0xbf>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x5,-0x24(%rbp)
jne    1205 <main+0xd5>
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x6,-0x24(%rbp)
jne    121b <main+0xeb>
movl   $0x0,-0x4(%rbp)
jmp    1227 <main+0xf7>
jmp    1152 <main+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xf39(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    0x2e85(%rip),%r12
cmp    (%r12),%rax
jne    117a <main+0x4a>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0xe96(%rip),%r15
lea    0xe73(%rip),%r13
jmp    11b6 <main+0x86>
lea    0xeda(%rip),%rdi
cs nopw 0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
cmp    (%r12),%rax
je     1169 <main+0x39>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <door_state@plt>
mov    %eax,%ebp
cmp    $0x6,%eax
ja     11a5 <main+0x75>
mov    %ebp,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
mov    %r14,%rdi
jmp    *%rax
lea    0xe88(%rip),%rdi
jmp    11a0 <main+0x70>
lea    0xe71(%rip),%rdi
jmp    11a0 <main+0x70>
lea    0xe4c(%rip),%rdi
jmp    11a0 <main+0x70>
lea    0xe27(%rip),%rdi
jmp    11a0 <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"Door: OPENING\0A\00"
@.str.3 = [12 x i8] c"Door: OPEN\0A\00"
@.str.4 = [15 x i8] c"Door: CLOSING\0A\00"
@.str.5 = [29 x i8] c"Door: STOPPED_WHILE_CLOSING\0A\00"
@.str.6 = [29 x i8] c"Door: STOPPED_WHILE_OPENING\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %47, %0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = load i64, i64* @EOF
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %48
10: ; preds = %5
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%12 = load i32, i32* %3
%13 = call i32 @door_state(i8* %11, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %3
%35 = icmp eq i32 %34, 4
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 5
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = load i32, i32* %3
%45 = icmp eq i32 %44, 6
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 0, i32* %1
br label %49
47: ; preds = %43
br label %5
48: ; preds = %5
store i32 0, i32* %1
br label %49
49: ; preds = %48, %46
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@str.7 = [28 x i8] c"Door: STOPPED_WHILE_OPENING\00"
@str.8 = [28 x i8] c"Door: STOPPED_WHILE_CLOSING\00"
@str.9 = [14 x i8] c"Door: CLOSING\00"
@str.10 = [11 x i8] c"Door: OPEN\00"
@str.11 = [14 x i8] c"Door: OPENING\00"
@str.12 = [13 x i8] c"Door: CLOSED\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(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 %22, label %7
7: ; preds = %0, %13
%8 = phi i32 [ %9, %13 ], [ 0, %0 ]
%9 = call i32 @door_state(i8* %2, i32 %8)
switch i32 %9, label %13 [
i32 0, label %10
i32 1, label %17
i32 2, label %18
i32 3, label %19
i32 4, label %20
i32 5, label %21
i32 6, label %22
]
10: ; preds = %7, %21, %20, %19, %18, %17
%11 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0), %17 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.10, i64 0, i64 0), %18 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0), %19 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0), %20 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0), %21 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0), %7 ]
%12 = call i32 @puts(i8* dereferenceable(1) %11)
br label %13
13: ; preds = %10, %7
%14 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %22, label %7
17: ; preds = %7
br label %10
18: ; preds = %7
br label %10
19: ; preds = %7
br label %10
20: ; preds = %7
br label %10
21: ; preds = %7
br label %10
22: ; preds = %7, %13, %0
ret i32 0
}