#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*/ Delay(int);
scalar_t__ IsHalt(char *);
scalar_t__ IsRun(char *);
scalar_t__ IsTrain(char *);
int /*<<< orphan*/ Read(char *, int);
int Receive(char **, int);
int /*<<< orphan*/ RegisterAs(char *);
int /*<<< orphan*/ Reply(int, int /*<<< orphan*/, int /*<<< orphan*/);
int RunWhat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ Send(int, char **, int, int /*<<< orphan*/,
                        int /*<<< orphan*/);
int /*<<< orphan*/ Write(char *, int /*<<< orphan*/, int);
int getInt(char *, int /*<<< orphan*/);
char getSens(char *, int /*<<< orphan*/);
int /*<<< orphan*/ len(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strLen(char *);
int validTrainNum(int, char *);
main() {
  char InputData[23];
  char WriteData[23];
  char Instruction[4];
  char runningTrain[6];
  int TrainNum;
  char SrcNode;
  char DestNode;
  int DoWhat;
  int CentralControlTID;
  RegisterAs("Tokenizer");
  Delay(10);
  CentralControlTID = Receive(&runningTrain, (6 * sizeof(char)));
  Reply(CentralControlTID, 0, 0);
  while (1) {
    sprintf(WriteData, "\n$ ");
    Write(WriteData, strLen(WriteData), 1);
    Read(InputData, 1);
    if (IsHalt(InputData)) {
      Instruction[0] = 0;
      Send(CentralControlTID, &Instruction, (sizeof(char) * 4), 0, 0);
    } else if (IsTrain(InputData)) {
      TrainNum = getInt(InputData, len("train "));
      TrainNum = validTrainNum(TrainNum, runningTrain);
      SrcNode = getSens(InputData, len("train nn -s "));
      DestNode = getSens(InputData, len("train nn -s nnn -e "));
      if ((TrainNum < 0) || (SrcNode < 0) || (DestNode < 0)) {
        TrainNum = (-5);
      } else {
        Instruction[0] = 4;
        Instruction[1] = TrainNum;
        Instruction[2] = SrcNode;
        Instruction[3] = DestNode;
        Send(CentralControlTID, &Instruction, (sizeof(char) * 4), 0, 0);
      }
    } else if (IsRun(InputData)) {
      DoWhat = RunWhat(InputData, len("run "));
      if (DoWhat == 0) {
        Instruction[0] = 1;
        Send(CentralControlTID, &Instruction, (sizeof(char) * 4), 0, 0);
      } else if (DoWhat == 1) {
        Instruction[0] = 2;
        Send(CentralControlTID, &Instruction, (sizeof(char) * 4), 0, 0);
      } else if (DoWhat == 2) {
        Instruction[0] = 3;
        Send(CentralControlTID, &Instruction, (sizeof(char) * 4), 0, 0);
      }
    } else {
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xdd7(%rip),%rdi
call   10f0 <RegisterAs@plt>
mov    $0xa,%edi
call   1040 <Delay@plt>
lea    -0x4a(%rbp),%rdi
mov    $0x6,%esi
call   1050 <Receive@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <Reply@plt>
lea    -0x40(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1130 <sprintf@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x40(%rbp),%rdi
call   10d0 <strLen@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <Write@plt>
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1060 <Read@plt>
lea    -0x20(%rbp),%rdi
call   10b0 <IsHalt@plt>
cmp    $0x0,%rax
je     12c7 <main+0xb7>
movb   $0x0,-0x44(%rbp)
mov    -0x5c(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   10e0 <Send@plt>
jmp    1483 <main+0x273>
lea    -0x20(%rbp),%rdi
call   1100 <IsTrain@plt>
cmp    $0x0,%rax
je     13b1 <main+0x1a1>
lea    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    0xd25(%rip),%rdi
call   1030 <len@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   1110 <getInt@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x4a(%rbp),%rsi
call   1120 <validTrainNum@plt>
mov    %eax,-0x50(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xcfb(%rip),%rdi
call   1030 <len@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
call   10a0 <getSens@plt>
mov    %al,-0x51(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    0xce6(%rip),%rdi
call   1030 <len@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
call   10a0 <getSens@plt>
mov    %al,-0x52(%rbp)
cmpl   $0x0,-0x50(%rbp)
jl     1373 <main+0x163>
movsbl -0x51(%rbp),%eax
cmp    $0x0,%eax
jl     1373 <main+0x163>
movsbl -0x52(%rbp),%eax
cmp    $0x0,%eax
jge    137f <main+0x16f>
movl   $0xfffffffb,-0x50(%rbp)
jmp    13ac <main+0x19c>
movb   $0x4,-0x44(%rbp)
mov    -0x50(%rbp),%eax
mov    %al,-0x43(%rbp)
mov    -0x51(%rbp),%al
mov    %al,-0x42(%rbp)
mov    -0x52(%rbp),%al
mov    %al,-0x41(%rbp)
mov    -0x5c(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   10e0 <Send@plt>
jmp    147e <main+0x26e>
lea    -0x20(%rbp),%rdi
call   1070 <IsRun@plt>
cmp    $0x0,%rax
je     1474 <main+0x264>
lea    -0x20(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xc60(%rip),%rdi
call   1030 <len@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
call   10c0 <RunWhat@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jne    1416 <main+0x206>
movb   $0x1,-0x44(%rbp)
mov    -0x5c(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   10e0 <Send@plt>
jmp    146f <main+0x25f>
cmpl   $0x1,-0x58(%rbp)
jne    1440 <main+0x230>
movb   $0x2,-0x44(%rbp)
mov    -0x5c(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   10e0 <Send@plt>
jmp    146a <main+0x25a>
cmpl   $0x2,-0x58(%rbp)
jne    1465 <main+0x255>
movb   $0x3,-0x44(%rbp)
mov    -0x5c(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   10e0 <Send@plt>
jmp    146a <main+0x25a>
jmp    146f <main+0x25f>
jmp    1479 <main+0x269>
jmp    1479 <main+0x269>
jmp    147e <main+0x26e>
jmp    1483 <main+0x273>
jmp    1255 <main+0x45>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xdeb(%rip),%rdi
call   10f0 <RegisterAs@plt>
mov    $0xa,%edi
call   1040 <Delay@plt>
lea    0xa(%rsp),%rdi
mov    $0x6,%esi
call   1050 <Receive@plt>
mov    %eax,%r15d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <Reply@plt>
lea    0x10(%rsp),%rbx
lea    0x30(%rsp),%rbp
lea    0x6(%rsp),%r13
jmp    127a <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,0x6(%rsp)
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10e0 <Send@plt>
movl   $0x20240a,0x10(%rsp)
mov    %rbx,%rdi
call   10d0 <strLen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1090 <Write@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
call   1060 <Read@plt>
mov    %rbp,%rdi
call   10b0 <IsHalt@plt>
test   %rax,%rax
jne    1260 <main+0x60>
mov    %rbp,%rdi
call   1100 <IsTrain@plt>
test   %rax,%rax
je     134a <main+0x14a>
lea    0xd3f(%rip),%rdi
call   1030 <len@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1110 <getInt@plt>
mov    %eax,%edi
lea    0xa(%rsp),%rsi
call   1120 <validTrainNum@plt>
mov    %eax,%r12d
lea    0xd21(%rip),%rdi
call   1030 <len@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   10a0 <getSens@plt>
mov    %eax,%r14d
lea    0xd15(%rip),%rdi
call   1030 <len@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   10a0 <getSens@plt>
test   %r12d,%r12d
js     127a <main+0x7a>
test   %r14b,%r14b
js     127a <main+0x7a>
test   %al,%al
js     127a <main+0x7a>
movb   $0x4,0x6(%rsp)
mov    %r12b,0x7(%rsp)
mov    %r14b,0x8(%rsp)
mov    %al,0x9(%rsp)
jmp    1265 <main+0x65>
mov    %rbp,%rdi
call   1070 <IsRun@plt>
test   %rax,%rax
je     127a <main+0x7a>
lea    0xcd0(%rip),%rdi
call   1030 <len@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   10c0 <RunWhat@plt>
cmp    $0x2,%eax
je     138d <main+0x18d>
cmp    $0x1,%eax
je     1397 <main+0x197>
test   %eax,%eax
jne    127a <main+0x7a>
movb   $0x1,0x6(%rsp)
jmp    1265 <main+0x65>
movb   $0x3,0x6(%rsp)
jmp    1265 <main+0x65>
movb   $0x2,0x6(%rsp)
jmp    1265 <main+0x65>

LLVM IR (-O0):
@.str = [10 x i8] c"Tokenizer\00"
@.str.1 = [4 x i8] c"\0A$ \00"
@.str.2 = [7 x i8] c"train \00"
@.str.3 = [13 x i8] c"train nn -s \00"
@.str.4 = [20 x i8] c"train nn -s nnn -e \00"
@.str.5 = [5 x i8] c"run \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [23 x i8]
%3 = alloca [23 x i8]
%4 = alloca [4 x i8]
%5 = alloca [6 x i8]
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32 @RegisterAs(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @Delay(i32 10)
%13 = bitcast [6 x i8]* %5 to i8**
%14 = call i32 @Receive(i8** %13, i32 6)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = call i32 @Reply(i32 %15, i32 0, i32 0)
br label %17
17: ; preds = %0, %112
%18 = getelementptr inbounds [23 x i8], [23 x i8]* %3, i64 0, i64 0
%19 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [23 x i8], [23 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [23 x i8], [23 x i8]* %3, i64 0, i64 0
%22 = call i32 @strLen(i8* %21)
%23 = call i32 @Write(i8* %20, i32 %22, i32 1)
%24 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%25 = call i32 @Read(i8* %24, i32 1)
%26 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%27 = call i64 @IsHalt(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %17
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 0, i8* %30
%31 = load i32, i32* %10
%32 = bitcast [4 x i8]* %4 to i8**
%33 = call i32 @Send(i32 %31, i8** %32, i32 4, i32 0, i32 0)
br label %112
34: ; preds = %17
%35 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%36 = call i64 @IsTrain(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %75
38: ; preds = %34
%39 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%40 = call i32 @len(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @getInt(i8* %39, i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%44 = call i32 @validTrainNum(i32 %42, i8* %43)
store i32 %44, i32* %6
%45 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%46 = call i32 @len(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%47 = call signext i8 @getSens(i8* %45, i32 %46)
store i8 %47, i8* %7
%48 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%49 = call i32 @len(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%50 = call signext i8 @getSens(i8* %48, i32 %49)
store i8 %50, i8* %8
%51 = load i32, i32* %6
%52 = icmp slt i32 %51, 0
br i1 %52, label %61, label %53
53: ; preds = %38
%54 = load i8, i8* %7
%55 = sext i8 %54 to i32
%56 = icmp slt i32 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i8, i8* %8
%59 = sext i8 %58 to i32
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %57, %53, %38
store i32 -5, i32* %6
br label %74
62: ; preds = %57
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 4, i8* %63
%64 = load i32, i32* %6
%65 = trunc i32 %64 to i8
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %65, i8* %66
%67 = load i8, i8* %7
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %67, i8* %68
%69 = load i8, i8* %8
%70 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 %69, i8* %70
%71 = load i32, i32* %10
%72 = bitcast [4 x i8]* %4 to i8**
%73 = call i32 @Send(i32 %71, i8** %72, i32 4, i32 0, i32 0)
br label %74
74: ; preds = %62, %61
br label %111
75: ; preds = %34
%76 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%77 = call i64 @IsRun(i8* %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %109
79: ; preds = %75
%80 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%81 = call i32 @len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%82 = call i32 @RunWhat(i8* %80, i32 %81)
store i32 %82, i32* %9
%83 = load i32, i32* %9
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %90
85: ; preds = %79
%86 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 1, i8* %86
%87 = load i32, i32* %10
%88 = bitcast [4 x i8]* %4 to i8**
%89 = call i32 @Send(i32 %87, i8** %88, i32 4, i32 0, i32 0)
br label %108
90: ; preds = %79
%91 = load i32, i32* %9
%92 = icmp eq i32 %91, 1
br i1 %92, label %93, label %98
93: ; preds = %90
%94 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 2, i8* %94
%95 = load i32, i32* %10
%96 = bitcast [4 x i8]* %4 to i8**
%97 = call i32 @Send(i32 %95, i8** %96, i32 4, i32 0, i32 0)
br label %107
98: ; preds = %90
%99 = load i32, i32* %9
%100 = icmp eq i32 %99, 2
br i1 %100, label %101, label %106
101: ; preds = %98
%102 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 3, i8* %102
%103 = load i32, i32* %10
%104 = bitcast [4 x i8]* %4 to i8**
%105 = call i32 @Send(i32 %103, i8** %104, i32 4, i32 0, i32 0)
br label %106
106: ; preds = %101, %98
br label %107
107: ; preds = %106, %93
br label %108
108: ; preds = %107, %85
br label %110
109: ; preds = %75
br label %110
110: ; preds = %109, %108
br label %111
111: ; preds = %110, %74
br label %112
112: ; preds = %111, %29
br label %17
}

LLVM IR (-O2):
@.str = [10 x i8] c"Tokenizer\00"
@.str.2 = [7 x i8] c"train \00"
@.str.3 = [13 x i8] c"train nn -s \00"
@.str.4 = [20 x i8] c"train nn -s nnn -e \00"
@.str.5 = [5 x i8] c"run \00"
define i32 @main() {
%1 = alloca [23 x i8]
%2 = alloca [23 x i8]
%3 = alloca [4 x i8]
%4 = alloca [6 x i8]
%5 = getelementptr inbounds [23 x i8], [23 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = tail call i32 @RegisterAs(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @Delay(i32 10)
%11 = bitcast [6 x i8]* %4 to i8**
%12 = call i32 @Receive(i8** %11, i32 6)
%13 = call i32 @Reply(i32 %12, i32 0, i32 0)
%14 = bitcast [23 x i8]* %2 to i32*
%15 = bitcast [4 x i8]* %3 to i8**
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
br label %19
19: ; preds = %55, %0
store i32 2106378, i32* %14
%20 = call i32 @strLen(i8* %6)
%21 = call i32 @Write(i8* %6, i32 %20, i32 1)
%22 = call i32 @Read(i8* %5, i32 1)
%23 = call i64 @IsHalt(i8* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %19
store i8 0, i8* %7
br label %53
26: ; preds = %19
%27 = call i64 @IsTrain(i8* %5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %44, label %29
29: ; preds = %26
%30 = call i32 @len(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @getInt(i8* %5, i32 %30)
%32 = call i32 @validTrainNum(i32 %31, i8* %8)
%33 = call i32 @len(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%34 = call signext i8 @getSens(i8* %5, i32 %33)
%35 = call i32 @len(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%36 = call signext i8 @getSens(i8* %5, i32 %35)
%37 = icmp slt i32 %32, 0
%38 = icmp slt i8 %34, 0
%39 = select i1 %37, i1 true, i1 %38
%40 = icmp slt i8 %36, 0
%41 = select i1 %39, i1 true, i1 %40
br i1 %41, label %55, label %42
42: ; preds = %29
store i8 4, i8* %7
%43 = trunc i32 %32 to i8
store i8 %43, i8* %16
store i8 %34, i8* %17
store i8 %36, i8* %18
br label %53
44: ; preds = %26
%45 = call i64 @IsRun(i8* %5)
%46 = icmp eq i64 %45, 0
br i1 %46, label %55, label %47
47: ; preds = %44
%48 = call i32 @len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 @RunWhat(i8* %5, i32 %48)
switch i32 %49, label %55 [
i32 0, label %50
i32 1, label %51
i32 2, label %52
]
50: ; preds = %47
store i8 1, i8* %7
br label %53
51: ; preds = %47
store i8 2, i8* %7
br label %53
52: ; preds = %47
store i8 3, i8* %7
br label %53
53: ; preds = %25, %51, %52, %50, %42
%54 = call i32 @Send(i32 %12, i8** %15, i32 4, i32 0, i32 0)
br label %55
55: ; preds = %53, %47, %29, %44
br label %19
}