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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x84,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0xa4(%rbp)
lea    0xf09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x13(%rbp),%rsi
lea    0xf04(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
je     1331 <main+0x1f1>
lea    -0x13(%rbp),%rdi
lea    0xee7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12a9 <main+0x169>
cmpl   $0x0,-0xa4(%rbp)
jne    11d8 <main+0x98>
movl   $0x4,-0xa4(%rbp)
jmp    1278 <main+0x138>
cmpl   $0x1,-0xa4(%rbp)
jne    11f4 <main+0xb4>
movl   $0x2,-0xa4(%rbp)
jmp    1273 <main+0x133>
cmpl   $0x2,-0xa4(%rbp)
jne    1210 <main+0xd0>
movl   $0x4,-0xa4(%rbp)
jmp    126e <main+0x12e>
cmpl   $0x3,-0xa4(%rbp)
jne    122c <main+0xec>
movl   $0x1,-0xa4(%rbp)
jmp    1269 <main+0x129>
cmpl   $0x4,-0xa4(%rbp)
jne    1248 <main+0x108>
movl   $0x5,-0xa4(%rbp)
jmp    1264 <main+0x124>
cmpl   $0x5,-0xa4(%rbp)
jne    125f <main+0x11f>
movl   $0x1,-0xa4(%rbp)
jmp    1264 <main+0x124>
jmp    1269 <main+0x129>
jmp    126e <main+0x12e>
jmp    1273 <main+0x133>
jmp    1278 <main+0x138>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xa4(%rbp),%rax
lea    -0xa0(%rbp),%rsi
imul   $0x16,%rax,%rax
add    %rax,%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x13(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    132c <main+0x1ec>
cmpl   $0x1,-0xa4(%rbp)
jne    12df <main+0x19f>
movl   $0x0,-0xa4(%rbp)
jmp    12fb <main+0x1bb>
cmpl   $0x4,-0xa4(%rbp)
jne    12f6 <main+0x1b6>
movl   $0x3,-0xa4(%rbp)
jmp    12fb <main+0x1bb>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xa4(%rbp),%rax
lea    -0xa0(%rbp),%rsi
imul   $0x16,%rax,%rax
add    %rax,%rsi
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1182 <main+0x42>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xea8(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x84,%edx
call   1050 <memcpy@plt>
lea    0xf2e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf2d(%rip),%rdi
lea    0x1(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x2e5b(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    11a7 <main+0x67>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xefe(%rip),%r14
lea    0x1(%rsp),%rbx
lea    0xeef(%rip),%r12
lea    0xf02(%rip),%r13
xor    %r15d,%r15d
jmp    1208 <main+0xc8>
xor    %r15d,%r15d
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq %r15d,%rax
lea    (%rax,%rax,4),%rcx
lea    (%rax,%rcx,4),%rcx
add    %rax,%rcx
lea    (%rsp,%rcx,1),%rsi
add    $0x10,%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    0x0(%rbp),%rax
je     1193 <main+0x53>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    125a <main+0x11a>
cmp    $0x5,%r15d
ja     122c <main+0xec>
movslq %r15d,%rax
lea    0xe5c(%rip),%rcx
mov    (%rcx,%rax,4),%r15d
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq %r15d,%rax
lea    (%rax,%rax,4),%rcx
lea    (%rax,%rcx,4),%rcx
add    %rax,%rcx
lea    (%rsp,%rcx,1),%rsi
add    $0x10,%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11f7 <main+0xb7>
cmp    $0x1,%r15d
je     11c6 <main+0x86>
cmp    $0x4,%r15d
jne    11c9 <main+0x89>
mov    $0x3,%r15d
jmp    11c9 <main+0x89>

LLVM IR (-O0):
@__const.main.states = [6 x [22 x i8]] [[22 x i8] c"CLOSED\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"CLOSING\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"STOPPED_WHILE_CLOSING\00", [22 x i8] c"OPEN\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"OPENING\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"STOPPED_WHILE_OPENING\00"]
@.str = [13 x i8] c"Door: CLOSED\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [15 x i8] c"button_clicked\00"
@.str.3 = [8 x i8] c"\0ADoor: \00"
@.str.4 = [15 x i8] c"cycle_complete\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [15 x i8]
%3 = alloca [6 x [22 x i8]]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [6 x [22 x i8]]* %3 to i8*
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %72, %0
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%9 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i64, i64* @EOF
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %73
12: ; preds = %7
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %52
16: ; preds = %12
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 4, i32* %4
br label %45
20: ; preds = %16
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 2, i32* %4
br label %44
24: ; preds = %20
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 4, i32* %4
br label %43
28: ; preds = %24
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 1, i32* %4
br label %42
32: ; preds = %28
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 4
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 5, i32* %4
br label %41
36: ; preds = %32
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 5
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 1, i32* %4
br label %40
40: ; preds = %39, %36
br label %41
41: ; preds = %40, %35
br label %42
42: ; preds = %41, %31
br label %43
43: ; preds = %42, %27
br label %44
44: ; preds = %43, %23
br label %45
45: ; preds = %44, %19
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [6 x [22 x i8]], [6 x [22 x i8]]* %3, i64 0, i64 %48
%50 = getelementptr inbounds [22 x i8], [22 x i8]* %49, i64 0, i64 0
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %45, %12
%53 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %72
56: ; preds = %52
%57 = load i32, i32* %4
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %56
store i32 0, i32* %4
br label %65
60: ; preds = %56
%61 = load i32, i32* %4
%62 = icmp eq i32 %61, 4
br i1 %62, label %63, label %64
63: ; preds = %60
store i32 3, i32* %4
br label %64
64: ; preds = %63, %60
br label %65
65: ; preds = %64, %59
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* %4
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [6 x [22 x i8]], [6 x [22 x i8]]* %3, i64 0, i64 %68
%70 = getelementptr inbounds [22 x i8], [22 x i8]* %69, i64 0, i64 0
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %65, %52
br label %7
73: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@__const.main.states = [6 x [22 x i8]] [[22 x i8] c"CLOSED\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"CLOSING\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"STOPPED_WHILE_CLOSING\00", [22 x i8] c"OPEN\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"OPENING\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", [22 x i8] c"STOPPED_WHILE_OPENING\00"]
@.str = [13 x i8] c"Door: CLOSED\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [15 x i8] c"button_clicked\00"
@.str.3 = [8 x i8] c"\0ADoor: \00"
@.str.4 = [15 x i8] c"cycle_complete\00"
@switch.table.main = [6 x i32] [i32 4, i32 2, i32 4, i32 1, i32 5, i32 1]
define i32 @main() {
%1 = alloca [15 x i8]
%2 = alloca [6 x [22 x i8]]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [6 x [22 x i8]], [6 x [22 x i8]]* %2, i64 0, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %43, label %9
9: ; preds = %0, %38
%10 = phi i32 [ %39, %38 ], [ 0, %0 ]
%11 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = icmp ult i32 %10, 6
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.main, i64 0, i64 %16
%18 = load i32, i32* %17
br label %19
19: ; preds = %13, %15
%20 = phi i32 [ %18, %15 ], [ %10, %13 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds [6 x [22 x i8]], [6 x [22 x i8]]* %2, i64 0, i64 %22, i64 0
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %19, %9
%26 = phi i32 [ %20, %19 ], [ %10, %9 ]
%27 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %25
switch i32 %26, label %31 [
i32 1, label %32
i32 4, label %30
]
30: ; preds = %29
br label %32
31: ; preds = %29
br label %32
32: ; preds = %29, %31, %30
%33 = phi i32 [ 3, %30 ], [ 0, %29 ], [ %26, %31 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [6 x [22 x i8]], [6 x [22 x i8]]* %2, i64 0, i64 %35, i64 0
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %32, %25
%39 = phi i32 [ %33, %32 ], [ %26, %25 ]
%40 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%41 = load i64, i64* @EOF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %9
43: ; preds = %38, %0
ret i32 0
}