#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 */
typedef int /*<<< orphan*/ currentCommand;
typedef int /*<<< orphan*/ commandBuffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int S_IFIFO;
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  FILE *file = fopen("commands.txt", "r");
  if (argv[1] != NULL) {
    mknod(argv[1], S_IFIFO | 0600, 0);
  }
  int currentLineNumber = 0;
  char commandBuffer[10000];
  memset(commandBuffer, 0, sizeof(commandBuffer));
  while (1) {
    char currentCommand[200];
    memset(currentCommand, 0, sizeof(currentCommand));
    if (fgets(currentCommand, sizeof(currentCommand), file) != NULL) {
      currentCommand[strlen(currentCommand) - 1] = 0;
      if (argv[1] == NULL)
        strcat(commandBuffer, currentCommand);
    } else {
      if (argv[1] == NULL) {
        commandBuffer[strlen(commandBuffer) - 1] = 0;
        commandBuffer[strlen(commandBuffer) - 2] = 0;
        printf("%s\n", commandBuffer);
        system(commandBuffer);
      }
      break;
    }
    if (argv[1] != NULL) {
      if (currentLineNumber % 2 == 0) {
        execl(currentCommand, ">>", "/tmp/", argv[1], (char *)NULL);
      } else {
        execl(currentCommand, "<<", "/tmp/", argv[1], NULL);
      }
      currentLineNumber++;
    } else {
      strcat(commandBuffer, " | ");
    }
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2800,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rdi
lea    0xe46(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11fd <main+0x5d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
or     $0x180,%esi
xor    %edx,%edx
call   1090 <mknod@plt>
movl   $0x0,-0x1c(%rbp)
lea    -0x2730(%rbp),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
call   1070 <memset@plt>
lea    -0x2800(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1070 <memset@plt>
lea    -0x2800(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xc8,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1289 <main+0xe9>
lea    -0x2800(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x2800(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1284 <main+0xe4>
lea    -0x2730(%rbp),%rdi
lea    -0x2800(%rbp),%rsi
call   10b0 <strcat@plt>
jmp    12ee <main+0x14e>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    12e9 <main+0x149>
lea    -0x2730(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x2,%eax
cltq
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rsi
lea    0xd37(%rip),%rdi
call   1060 <printf@plt>
lea    -0x2730(%rbp),%rdi
call   1050 <system@plt>
jmp    138a <main+0x1ea>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1372 <main+0x1d2>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    133d <main+0x19d>
lea    -0x2800(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xcec(%rip),%rsi
lea    0xce8(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <execl@plt>
jmp    1364 <main+0x1c4>
lea    -0x2800(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xcc9(%rip),%rsi
lea    0xcbc(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10c0 <execl@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1385 <main+0x1e5>
lea    -0x2730(%rbp),%rdi
lea    0xc9f(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1217 <main+0x77>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x2800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x27e8,%rsp
mov    %rsi,%r12
lea    0xe45(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    0x8(%r12),%rdi
test   %rdi,%rdi
je     11e9 <main+0x49>
mov    0x2e05(%rip),%rax
mov    $0x180,%esi
or     (%rax),%esi
xor    %edx,%edx
call   1090 <mknod@plt>
lea    0xd0(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x2710,%edx
call   1070 <memset@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12d0 <main+0x130>
lea    0xdeb(%rip),%r13
lea    0xdde(%rip),%r15
jmp    1287 <main+0xe7>
nopw   0x0(%rax,%rax,1)
test   $0x1,%bpl
mov    %r13,%rsi
lea    0xdc5(%rip),%rax
cmove  %rax,%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %r8d,%r8d
call   10c0 <execl@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12d0 <main+0x130>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    0x8(%r12),%rcx
test   %rcx,%rcx
jne    1240 <main+0xa0>
lea    0xd0(%rsp),%rdi
mov    %rbx,%rsi
call   10b0 <strcat@plt>
mov    0x8(%r12),%rcx
test   %rcx,%rcx
jne    1240 <main+0xa0>
lea    0xd0(%rsp),%rdi
lea    0xd56(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1263 <main+0xc3>
cmpq   $0x0,0x8(%r12)
jne    1315 <main+0x175>
lea    0xd0(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%rbx,1)
lea    0xd0a(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x27e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"commands.txt\00"
@.str.1 = [2 x i8] c"r\00"
@S_IFIFO = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c">>\00"
@.str.4 = [6 x i8] c"/tmp/\00"
@.str.5 = [3 x i8] c"<<\00"
@.str.6 = [4 x i8] c" | \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [10000 x i8]
%9 = alloca [200 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @S_IFIFO
%20 = or i32 %19, 384
%21 = call i32 @mknod(i8* %18, i32 %20, i32 0)
br label %22
22: ; preds = %15, %2
store i32 0, i32* %7
%23 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 0, i32 10000)
br label %25
25: ; preds = %22, %95
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 200)
%28 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%29 = load i32*, i32** %6
%30 = call i32* @fgets(i8* %28, i32 200, i32* %29)
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %47
32: ; preds = %25
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %46
42: ; preds = %32
%43 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%45 = call i32 @strcat(i8* %43, i8* %44)
br label %46
46: ; preds = %42, %32
br label %68
47: ; preds = %25
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %67
52: ; preds = %47
%53 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%54 = call i32 @strlen(i8* %53)
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 %56
store i8 0, i8* %57
%58 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%59 = call i32 @strlen(i8* %58)
%60 = sub nsw i32 %59, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 %61
store i8 0, i8* %62
%63 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %63)
%65 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%66 = call i32 @system(i8* %65)
br label %67
67: ; preds = %52, %47
br label %96
68: ; preds = %46
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 1
%71 = load i8*, i8** %70
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %92
73: ; preds = %68
%74 = load i32, i32* %7
%75 = srem i32 %74, 2
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %83
77: ; preds = %73
%78 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 @execl(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %81, i8* null)
br label %89
83: ; preds = %73
%84 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = call i32 @execl(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %87, i8* null)
br label %89
89: ; preds = %83, %77
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %95
92: ; preds = %68
%93 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%94 = call i32 @strcat(i8* %93, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %95
95: ; preds = %92, %89
br label %25
96: ; preds = %67
%97 = load i32*, i32** %6
%98 = call i32 @fclose(i32* %97)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"commands.txt\00"
@.str.1 = [2 x i8] c"r\00"
@S_IFIFO = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c">>\00"
@.str.4 = [6 x i8] c"/tmp/\00"
@.str.5 = [3 x i8] c"<<\00"
@.str.6 = [4 x i8] c" | \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10000 x i8]
%4 = alloca [200 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @S_IFIFO
%11 = or i32 %10, 384
%12 = tail call i32 @mknod(i8* %7, i32 %11, i32 0)
br label %13
13: ; preds = %9, %2
%14 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 10000)
%16 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 200)
%18 = call i32* @fgets(i8* %16, i32 200, i32* %5)
%19 = icmp eq i32* %18, null
br i1 %19, label %28, label %20
20: ; preds = %13, %55
%21 = phi i32 [ %56, %55 ], [ 0, %13 ]
%22 = call i32 @strlen(i8* %16)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %6
%27 = icmp eq i8* %26, null
br i1 %27, label %42, label %46
28: ; preds = %55, %13
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %60
31: ; preds = %28
%32 = call i32 @strlen(i8* %14)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i32 @strlen(i8* %14)
%37 = add nsw i32 %36, -2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%41 = call i32 @system(i8* %14)
br label %60
42: ; preds = %20
%43 = call i32 @strcat(i8* %14, i8* %16)
%44 = load i8*, i8** %6
%45 = icmp eq i8* %44, null
br i1 %45, label %53, label %46
46: ; preds = %20, %42
%47 = phi i8* [ %44, %42 ], [ %26, %20 ]
%48 = and i32 %21, 1
%49 = icmp eq i32 %48, 0
%50 = select i1 %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%51 = call i32 @execl(i8* %16, i8* %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %47, i8* null)
%52 = add nsw i32 %21, 1
br label %55
53: ; preds = %42
%54 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %55
55: ; preds = %46, %53
%56 = phi i32 [ %52, %46 ], [ %21, %53 ]
%57 = call i32 @memset(i8* %16, i32 0, i32 200)
%58 = call i32* @fgets(i8* %16, i32 200, i32* %5)
%59 = icmp eq i32* %58, null
br i1 %59, label %28, label %20
60: ; preds = %31, %28
%61 = call i32 @fclose(i32* %5)
ret i32 0
}