#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*/ printMsg(int);
scalar_t__ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main() {
  char input[30];
  int doorStatus = 0;
  printMsg(doorStatus);
  while (scanf("%s", input) != EOF) {
    if (strcmp(input, "button_clicked") == 0) {
      switch (doorStatus) {
      case 0: {
        doorStatus = 1;
        printMsg(doorStatus);
      } break;
      case 1: {
        doorStatus = 5;
        printMsg(doorStatus);
      } break;
      case 2: {
        doorStatus = 3;
        printMsg(doorStatus);
      } break;
      case 3: {
        doorStatus = 4;
        printMsg(doorStatus);
      } break;
      case 4: {
        doorStatus = 1;
        printMsg(doorStatus);
      } break;
      case 5: {
        doorStatus = 3;
        printMsg(doorStatus);
      } break;
      }
    } else if (strcmp(input, "cycle_complete") == 0) {
      switch (doorStatus) {
      case 1: {
        doorStatus = 2;
        printMsg(doorStatus);
      } break;
      case 3: {
        doorStatus = 0;
        printMsg(doorStatus);
      } break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
lea    -0x30(%rbp),%rsi
lea    0xebf(%rip),%rdi
call   1050 <scanf@plt>
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
je     1296 <main+0x166>
lea    -0x30(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1225 <main+0xf5>
mov    -0x34(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0x5,%rax
ja     1220 <main+0xf0>
mov    -0x40(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    1220 <main+0xf0>
movl   $0x5,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    1220 <main+0xf0>
movl   $0x3,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    1220 <main+0xf0>
movl   $0x4,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    1220 <main+0xf0>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    1220 <main+0xf0>
movl   $0x3,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    1291 <main+0x161>
lea    -0x30(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    128c <main+0x15c>
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x1,%eax
je     1264 <main+0x134>
jmp    1253 <main+0x123>
mov    -0x44(%rbp),%eax
sub    $0x3,%eax
je     1278 <main+0x148>
jmp    1287 <main+0x157>
movl   $0x2,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    1287 <main+0x157>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <printMsg@plt>
jmp    128c <main+0x15c>
jmp    1291 <main+0x161>
jmp    114e <main+0x1e>
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
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <printMsg@plt>
lea    0xeb2(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    0x2e8b(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1174 <main+0x44>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe88(%rip),%r14
mov    %rsp,%r15
lea    0xe7b(%rip),%r12
lea    0xe86(%rip),%r13
jmp    11ab <main+0x7b>
mov    $0x2,%ebx
mov    %ebx,%edi
call   1040 <printMsg@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
cmp    0x0(%rbp),%rax
je     1163 <main+0x33>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <main+0xb0>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    119a <main+0x6a>
cmp    $0x1,%ebx
je     118e <main+0x5e>
cmp    $0x3,%ebx
jne    119a <main+0x6a>
xor    %ebx,%ebx
jmp    1193 <main+0x63>
nopl   0x0(%rax)
cmp    $0x6,%ebx
jae    119a <main+0x6a>
movslq %ebx,%rax
lea    0xe35(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
jmp    1193 <main+0x63>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.1 = [15 x i8] c"button_clicked\00"
@.str.2 = [15 x i8] c"cycle_complete\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 = load i32, i32* %3
%5 = call i32 @printMsg(i32 %4)
br label %6
6: ; preds = %50, %0
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %51
11: ; preds = %6
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %11
%16 = load i32, i32* %3
switch i32 %16, label %35 [
i32 0, label %17
i32 1, label %20
i32 2, label %23
i32 3, label %26
i32 4, label %29
i32 5, label %32
]
17: ; preds = %15
store i32 1, i32* %3
%18 = load i32, i32* %3
%19 = call i32 @printMsg(i32 %18)
br label %35
20: ; preds = %15
store i32 5, i32* %3
%21 = load i32, i32* %3
%22 = call i32 @printMsg(i32 %21)
br label %35
23: ; preds = %15
store i32 3, i32* %3
%24 = load i32, i32* %3
%25 = call i32 @printMsg(i32 %24)
br label %35
26: ; preds = %15
store i32 4, i32* %3
%27 = load i32, i32* %3
%28 = call i32 @printMsg(i32 %27)
br label %35
29: ; preds = %15
store i32 1, i32* %3
%30 = load i32, i32* %3
%31 = call i32 @printMsg(i32 %30)
br label %35
32: ; preds = %15
store i32 3, i32* %3
%33 = load i32, i32* %3
%34 = call i32 @printMsg(i32 %33)
br label %35
35: ; preds = %15, %32, %29, %26, %23, %20, %17
br label %50
36: ; preds = %11
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i32, i32* %3
switch i32 %41, label %48 [
i32 1, label %42
i32 3, label %45
]
42: ; preds = %40
store i32 2, i32* %3
%43 = load i32, i32* %3
%44 = call i32 @printMsg(i32 %43)
br label %48
45: ; preds = %40
store i32 0, i32* %3
%46 = load i32, i32* %3
%47 = call i32 @printMsg(i32 %46)
br label %48
48: ; preds = %40, %45, %42
br label %49
49: ; preds = %48, %36
br label %50
50: ; preds = %49, %35
br label %6
51: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.1 = [15 x i8] c"button_clicked\00"
@.str.2 = [15 x i8] c"cycle_complete\00"
@switch.table.main = [6 x i32] [i32 1, i32 5, i32 3, i32 4, i32 1, i32 3]
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 @printMsg(i32 0)
%4 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %30, label %7
7: ; preds = %0, %25
%8 = phi i32 [ %26, %25 ], [ 0, %0 ]
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = icmp ult i32 %8, 6
br i1 %12, label %18, label %25
13: ; preds = %7
%14 = call i64 @strcmp(i8* %2, 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 %25
16: ; preds = %13
switch i32 %8, label %25 [
i32 1, label %22
i32 3, label %17
]
17: ; preds = %16
br label %22
18: ; preds = %11
%19 = sext i32 %8 to i64
%20 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.main, i64 0, i64 %19
%21 = load i32, i32* %20
br label %22
22: ; preds = %18, %16, %17
%23 = phi i32 [ 0, %17 ], [ 2, %16 ], [ %21, %18 ]
%24 = call i32 @printMsg(i32 %23)
br label %25
25: ; preds = %11, %22, %13, %16
%26 = phi i32 [ %8, %11 ], [ %8, %16 ], [ %8, %13 ], [ %23, %22 ]
%27 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %7
30: ; preds = %25, %0
ret i32 0
}