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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xee3(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xee1(%rip),%rdi
call   1050 <scanf@plt>
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%rax
je     12e5 <main+0x1b5>
lea    -0x30(%rbp),%rdi
lea    0xec4(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1241 <main+0x111>
mov    -0x34(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0x5,%rax
ja     123c <main+0x10c>
mov    -0x40(%rbp),%rax
lea    0xe58(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x34(%rbp)
jmp    123c <main+0x10c>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x34(%rbp)
jmp    123c <main+0x10c>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x34(%rbp)
jmp    123c <main+0x10c>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,-0x34(%rbp)
jmp    123c <main+0x10c>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x34(%rbp)
jmp    123c <main+0x10c>
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x34(%rbp)
jmp    1241 <main+0x111>
lea    -0x30(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12e0 <main+0x1b0>
mov    -0x34(%rbp),%eax
mov    %rax,-0x48(%rbp)
sub    $0x5,%rax
ja     12db <main+0x1ab>
mov    -0x48(%rbp),%rax
lea    0xda1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xda9(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    12db <main+0x1ab>
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x34(%rbp)
jmp    12db <main+0x1ab>
lea    0xd79(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
jmp    12db <main+0x1ab>
lea    0xde8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x34(%rbp)
jmp    12e0 <main+0x1b0>
jmp    1152 <main+0x22>
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
lea    0xee7(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    0x2e88(%rip),%r13
cmp    0x0(%r13),%rax
jne    1177 <main+0x47>
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    0xf0c(%rip),%rbp
lea    0xe87(%rip),%r15
lea    0xe6e(%rip),%r12
jmp    11b1 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    0x0(%r13),%rax
je     1166 <main+0x36>
mov    %rbx,%rdi
lea    0xe48(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11e6 <main+0xb6>
cmp    $0x5,%r14d
ja     11e6 <main+0xb6>
movslq %r14d,%rax
movslq 0x0(%rbp,%rax,4),%rdi
add    %rbp,%rdi
lea    0xecb(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11a0 <main+0x70>
cmp    $0x5,%r14d
ja     11a0 <main+0x70>
mov    $0x2b,%eax
bt     %r14d,%eax
jae    11a0 <main+0x70>
movslq %r14d,%rax
lea    0xeaf(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
lea    0xeb9(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
call   1030 <puts@plt>
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"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 [30 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 = %44, %0
%6 = getelementptr inbounds [30 x i8], [30 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 %45
10: ; preds = %5
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i32, i32* %3
switch i32 %15, label %28 [
i32 0, label %16
i32 1, label %18
i32 2, label %20
i32 3, label %22
i32 4, label %24
i32 5, label %26
]
16: ; preds = %14
%17 = 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 %28
18: ; preds = %14
%19 = 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 %28
20: ; preds = %14
%21 = 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 %28
22: ; preds = %14
%23 = 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 %28
24: ; preds = %14
%25 = 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 %28
26: ; preds = %14
%27 = 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 %28
28: ; preds = %14, %26, %24, %22, %20, %18, %16
br label %29
29: ; preds = %28, %10
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i32, i32* %3
switch i32 %34, label %43 [
i32 0, label %35
i32 1, label %37
i32 3, label %39
i32 5, label %41
]
35: ; preds = %33
%36 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %43
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i32 5, i32* %3
br label %43
39: ; preds = %33
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %43
41: ; preds = %33
%42 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i32 5, i32* %3
br label %43
43: ; preds = %33, %41, %39, %37, %35
br label %44
44: ; preds = %43, %29
br label %5
45: ; preds = %5
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.11 = [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)]
@switch.table.main.19 = [6 x i32] [i32 1, i32 2, i32 3, i32 4, i32 1, i32 3]
@reltable.main.22 = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.22 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.11 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.22 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.22 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.22 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.12 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.22 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.11 to i64), i64 ptrtoint ([6 x i32]* @reltable.main.22 to i64)) to i32)]
@switch.table.main.21 = [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 @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 %45, label %7
7: ; preds = %0, %40
%8 = phi i32 [ %41, %40 ], [ 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 %21
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 = sext i32 %8 to i64
%18 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.main.19, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @puts(i8* dereferenceable(1) %16)
br label %21
21: ; preds = %13, %7
%22 = phi i32 [ %8, %7 ], [ %19, %13 ]
%23 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
%25 = icmp ult i32 %22, 6
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %40
27: ; preds = %21
%28 = trunc i32 %22 to i8
%29 = lshr i8 43, %28
%30 = and i8 %29, 1
%31 = icmp eq i8 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %27
%33 = sext i32 %22 to i64
%34 = shl i64 %33, 2
%35 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.main.22 to i8*), i64 %34)
%36 = sext i32 %22 to i64
%37 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.main.21, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = call i32 @puts(i8* dereferenceable(1) %35)
br label %40
40: ; preds = %27, %32, %21
%41 = phi i32 [ %22, %21 ], [ %38, %32 ], [ %22, %27 ]
%42 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%43 = load i64, i64* @EOF
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %7
45: ; preds = %40, %0
ret i32 0
}