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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(void) {
  int fd[2];
  pid_t pid;
  pipe(fd);
  if ((pid = fork()) == 0) {
    close(fd[1]);
    dup2(fd[0], STDIN_FILENO);
    execlp("sort", "sort", 0);
  } else {
    FILE *stream;
    close(fd[0]);
    stream = fdopen(fd[1], "w");
    fprintf(stream, "BBBBBBBBBBBB\n");
    fprintf(stream, "FFFFFFFFFFFF\n");
    fprintf(stream, "AAAAAAAAAAAA\n");
    fprintf(stream, "CCCCCCCCCCCC\n");
    fprintf(stream, "DDDDDDDDDDDD\n");
    fprintf(stream, "EEEEEEEEEEEE\n");
    fflush(stream);
    close(fd[1]);
    waitpid(pid, NULL, 0);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    11ea <main+0x5a>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xe25(%rip),%rsi
xor    %edx,%edx
mov    %rsi,%rdi
call   10a0 <execlp@plt>
jmp    1284 <main+0xf4>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
lea    0xe09(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     127b <main+0xeb>
mov    %eax,%ebp
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
lea    0xe46(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,%rbx
lea    0xe39(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0xe2e(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xe23(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xe18(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xe0d(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xe02(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <waitpid@plt>
jmp    12a6 <main+0x116>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
lea    0xd64(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10a0 <execlp@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [5 x i8] c"sort\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"BBBBBBBBBBBB\0A\00"
@.str.3 = [14 x i8] c"FFFFFFFFFFFF\0A\00"
@.str.4 = [14 x i8] c"AAAAAAAAAAAA\0A\00"
@.str.5 = [14 x i8] c"CCCCCCCCCCCC\0A\00"
@.str.6 = [14 x i8] c"DDDDDDDDDDDD\0A\00"
@.str.7 = [14 x i8] c"EEEEEEEEEEEE\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
store i32 %7, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%11 = load i32, i32* %10
%12 = call i32 @close(i32 %11)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%14 = load i32, i32* %13
%15 = load i32, i32* @STDIN_FILENO
%16 = call i32 @dup2(i32 %14, i32 %15)
%17 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
br label %44
18: ; preds = %0
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%20 = load i32, i32* %19
%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 = call i32* @fdopen(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %4
%25 = load i32*, i32** %4
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32*, i32** %4
%28 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32*, i32** %4
%30 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32*, i32** %4
%32 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32*, i32** %4
%34 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%35 = load i32*, i32** %4
%36 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%37 = load i32*, i32** %4
%38 = call i32 @fflush(i32* %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %3
%43 = call i32 @waitpid(i32 %42, i32* null, i32 0)
br label %44
44: ; preds = %18, %9
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [5 x i8] c"sort\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"BBBBBBBBBBBB\0A\00"
@.str.3 = [14 x i8] c"FFFFFFFFFFFF\0A\00"
@.str.4 = [14 x i8] c"AAAAAAAAAAAA\0A\00"
@.str.5 = [14 x i8] c"CCCCCCCCCCCC\0A\00"
@.str.6 = [14 x i8] c"DDDDDDDDDDDD\0A\00"
@.str.7 = [14 x i8] c"EEEEEEEEEEEE\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%9 = load i32, i32* %8
%10 = call i32 @close(i32 %9)
%11 = load i32, i32* %3
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @dup2(i32 %11, i32 %12)
%14 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0)
br label %31
15: ; preds = %0
%16 = load i32, i32* %3
%17 = call i32 @close(i32 %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32* @fdopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 13, i64 1, i32* %20)
%22 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 13, i64 1, i32* %20)
%23 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i64 13, i64 1, i32* %20)
%24 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 13, i64 1, i32* %20)
%25 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 13, i64 1, i32* %20)
%26 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i64 13, i64 1, i32* %20)
%27 = call i32 @fflush(i32* %20)
%28 = load i32, i32* %18
%29 = call i32 @close(i32 %28)
%30 = call i32 @waitpid(i32 %5, i32* null, i32 0)
br label %31
31: ; preds = %15, %7
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}