#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 */
int /*<<< orphan*/ door_state(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int main() {
  char commands[500];
  int state = 0;
  scanf("%[^EOF]s", commands);
  printf("\n");
  char *string;
  string = strtok(commands, "\n");
  do {
    door_state(state);
    printf("\n");
    if (strcmp(string, "button_clicked") == 0) {
      switch (state) {
      case 0:
        state = 2;
        break;
      case 1:
        state = 4;
        break;
      case 4:
        state = 5;
        break;
      case 2:
        state = 3;
        break;
      case 5:
        state = 2;
        break;
      case 3:
        state = 4;
        break;
      }
    } else {
      if (state == 4) {
        state = 0;
      } else if (state == 2) {
        state = 1;
      }
    }
    string = strtok(NULL, "\n");
  } while (string != NULL);
  door_state(state);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x204(%rbp)
lea    -0x200(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1050 <scanf@plt>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
lea    -0x200(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x210(%rbp)
mov    -0x204(%rbp),%edi
call   1070 <door_state@plt>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x210(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1261 <main+0x111>
mov    -0x204(%rbp),%eax
mov    %rax,-0x218(%rbp)
sub    $0x5,%rax
ja     125c <main+0x10c>
mov    -0x218(%rbp),%rax
lea    0xe02(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x204(%rbp)
jmp    125c <main+0x10c>
movl   $0x4,-0x204(%rbp)
jmp    125c <main+0x10c>
movl   $0x5,-0x204(%rbp)
jmp    125c <main+0x10c>
movl   $0x3,-0x204(%rbp)
jmp    125c <main+0x10c>
movl   $0x2,-0x204(%rbp)
jmp    125c <main+0x10c>
movl   $0x4,-0x204(%rbp)
jmp    129e <main+0x14e>
cmpl   $0x4,-0x204(%rbp)
jne    127d <main+0x12d>
movl   $0x0,-0x204(%rbp)
jmp    1299 <main+0x149>
cmpl   $0x2,-0x204(%rbp)
jne    1294 <main+0x144>
movl   $0x1,-0x204(%rbp)
jmp    1299 <main+0x149>
jmp    129e <main+0x14e>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd78(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x210(%rbp)
cmpq   $0x0,-0x210(%rbp)
jne    11a5 <main+0x55>
mov    -0x204(%rbp),%edi
call   1070 <door_state@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f8,%rsp
lea    0xe98(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe85(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
lea    0xe6f(%rip),%r15
mov    $0x1,%r13d
jmp    11d2 <main+0x82>
movslq %ebp,%rax
lea    0xe6e(%rip),%rcx
mov    (%rcx,%rax,4),%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     121a <main+0xca>
mov    %r12d,%ebp
mov    %r12d,%edi
call   1070 <door_state@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1210 <main+0xc0>
xor    %r12d,%r12d
cmp    $0x4,%ebp
je     11c0 <main+0x70>
cmp    $0x2,%ebp
cmove  %r13d,%ebp
mov    %ebp,%r12d
jmp    11c0 <main+0x70>
nopl   0x0(%rax,%rax,1)
cmp    $0x6,%ebp
jb     11a4 <main+0x54>
mov    %ebp,%r12d
jmp    11c0 <main+0x70>
mov    %r12d,%edi
call   1070 <door_state@plt>
xor    %eax,%eax
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%[^EOF]s\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [15 x i8] c"button_clicked\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500 x i8]
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%9 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %4
br label %10
10: ; preds = %38, %0
%11 = load i32, i32* %3
%12 = call i32 @door_state(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %4
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %10
%18 = load i32, i32* %3
switch i32 %18, label %25 [
i32 0, label %19
i32 1, label %20
i32 4, label %21
i32 2, label %22
i32 5, label %23
i32 3, label %24
]
19: ; preds = %17
store i32 2, i32* %3
br label %25
20: ; preds = %17
store i32 4, i32* %3
br label %25
21: ; preds = %17
store i32 5, i32* %3
br label %25
22: ; preds = %17
store i32 3, i32* %3
br label %25
23: ; preds = %17
store i32 2, i32* %3
br label %25
24: ; preds = %17
store i32 4, i32* %3
br label %25
25: ; preds = %17, %24, %23, %22, %21, %20, %19
br label %36
26: ; preds = %10
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 4
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 0, i32* %3
br label %35
30: ; preds = %26
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 1, i32* %3
br label %34
34: ; preds = %33, %30
br label %35
35: ; preds = %34, %29
br label %36
36: ; preds = %35, %25
%37 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %37, i8** %4
br label %38
38: ; preds = %36
%39 = load i8*, i8** %4
%40 = icmp ne i8* %39, null
br i1 %40, label %10, label %41
41: ; preds = %38
%42 = load i32, i32* %3
%43 = call i32 @door_state(i32 %42)
ret i32 0
}

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