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

/* Variables and functions */
int /*<<< orphan*/ EOF;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int pp2c[2];
  int pc2p[2];
  pipe(pp2c);
  pipe(pc2p);
  switch (fork()) {
  case -1:
    break;
  case 0:
    close(pp2c[1]);
    dup2(pp2c[0], STDIN_FILENO);
    close(pp2c[0]);
    close(pc2p[0]);
    dup2(pc2p[1], STDOUT_FILENO);
    close(pc2p[1]);
    execlp("rev", "rev", (char *)NULL);
    perror("exec failed");
    exit(127);
    break;
  default:
    close(pp2c[0]);
    close(pc2p[1]);
    FILE *out = fdopen(pp2c[1], "w");
    FILE *in = fdopen(pc2p[0], "r");
    char word[1024];
    while (scanf("%s", word) != EOF) {
      fprintf(out, "%s\n", word);
    }
    fclose(out);
    while (fscanf(in, "%s", word) != EOF) {
      printf("%s\n", word);
    }
    fclose(in);
    wait(NULL);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1080 <pipe@plt>
lea    -0x14(%rbp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   1100 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x434(%rbp)
sub    $0xffffffff,%eax
je     1234 <main+0x54>
jmp    1221 <main+0x41>
mov    -0x434(%rbp),%eax
test   %eax,%eax
je     1239 <main+0x59>
jmp    12a4 <main+0xc4>
jmp    1371 <main+0x191>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   10e0 <execlp@plt>
lea    0xd6f(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x7f,%edi
call   10d0 <exit@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%edi
lea    0xd52(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    0xd41(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x430(%rbp),%rsi
lea    0xd2c(%rip),%rdi
call   10b0 <scanf@plt>
mov    0x2cec(%rip),%rcx
cmp    (%rcx),%eax
je     1318 <main+0x138>
mov    -0x20(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    0xd09(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12da <main+0xfa>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    0xce1(%rip),%rsi
call   1060 <fscanf@plt>
mov    0x2ca1(%rip),%rcx
cmp    (%rcx),%eax
je     135f <main+0x17f>
lea    -0x430(%rbp),%rsi
lea    0xcc2(%rip),%rdi
call   1050 <printf@plt>
jmp    1321 <main+0x141>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <wait@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
mov    %rsp,%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     131d <main+0x13d>
test   %eax,%eax
je     1331 <main+0x151>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
lea    0xdd8(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,%r12
mov    (%rsp),%edi
lea    0xdc8(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,%r14
lea    0xdbb(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0x2d76(%rip),%rbp
cmp    0x0(%rbp),%eax
je     12ae <main+0xce>
lea    0xda1(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xd92(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
cmp    0x0(%rbp),%eax
jne    1290 <main+0xb0>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xd57(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1060 <fscanf@plt>
cmp    0x0(%rbp),%eax
je     130e <main+0x12e>
lea    0xd41(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xd32(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
cmp    0x0(%rbp),%eax
jne    12f0 <main+0x110>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   10f0 <wait@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
mov    0x2c8b(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    (%rsp),%edi
call   1070 <close@plt>
mov    0x4(%rsp),%edi
mov    0x2c88(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
lea    0xc81(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10e0 <execlp@plt>
lea    0xc74(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x7f,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [4 x i8] c"rev\00"
@.str.1 = [12 x i8] c"exec failed\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i32 0
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [1024 x i8]
store i32 0, i32* %1
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i32 (...) @fork()
switch i32 %11, label %37 [
i32 -1, label %12
i32 0, label %13
]
12: ; preds = %0
br label %75
13: ; preds = %0
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%18 = load i32, i32* %17
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @dup2(i32 %18, i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%28 = load i32, i32* %27
%29 = load i32, i32* @STDOUT_FILENO
%30 = call i32 @dup2(i32 %28, i32 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* null)
%35 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 127)
unreachable
37: ; preds = %0
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32* @fdopen(i32 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %46, i32** %4
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%48 = load i32, i32* %47
%49 = call i32* @fdopen(i32 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %49, i32** %5
br label %50
50: ; preds = %55, %37
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EOF
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load i32*, i32** %4
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%58 = call i32 @fprintf(i32* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %57)
br label %50
59: ; preds = %50
%60 = load i32*, i32** %4
%61 = call i32 @fclose(i32* %60)
br label %62
62: ; preds = %68, %59
%63 = load i32*, i32** %5
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%65 = call i32 @fscanf(i32* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @EOF
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %69)
br label %62
71: ; preds = %62
%72 = load i32*, i32** %5
%73 = call i32 @fclose(i32* %72)
%74 = call i32 @wait(i32* null)
br label %75
75: ; preds = %71, %12
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [4 x i8] c"rev\00"
@.str.1 = [12 x i8] c"exec failed\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i32 0
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [1024 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast [2 x i32]* %2 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
switch i32 %10, label %31 [
i32 -1, label %64
i32 0, label %11
]
11: ; preds = %0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* %6
%16 = load i32, i32* @STDIN_FILENO
%17 = call i32 @dup2(i32 %15, i32 %16)
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %8
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = load i32, i32* @STDOUT_FILENO
%25 = call i32 @dup2(i32 %23, i32 %24)
%26 = load i32, i32* %22
%27 = call i32 @close(i32 %26)
%28 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* null)
%29 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 127)
unreachable
31: ; preds = %0
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32* @fdopen(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* %8
%41 = call i32* @fdopen(i32 %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %51, label %46
46: ; preds = %31, %46
%47 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%49 = load i32, i32* @EOF
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %46
51: ; preds = %46, %31
%52 = call i32 @fclose(i32* %39)
%53 = call i32 @fscanf(i32* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%54 = load i32, i32* @EOF
%55 = icmp eq i32 %53, %54
br i1 %55, label %61, label %56
56: ; preds = %51, %56
%57 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%58 = call i32 @fscanf(i32* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%59 = load i32, i32* @EOF
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %56
61: ; preds = %56, %51
%62 = call i32 @fclose(i32* %41)
%63 = call i32 @wait(i32* null)
br label %64
64: ; preds = %61, %0
ret i32 0
}