#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*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
char *realloc(char *, size_t);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  signal(SIGCHLD, SIG_IGN);
  int input_fd[2];
  int output_fd[2];
  int pid;
  int status;
  if (pipe(input_fd) < 0 || pipe(output_fd) < 0) {
    perror("pipe");
  }
  pid = fork();
  if (pid < 0) {
    perror("fork");
  } else if (pid == 0) {
    dup2(output_fd[1], STDOUT_FILENO);
    dup2(input_fd[0], STDIN_FILENO);
    close(output_fd[0]);
    close(input_fd[1]);
    execl("folder/color.cgi", "folder/color.cgi", NULL);
    perror("execl");
    exit(-1);
  } else {
    char strbuf[4096];
    int sz;
    char *output_buffer = NULL;
    size_t output_size = 0;
    close(output_fd[1]);
    close(input_fd[0]);
    memset(strbuf, 0, 4096);
    while ((sz = read(output_fd[0], strbuf, 4096)) != 0) {
      if (sz < 0) {
        perror("read");
      }
      output_buffer = realloc(output_buffer, output_size + sz);
      memcpy(output_buffer + output_size, strbuf, sz);
      output_size += sz;
      memset(strbuf, 0, 4096);
    }
    close(output_fd[0]);
    close(input_fd[1]);
    printf("EXECL: %s\n", output_buffer);
    free(output_buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
lea    -0xc(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jl     122f <main+0x4f>
lea    -0x14(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jge    123b <main+0x5b>
lea    0xdca(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1260 <main+0x80>
lea    0xdaf(%rip),%rdi
call   10d0 <perror@plt>
jmp    13df <main+0x1ff>
cmpl   $0x0,-0x18(%rbp)
jne    12c5 <main+0xe5>
mov    -0x10(%rbp),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0xc(%rbp),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
lea    0xd67(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   10f0 <execl@plt>
lea    0xd65(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
movq   $0x0,-0x1030(%rbp)
movq   $0x0,-0x1038(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %eax,-0x1024(%rbp)
cmp    $0x0,%eax
je     13ab <main+0x1cb>
cmpl   $0x0,-0x1024(%rbp)
jge    133a <main+0x15a>
lea    0xcec(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x1030(%rbp),%rdi
mov    -0x1038(%rbp),%rsi
movslq -0x1024(%rbp),%rax
add    %rax,%rsi
call   10c0 <realloc@plt>
mov    %rax,-0x1030(%rbp)
mov    -0x1030(%rbp),%rdi
add    -0x1038(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1024(%rbp),%edx
call   10b0 <memcpy@plt>
movslq -0x1024(%rbp),%rax
add    -0x1038(%rbp),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
jmp    12fe <main+0x11e>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x1030(%rbp),%rsi
lea    0xc5d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1030(%rbp),%rdi
call   1030 <free@plt>
jmp    13df <main+0x1ff>
xor    %eax,%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
test   %rax,%rax
js     1336 <main+0x156>
mov    %rsp,%rdi
call   1080 <pipe@plt>
test   %rax,%rax
js     1336 <main+0x156>
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
js     1347 <main+0x167>
je     1355 <main+0x175>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
lea    0x10(%rsp),%rbx
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    (%rsp),%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
test   %eax,%eax
je     12fa <main+0x11a>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0xd98(%rip),%r14
lea    0x10(%rsp),%r15
xor    %r12d,%r12d
jmp    12ec <main+0x10c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebp,%r13
add    %rbx,%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   10c0 <realloc@plt>
mov    %rax,%r12
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   10b0 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    (%rsp),%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %eax,%ebp
mov    %r13,%rbx
test   %eax,%eax
je     12fa <main+0x11a>
test   %ebp,%ebp
jns    12a0 <main+0xc0>
mov    %r14,%rdi
call   10d0 <perror@plt>
jmp    12a0 <main+0xc0>
mov    (%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
lea    0xd14(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc3(%rip),%rdi
call   10d0 <perror@plt>
jmp    122c <main+0x4c>
lea    0xcb7(%rip),%rdi
call   10d0 <perror@plt>
jmp    1322 <main+0x142>
mov    0x4(%rsp),%edi
mov    0x2c90(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x8(%rsp),%edi
mov    0x2c56(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    (%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
lea    0xc79(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10f0 <execl@plt>
lea    0xc79(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.2 = [17 x i8] c"folder/color.cgi\00"
@.str.3 = [6 x i8] c"execl\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [11 x i8] c"EXECL: %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 [4096 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %1
%10 = load i32, i32* @SIGCHLD
%11 = load i32, i32* @SIG_IGN
%12 = call i32 @signal(i32 %10, i32 %11)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%14 = call i64 @pipe(i32* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %0
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%18 = call i64 @pipe(i32* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16, %0
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = call i32 (...) @fork()
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %100
28: ; preds = %22
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %49
31: ; preds = %28
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%33 = load i32, i32* %32
%34 = load i32, i32* @STDOUT_FILENO
%35 = call i32 @dup2(i32 %33, i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%37 = load i32, i32* %36
%38 = load i32, i32* @STDIN_FILENO
%39 = call i32 @dup2(i32 %37, i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
%46 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* null)
%47 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %28
store i8* null, i8** %8
store i64 0, i64* %9
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i32 0, i32 4096)
br label %58
58: ; preds = %69, %49
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%60 = load i32, i32* %59
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%62 = call i32 @read(i32 %60, i8* %61, i32 4096)
store i32 %62, i32* %7
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %88
64: ; preds = %58
%65 = load i32, i32* %7
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = load i8*, i8** %8
%71 = load i64, i64* %9
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = add i64 %71, %73
%75 = call i8* @realloc(i8* %70, i64 %74)
store i8* %75, i8** %8
%76 = load i8*, i8** %8
%77 = load i64, i64* %9
%78 = getelementptr inbounds i8, i8* %76, i64 %77
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%80 = load i32, i32* %7
%81 = call i32 @memcpy(i8* %78, i8* %79, i32 %80)
%82 = load i32, i32* %7
%83 = sext i32 %82 to i64
%84 = load i64, i64* %9
%85 = add i64 %84, %83
store i64 %85, i64* %9
%86 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%87 = call i32 @memset(i8* %86, i32 0, i32 4096)
br label %58
88: ; preds = %58
%89 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%90 = load i32, i32* %89
%91 = call i32 @close(i32 %90)
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%93 = load i32, i32* %92
%94 = call i32 @close(i32 %93)
%95 = load i8*, i8** %8
%96 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %95)
%97 = load i8*, i8** %8
%98 = call i32 @free(i8* %97)
br label %99
99: ; preds = %88
br label %100
100: ; preds = %99, %26
ret i32 0
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.2 = [17 x i8] c"folder/color.cgi\00"
@.str.3 = [6 x i8] c"execl\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [11 x i8] c"EXECL: %s\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [4096 x i8]
%4 = load i32, i32* @SIGCHLD
%5 = load i32, i32* @SIG_IGN
%6 = tail call i32 @signal(i32 %4, i32 %5)
%7 = bitcast [2 x i32]* %1 to i8*
%8 = bitcast [2 x i32]* %2 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%14 = call i64 @pipe(i32* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12, %0
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = call i32 (...) @fork()
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %80
23: ; preds = %18
%24 = icmp eq i32 %19, 0
br i1 %24, label %25, label %42
25: ; preds = %23
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%27 = load i32, i32* %26
%28 = load i32, i32* @STDOUT_FILENO
%29 = call i32 @dup2(i32 %27, i32 %28)
%30 = load i32, i32* %9
%31 = load i32, i32* @STDIN_FILENO
%32 = call i32 @dup2(i32 %30, i32 %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* null)
%40 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %23
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* %9
%48 = call i32 @close(i32 %47)
%49 = call i32 @memset(i8* %43, i32 0, i32 4096)
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%51 = load i32, i32* %50
%52 = call i32 @read(i32 %51, i8* %43, i32 4096)
%53 = icmp eq i32 %52, 0
br i1 %53, label %71, label %54
54: ; preds = %42, %61
%55 = phi i32 [ %69, %61 ], [ %52, %42 ]
%56 = phi i64 [ %63, %61 ], [ 0, %42 ]
%57 = phi i8* [ %64, %61 ], [ null, %42 ]
%58 = icmp slt i32 %55, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %54
%62 = sext i32 %55 to i64
%63 = add i64 %56, %62
%64 = call i8* @realloc(i8* %57, i64 %63)
%65 = getelementptr inbounds i8, i8* %64, i64 %56
%66 = call i32 @memcpy(i8* %65, i8* %43, i32 %55)
%67 = call i32 @memset(i8* %43, i32 0, i32 4096)
%68 = load i32, i32* %50
%69 = call i32 @read(i32 %68, i8* %43, i32 4096)
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %54
71: ; preds = %61, %42
%72 = phi i8* [ null, %42 ], [ %64, %61 ]
%73 = load i32, i32* %50
%74 = call i32 @close(i32 %73)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%76 = load i32, i32* %75
%77 = call i32 @close(i32 %76)
%78 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %72)
%79 = call i32 @free(i8* %72)
br label %80
80: ; preds = %71, %21
ret i32 0
}