#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*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ write_console(int);
int main() {
  char input[10000];
  int state = 0;
  scanf("%[^EOF]s", input);
  printf("\n");
  char *token;
  token = strtok(input, "\n");
  while (token != NULL) {
    write_console(state);
    printf("\n");
    if (strcmp(token, "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 == 2) {
        state = 1;
      } else if (state == 4) {
        state = 0;
      }
    }
    token = strtok(NULL, "\n");
  }
  write_console(state);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x2724(%rbp)
lea    -0x2720(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
lea    -0x2720(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x2730(%rbp)
cmpq   $0x0,-0x2730(%rbp)
je     12c8 <main+0x178>
mov    -0x2724(%rbp),%edi
call   1050 <write_console@plt>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2730(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    126f <main+0x11f>
mov    -0x2724(%rbp),%eax
mov    %rax,-0x2738(%rbp)
sub    $0x5,%rax
ja     126a <main+0x11a>
mov    -0x2738(%rbp),%rax
lea    0xdf4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x2724(%rbp)
jmp    126a <main+0x11a>
movl   $0x4,-0x2724(%rbp)
jmp    126a <main+0x11a>
movl   $0x5,-0x2724(%rbp)
jmp    126a <main+0x11a>
movl   $0x3,-0x2724(%rbp)
jmp    126a <main+0x11a>
movl   $0x2,-0x2724(%rbp)
jmp    126a <main+0x11a>
movl   $0x4,-0x2724(%rbp)
jmp    12ac <main+0x15c>
cmpl   $0x2,-0x2724(%rbp)
jne    128b <main+0x13b>
movl   $0x1,-0x2724(%rbp)
jmp    12a7 <main+0x157>
cmpl   $0x4,-0x2724(%rbp)
jne    12a2 <main+0x152>
movl   $0x0,-0x2724(%rbp)
jmp    12a7 <main+0x157>
jmp    12ac <main+0x15c>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x2730(%rbp)
jmp    11a5 <main+0x55>
mov    -0x2724(%rbp),%edi
call   1050 <write_console@plt>
xor    %eax,%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2718,%rsp
lea    0xe98(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     121a <main+0xca>
mov    %rax,%rbx
xor    %r13d,%r13d
lea    0xe69(%rip),%r14
lea    0xe60(%rip),%r15
xor    %ebp,%ebp
jmp    11d5 <main+0x85>
movslq %ebp,%rax
lea    0xe65(%rip),%rcx
mov    (%rcx,%rax,4),%r12d
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
mov    %r12d,%ebp
test   %rax,%rax
je     121d <main+0xcd>
mov    %ebp,%edi
call   1050 <write_console@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1210 <main+0xc0>
mov    $0x1,%r12d
cmp    $0x2,%ebp
je     11c0 <main+0x70>
cmp    $0x4,%ebp
cmove  %r13d,%ebp
mov    %ebp,%r12d
jmp    11c0 <main+0x70>
nopl   (%rax)
cmp    $0x6,%ebp
jb     11ad <main+0x5d>
mov    %ebp,%r12d
jmp    11c0 <main+0x70>
xor    %r12d,%r12d
mov    %r12d,%edi
call   1050 <write_console@plt>
xor    %eax,%eax
add    $0x2718,%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 [10000 x i8]
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
%5 = getelementptr inbounds [10000 x i8], [10000 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 [10000 x i8], [10000 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 = %39, %0
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %41
13: ; preds = %10
%14 = load i32, i32* %3
%15 = call i32 @write_console(i32 %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %4
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %13
%21 = load i32, i32* %3
switch i32 %21, label %28 [
i32 0, label %22
i32 1, label %23
i32 4, label %24
i32 2, label %25
i32 5, label %26
i32 3, label %27
]
22: ; preds = %20
store i32 2, i32* %3
br label %28
23: ; preds = %20
store i32 4, i32* %3
br label %28
24: ; preds = %20
store i32 5, i32* %3
br label %28
25: ; preds = %20
store i32 3, i32* %3
br label %28
26: ; preds = %20
store i32 2, i32* %3
br label %28
27: ; preds = %20
store i32 4, i32* %3
br label %28
28: ; preds = %20, %27, %26, %25, %24, %23, %22
br label %39
29: ; preds = %13
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1, i32* %3
br label %38
33: ; preds = %29
%34 = load i32, i32* %3
%35 = icmp eq i32 %34, 4
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 0, i32* %3
br label %37
37: ; preds = %36, %33
br label %38
38: ; preds = %37, %32
br label %39
39: ; preds = %38, %28
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %40, i8** %4
br label %10
41: ; preds = %10
%42 = load i32, i32* %3
%43 = call i32 @write_console(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 [10000 x i8]
%2 = getelementptr inbounds [10000 x i8], [10000 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))
%6 = icmp eq i8* %5, null
br i1 %6, label %29, label %7
7: ; preds = %0, %25
%8 = phi i8* [ %27, %25 ], [ %5, %0 ]
%9 = phi i32 [ %26, %25 ], [ 0, %0 ]
%10 = call i32 @write_console(i32 %9)
%11 = call i32 @putchar(i32 10)
%12 = call i64 @strcmp(i8* %8, 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 %16
14: ; preds = %7
%15 = icmp ult i32 %9, 6
br i1 %15, label %21, label %25
16: ; preds = %7
%17 = icmp eq i32 %9, 2
br i1 %17, label %25, label %18
18: ; preds = %16
%19 = icmp eq i32 %9, 4
%20 = select i1 %19, i32 0, i32 %9
br label %25
21: ; preds = %14
%22 = sext i32 %9 to i64
%23 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.main, i64 0, i64 %22
%24 = load i32, i32* %23
br label %25
25: ; preds = %21, %14, %16, %18
%26 = phi i32 [ %9, %14 ], [ %20, %18 ], [ 1, %16 ], [ %24, %21 ]
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %7
29: ; preds = %25, %0
%30 = phi i32 [ 0, %0 ], [ %26, %25 ]
%31 = call i32 @write_console(i32 %30)
ret i32 0
}