#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*/ words;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
scalar_t__ get_words(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strrev(char *);
int /*<<< orphan*/ write(int, ...);
void child_process(int *out, int *in) {
  int words = 0, fd, bytes_read = 0, current_line, position;
  char command[200], filename[200], line[200], c;
  close(in[1]);
  close(out[0]);
  read(in[0], command, 200);
  if (!strcmp(command, "show")) {
    do {
      read(in[0], &command, 200);
      words += get_words(command);
    } while (!strcmp(command, "EOF"));
    words -= 1;
    write(out[1], &words, sizeof(words));
  } else if (!strcmp(command, "trim")) {
    read(in[0], &filename, 200);
    printf("file: %s", filename);
    fd = open(filename, O_RDONLY);
    lseek(fd, 0, SEEK_END);
    while (current_line < 10) {
      position = 0;
      do {
        lseek(fd, -2, SEEK_CUR);
        read(fd, &c, 1);
        line[position] = c;
        position += 1;
      } while (c != '\n');
      line[position] = '\0';
      current_line += 1;
      strrev(line);
      write(out[1], line, 200);
    }
  }
}


x86 assembly (clang, -O0):
<child_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0xf0(%rbp),%rsi
mov    $0xc8,%edx
mov    $0x0,%al
call   1080 <read@plt>
lea    -0xf0(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    127c <child_process+0xec>
jmp    1202 <child_process+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0xf0(%rbp),%rsi
mov    $0xc8,%edx
mov    $0x0,%al
call   1080 <read@plt>
lea    -0xf0(%rbp),%rdi
call   1040 <get_words@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
lea    -0xf0(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1202 <child_process+0x72>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    13a0 <child_process+0x210>
lea    -0xf0(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    139b <child_process+0x20b>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x1c0(%rbp),%rsi
mov    $0xc8,%edx
mov    $0x0,%al
call   1080 <read@plt>
lea    -0x1c0(%rbp),%rsi
lea    0xd4f(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1c0(%rbp),%rdi
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d02(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
cmpl   $0xa,-0x20(%rbp)
jge    1396 <child_process+0x206>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2cd6(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1060 <lseek@plt>
mov    -0x18(%rbp),%edi
lea    -0x291(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1080 <read@plt>
mov    -0x291(%rbp),%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x290(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x291(%rbp),%eax
cmp    $0xa,%eax
jne    1300 <child_process+0x170>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x290(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
lea    -0x290(%rbp),%rdi
call   10a0 <strrev@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x290(%rbp),%rsi
mov    $0xc8,%edx
mov    $0x0,%al
call   1030 <write@plt>
jmp    12ef <child_process+0x15f>
jmp    139b <child_process+0x20b>
jmp    13a0 <child_process+0x210>
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_process>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x198,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x4(%rsi),%edi
call   1070 <close@plt>
mov    (%r14),%edi
call   1070 <close@plt>
mov    (%r15),%edi
mov    %rsp,%rsi
mov    $0xc8,%edx
xor    %eax,%eax
call   1080 <read@plt>
mov    $0x776f6873,%eax
xor    (%rsp),%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
je     1219 <child_process+0xa9>
mov    $0x6d697274,%eax
xor    (%rsp),%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
jne    1267 <child_process+0xf7>
mov    (%r15),%edi
lea    0xd0(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xc8,%edx
xor    %eax,%eax
call   1080 <read@plt>
lea    0xe1e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    0x2ddc(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
jmp    1267 <child_process+0xf7>
mov    %rsp,%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0xc8,%edx
xor    %eax,%eax
call   1080 <read@plt>
mov    %rbx,%rdi
call   1040 <get_words@plt>
add    %eax,%ebp
cmpl   $0x464f45,(%rsp)
je     1220 <child_process+0xb0>
add    $0xffffffff,%ebp
mov    %ebp,0xd0(%rsp)
mov    0x4(%r14),%edi
lea    0xd0(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <write@plt>
add    $0x198,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"show\00"
@.str.1 = [4 x i8] c"EOF\00"
@.str.2 = [5 x i8] c"trim\00"
@.str.3 = [9 x i8] c"file: %s\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_CUR = global i32 0
define void @child_process(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [200 x i8]
%11 = alloca [200 x i8]
%12 = alloca [200 x i8]
%13 = alloca i8
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 0, i32* %7
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%26 = call i32 (i32, ...) @read(i32 %24, i8* %25, i32 200)
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %54, label %30
30: ; preds = %2
br label %31
31: ; preds = %42, %30
%32 = load i32*, i32** %4
%33 = getelementptr inbounds i32, i32* %32, i64 0
%34 = load i32, i32* %33
%35 = call i32 (i32, ...) @read(i32 %34, [200 x i8]* %10, i32 200)
%36 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%37 = call i64 @get_words(i8* %36)
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = add nsw i64 %39, %37
%41 = trunc i64 %40 to i32
store i32 %41, i32* %5
br label %42
42: ; preds = %31
%43 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
br i1 %46, label %31, label %47
47: ; preds = %42
%48 = load i32, i32* %5
%49 = sub nsw i32 %48, 1
store i32 %49, i32* %5
%50 = load i32*, i32** %3
%51 = getelementptr inbounds i32, i32* %50, i64 1
%52 = load i32, i32* %51
%53 = call i32 (i32, ...) @write(i32 %52, i32* %5, i64 4)
br label %106
54: ; preds = %2
%55 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%56 = call i32 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %105, label %58
58: ; preds = %54
%59 = load i32*, i32** %4
%60 = getelementptr inbounds i32, i32* %59, i64 0
%61 = load i32, i32* %60
%62 = call i32 (i32, ...) @read(i32 %61, [200 x i8]* %11, i32 200)
%63 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %63)
%65 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%66 = load i32, i32* @O_RDONLY
%67 = call i32 @open(i8* %65, i32 %66)
store i32 %67, i32* %6
%68 = load i32, i32* %6
%69 = load i32, i32* @SEEK_END
%70 = call i32 @lseek(i32 %68, i32 0, i32 %69)
br label %71
71: ; preds = %91, %58
%72 = load i32, i32* %8
%73 = icmp slt i32 %72, 10
br i1 %73, label %74, label %104
74: ; preds = %71
store i32 0, i32* %9
br label %75
75: ; preds = %87, %74
%76 = load i32, i32* %6
%77 = load i32, i32* @SEEK_CUR
%78 = call i32 @lseek(i32 %76, i32 -2, i32 %77)
%79 = load i32, i32* %6
%80 = call i32 (i32, ...) @read(i32 %79, i8* %13, i32 1)
%81 = load i8, i8* %13
%82 = load i32, i32* %9
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 %83
store i8 %81, i8* %84
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
br label %87
87: ; preds = %75
%88 = load i8, i8* %13
%89 = sext i8 %88 to i32
%90 = icmp ne i32 %89, 10
br i1 %90, label %75, label %91
91: ; preds = %87
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 %93
store i8 0, i8* %94
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
store i32 %96, i32* %8
%97 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%98 = call i32 @strrev(i8* %97)
%99 = load i32*, i32** %3
%100 = getelementptr inbounds i32, i32* %99, i64 1
%101 = load i32, i32* %100
%102 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%103 = call i32 (i32, ...) @write(i32 %101, i8* %102, i32 200)
br label %71
104: ; preds = %71
br label %105
105: ; preds = %104, %54
br label %106
106: ; preds = %105, %47
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"show\00"
@.str.2 = [5 x i8] c"trim\00"
@.str.3 = [9 x i8] c"file: %s\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_CUR = global i32 0
define void @child_process(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = alloca [200 x i8]
%5 = alloca [200 x i8]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds i32, i32* %1, i64 1
%10 = load i32, i32* %9
%11 = tail call i32 @close(i32 %10)
%12 = load i32, i32* %0
%13 = tail call i32 @close(i32 %12)
%14 = load i32, i32* %1
%15 = call i32 (i32, ...) @read(i32 %14, i8* %7, i32 200)
%16 = call i32 @bcmp(i8* dereferenceable(5) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %2
%19 = bitcast [200 x i8]* %4 to i32*
br label %20
20: ; preds = %18, %20
%21 = phi i32 [ 0, %18 ], [ %26, %20 ]
%22 = load i32, i32* %1
%23 = call i32 (i32, ...) @read(i32 %22, [200 x i8]* %4, i32 200)
%24 = call i64 @get_words(i8* %7)
%25 = trunc i64 %24 to i32
%26 = add i32 %21, %25
%27 = load i32, i32* %19
%28 = icmp eq i32 %27, 4607813
br i1 %28, label %20, label %29
29: ; preds = %20
%30 = add nsw i32 %26, -1
store i32 %30, i32* %3
%31 = getelementptr inbounds i32, i32* %0, i64 1
%32 = load i32, i32* %31
%33 = call i32 (i32, ...) @write(i32 %32, i32* %3, i64 4)
br label %45
34: ; preds = %2
%35 = call i32 @bcmp(i8* dereferenceable(5) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i32, i32* %1
%39 = call i32 (i32, ...) @read(i32 %38, [200 x i8]* %5, i32 200)
%40 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%41 = load i32, i32* @O_RDONLY
%42 = call i32 @open(i8* %8, i32 %41)
%43 = load i32, i32* @SEEK_END
%44 = call i32 @lseek(i32 %42, i32 0, i32 %43)
br label %45
45: ; preds = %37, %34, %29
ret void
}