#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ errno;
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strsep(char **, char *);
int main(int argc, char *argv[]) {
  char *buf[1024];
  int no_errors = 1;
  int state = 0;
  while (!(state & 4) &&
         (char *)&buf == fgets((char *)&buf, sizeof buf, stdin)) {
    printf("buffer: %s", (char *)&buf);
    char *buf2, *token;
    for (buf2 = (char *)&buf;
         !(state > 3 || NULL == (token = strsep(&buf2, " \t,")));) {
      printf("token: \"%s\"\n", token);
      if (state < 1)
        state |= !strncmp("move", token, 4) << 0 |
                 !strncmp("pile", token, 4) << 1 |
                 !strncmp("quit", token, 4) << 2;
      else {
        state |= 8;
      }
    }
    printf("state now %i\n", state);
    if (state && !(state & 4)) {
      printf("executing some command; resetting state when complete\n");
      state = 0;
    }
  }
  if (errno || !no_errors) {
    perror(argv[0]);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x2014(%rbp)
movl   $0x0,-0x2018(%rbp)
mov    -0x2018(%rbp),%ecx
and    $0x4,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2029(%rbp)
jne    11d5 <main+0x85>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2038(%rbp)
lea    -0x2010(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    $0x2000,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
mov    -0x2038(%rbp),%rax
cmp    %rcx,%rax
sete   %al
mov    %al,-0x2029(%rbp)
mov    -0x2029(%rbp),%al
test   $0x1,%al
jne    11e8 <main+0x98>
jmp    1393 <main+0x243>
lea    -0x2010(%rbp),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2020(%rbp)
mov    $0x1,%al
cmpl   $0x3,-0x2018(%rbp)
mov    %al,-0x2039(%rbp)
jg     124b <main+0xfb>
lea    -0x2020(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,%rcx
mov    %rcx,-0x2028(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
mov    %al,-0x2039(%rbp)
mov    -0x2039(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    1260 <main+0x110>
jmp    1343 <main+0x1f3>
mov    -0x2028(%rbp),%rsi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x2018(%rbp)
jge    132f <main+0x1df>
mov    -0x2028(%rbp),%rsi
lea    0xd8c(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
shl    $0x0,%eax
mov    %eax,-0x2044(%rbp)
mov    -0x2028(%rbp),%rsi
lea    0xd63(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
mov    -0x2044(%rbp),%eax
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
shl    $0x1,%ecx
or     %ecx,%eax
mov    %eax,-0x2040(%rbp)
mov    -0x2028(%rbp),%rsi
lea    0xd2e(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
mov    -0x2040(%rbp),%eax
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
shl    $0x2,%ecx
or     %ecx,%eax
or     -0x2018(%rbp),%eax
mov    %eax,-0x2018(%rbp)
jmp    133e <main+0x1ee>
mov    -0x2018(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x2018(%rbp)
jmp    120b <main+0xbb>
mov    -0x2018(%rbp),%esi
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x2018(%rbp)
je     138e <main+0x23e>
mov    -0x2018(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    138e <main+0x23e>
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2018(%rbp)
jmp    117d <main+0x2d>
mov    0x2c3e(%rip),%rax
cmpq   $0x0,(%rax)
jne    13b1 <main+0x261>
cmpl   $0x0,-0x2014(%rbp)
jne    13ce <main+0x27e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <perror@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13da <main+0x28a>
mov    0x2bf3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,(%rsp)
lea    0x10(%rsp),%r15
lea    0xe8a(%rip),%r13
lea    0x8(%rsp),%r14
lea    0xe82(%rip),%rbx
xor    %r12d,%r12d
mov    %rbx,%rbp
jmp    11af <main+0x4f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%r12d
test   $0x4,%bl
mov    %rbp,%rbx
jne    12f2 <main+0x192>
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x2000,%esi
call   1060 <fgets@plt>
cmp    %r15,%rax
jne    12f2 <main+0x192>
lea    0xe2b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,0x8(%rsp)
jmp    11f3 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
or     %eax,%r12d
cmp    $0x3,%r12d
jg     1290 <main+0x130>
mov    %r14,%rdi
mov    %r13,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     12d0 <main+0x170>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x8,%eax
test   %r12d,%r12d
jg     11f0 <main+0x90>
lea    0xdea(%rip),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
lea    0xdd4(%rip),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rbx,%rcx,2),%ebx
lea    0xdbb(%rip),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rbx,%rcx,4),%eax
mov    %rbp,%rbx
jmp    11f0 <main+0x90>
nopw   0x0(%rax,%rax,1)
lea    0xd94(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%r15
mov    %r12d,%ebx
test   $0x4,%r12b
jne    11a0 <main+0x40>
lea    0xd7f(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    11a0 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
xor    %ebx,%ebx
lea    0xd52(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12d,%r12d
lea    0x10(%rsp),%r15
jne    12a6 <main+0x146>
jmp    11a0 <main+0x40>
mov    0x2cdf(%rip),%rax
cmpq   $0x0,(%rax)
jne    131a <main+0x1ba>
mov    0x2cc2(%rip),%rax
mov    (%rax),%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rax
mov    (%rax),%rdi
call   1080 <perror@plt>
mov    0x2ca3(%rip),%rax
jmp    1306 <main+0x1a6>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [11 x i8] c"buffer: %s\00"
@.str.1 = [4 x i8] c" \09,\00"
@.str.2 = [13 x i8] c"token: \22%s\22\0A\00"
@.str.3 = [5 x i8] c"move\00"
@.str.4 = [5 x i8] c"pile\00"
@.str.5 = [5 x i8] c"quit\00"
@.str.6 = [14 x i8] c"state now %i\0A\00"
@.str.7 = [55 x i8] c"executing some command; resetting state when complete\0A\00"
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %79, %2
%12 = load i32, i32* %8
%13 = and i32 %12, 4
%14 = icmp ne i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = bitcast [1024 x i8*]* %6 to i8*
%17 = bitcast [1024 x i8*]* %6 to i8*
%18 = load i32, i32* @stdin
%19 = call i8* @fgets(i8* %17, i32 8192, i32 %18)
%20 = icmp eq i8* %16, %19
br label %21
21: ; preds = %15, %11
%22 = phi i1 [ false, %11 ], [ %20, %15 ]
br i1 %22, label %23, label %80
23: ; preds = %21
%24 = bitcast [1024 x i8*]* %6 to i8*
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = bitcast [1024 x i8*]* %6 to i8*
store i8* %26, i8** %9
br label %27
27: ; preds = %67, %23
%28 = load i32, i32* %8
%29 = icmp sgt i32 %28, 3
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = call i8* @strsep(i8** %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %10
%32 = icmp eq i8* null, %31
br label %33
33: ; preds = %30, %27
%34 = phi i1 [ true, %27 ], [ %32, %30 ]
%35 = xor i1 %34, true
br i1 %35, label %36, label %68
36: ; preds = %33
%37 = load i8*, i8** %10
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 1
br i1 %40, label %41, label %64
41: ; preds = %36
%42 = load i8*, i8** %10
%43 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %42, i32 4)
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
%46 = zext i1 %45 to i32
%47 = shl i32 %46, 0
%48 = load i8*, i8** %10
%49 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32 4)
%50 = icmp ne i32 %49, 0
%51 = xor i1 %50, true
%52 = zext i1 %51 to i32
%53 = shl i32 %52, 1
%54 = or i32 %47, %53
%55 = load i8*, i8** %10
%56 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %55, i32 4)
%57 = icmp ne i32 %56, 0
%58 = xor i1 %57, true
%59 = zext i1 %58 to i32
%60 = shl i32 %59, 2
%61 = or i32 %54, %60
%62 = load i32, i32* %8
%63 = or i32 %62, %61
store i32 %63, i32* %8
br label %67
64: ; preds = %36
%65 = load i32, i32* %8
%66 = or i32 %65, 8
store i32 %66, i32* %8
br label %67
67: ; preds = %64, %41
br label %27
68: ; preds = %33
%69 = load i32, i32* %8
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %69)
%71 = load i32, i32* %8
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = load i32, i32* %8
%75 = and i32 %74, 4
%76 = icmp ne i32 %75, 0
br i1 %76, label %79, label %77
77: ; preds = %73
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %8
br label %79
79: ; preds = %77, %73, %68
br label %11
80: ; preds = %21
%81 = load i64, i64* @errno
%82 = icmp ne i64 %81, 0
br i1 %82, label %86, label %83
83: ; preds = %80
%84 = load i32, i32* %7
%85 = icmp ne i32 %84, 0
br i1 %85, label %92, label %86
86: ; preds = %83, %80
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 0
%89 = load i8*, i8** %88
%90 = call i32 @perror(i8* %89)
%91 = load i32, i32* @EXIT_FAILURE
store i32 %91, i32* %3
br label %94
92: ; preds = %83
%93 = load i32, i32* @EXIT_SUCCESS
store i32 %93, i32* %3
br label %94
94: ; preds = %92, %86
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [11 x i8] c"buffer: %s\00"
@.str.1 = [4 x i8] c" \09,\00"
@.str.2 = [13 x i8] c"token: \22%s\22\0A\00"
@.str.3 = [5 x i8] c"move\00"
@.str.4 = [5 x i8] c"pile\00"
@.str.5 = [5 x i8] c"quit\00"
@.str.6 = [14 x i8] c"state now %i\0A\00"
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [54 x i8] c"executing some command; resetting state when complete\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8*]
%4 = alloca i8*
%5 = bitcast [1024 x i8*]* %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = bitcast i8** %4 to [1024 x i8*]**
br label %8
8: ; preds = %2, %51
%9 = phi i32 [ 0, %2 ], [ %52, %51 ]
%10 = load i32, i32* @stdin
%11 = call i8* @fgets(i8* %5, i32 8192, i32 %10)
%12 = icmp eq i8* %11, %5
br i1 %12, label %13, label %55
13: ; preds = %8
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), [1024 x i8*]* %3)
store [1024 x i8*]* %3, [1024 x i8*]** %7
%15 = icmp sgt i32 %9, 3
br i1 %15, label %16, label %19
16: ; preds = %38, %13
%17 = phi i32 [ %9, %13 ], [ %40, %38 ]
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %17)
br label %45
19: ; preds = %13, %38
%20 = phi i32 [ %40, %38 ], [ %9, %13 ]
%21 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %42, label %23
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%25 = icmp slt i32 %20, 1
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %21, i32 4)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %21, i32 4)
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i32 2, i32 0
%33 = or i32 %32, %29
%34 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %21, i32 4)
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i32 4, i32 0
%37 = or i32 %33, %36
br label %38
38: ; preds = %23, %26
%39 = phi i32 [ %37, %26 ], [ 8, %23 ]
%40 = or i32 %39, %20
%41 = icmp sgt i32 %40, 3
br i1 %41, label %16, label %19
42: ; preds = %19
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %20)
%44 = icmp eq i32 %20, 0
br i1 %44, label %51, label %45
45: ; preds = %16, %42
%46 = phi i32 [ %17, %16 ], [ %20, %42 ]
%47 = and i32 %46, 4
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
br label %51
51: ; preds = %49, %45, %42
%52 = phi i32 [ %46, %45 ], [ 0, %49 ], [ 0, %42 ]
%53 = and i32 %52, 4
%54 = icmp eq i32 %53, 0
br i1 %54, label %8, label %55
55: ; preds = %51, %8
%56 = load i64, i64* @errno
%57 = icmp eq i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = load i8*, i8** %1
%60 = call i32 @perror(i8* %59)
br label %61
61: ; preds = %55, %58
%62 = phi i32* [ @EXIT_FAILURE, %58 ], [ @EXIT_SUCCESS, %55 ]
%63 = load i32, i32* %62
ret i32 %63
}