#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(void) {
  int input_fd[2];
  int output_fd[2];
  int status;
  int pid;
  char *path = "site-package/index3.py";
  if (pipe(input_fd) < 0 || pipe(output_fd) < 0) {
    perror("pipe");
    return 501;
  }
  pid = fork();
  if (pid < 0) {
    perror("fork");
    return 501;
  } 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(path, path, NULL);
    perror("execl");
    exit(errno);
  } else {
    char strbuf[10240];
    ssize_t sz;
    close(output_fd[1]);
    close(input_fd[0]);
    memset(strbuf, 0, 10240);
    while ((sz = read(output_fd[0], strbuf, 10240)) != 0) {
      if (sz < 0) {
        perror("read");
        return 501;
      }
      printf("OUTPUT: %s\n", strbuf);
      memset(strbuf, 0, 10240);
    }
    waitpid(pid, &status, 0);
    if (WIFEXITED(status) && WEXITSTATUS(status)) {
      printf("STATUS: %d\n", WEXITSTATUS(status));
      return WEXITSTATUS(status);
    }
    close(output_fd[0]);
    close(input_fd[1]);
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2840,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe17(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jl     1213 <main+0x43>
lea    -0x14(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jge    122b <main+0x5b>
lea    0xdfd(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1f5,-0x4(%rbp)
jmp    13c9 <main+0x1f9>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1257 <main+0x87>
lea    0xdd6(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1f5,-0x4(%rbp)
jmp    13c9 <main+0x1f9>
cmpl   $0x0,-0x1c(%rbp)
jne    12be <main+0xee>
mov    -0x10(%rbp),%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0xc(%rbp),%edi
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10e0 <execl@plt>
lea    0xd76(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
lea    -0x2830(%rbp),%rdi
xor    %esi,%esi
mov    $0x2800,%edx
call   1050 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x2830(%rbp),%rsi
mov    $0x2800,%edx
call   1080 <read@plt>
mov    %rax,-0x2838(%rbp)
cmp    $0x0,%rax
je     1359 <main+0x189>
cmpq   $0x0,-0x2838(%rbp)
jge    132c <main+0x15c>
lea    0xd0c(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1f5,-0x4(%rbp)
jmp    13c9 <main+0x1f9>
lea    -0x2830(%rbp),%rsi
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x2830(%rbp),%rdi
xor    %esi,%esi
mov    $0x2800,%edx
call   1050 <memset@plt>
jmp    12e1 <main+0x111>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    -0x18(%rbp),%edi
call   10c0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     13b2 <main+0x1e2>
mov    -0x18(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     13b2 <main+0x1e2>
mov    -0x18(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xc9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    13c9 <main+0x1f9>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2820,%rsp
lea    0x18(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     1311 <main+0x141>
lea    0x10(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     1311 <main+0x141>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
js     131a <main+0x14a>
je     1342 <main+0x172>
mov    %eax,%r14d
mov    0x14(%rsp),%edi
call   1060 <close@plt>
mov    0x18(%rsp),%edi
call   1060 <close@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2800,%edx
call   1050 <memset@plt>
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x2800,%edx
call   1080 <read@plt>
test   %rax,%rax
je     12ab <main+0xdb>
lea    0xdd0(%rip),%rbp
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %rax,%rax
js     1323 <main+0x153>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2800,%edx
call   1050 <memset@plt>
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x2800,%edx
call   1080 <read@plt>
test   %rax,%rax
jne    1270 <main+0xa0>
lea    0xc(%rsp),%rsi
xor    %ebp,%ebp
mov    %r14d,%edi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    0xc(%rsp),%edi
call   10c0 <WIFEXITED@plt>
test   %rax,%rax
je     12fd <main+0x12d>
mov    0xc(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
test   %eax,%eax
je     12fd <main+0x12d>
mov    0xc(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
lea    0xd51(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%ebp
jmp    1334 <main+0x164>
mov    0x10(%rsp),%edi
call   1060 <close@plt>
mov    0x1c(%rsp),%edi
call   1060 <close@plt>
jmp    1334 <main+0x164>
lea    0xcff(%rip),%rdi
jmp    132a <main+0x15a>
lea    0xcfb(%rip),%rdi
jmp    132a <main+0x15a>
lea    0xcfd(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1f5,%ebp
mov    %ebp,%eax
add    $0x2820,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x14(%rsp),%edi
mov    0x2ca3(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0x18(%rsp),%edi
mov    0x2c71(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0x10(%rsp),%edi
call   1060 <close@plt>
mov    0x1c(%rsp),%edi
call   1060 <close@plt>
lea    0xc81(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10e0 <execl@plt>
lea    0xc91(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"site-package/index3.py\00"
@.str.1 = [5 x i8] c"pipe\00"
@.str.2 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.3 = [6 x i8] c"execl\00"
@errno = global i32 0
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [12 x i8] c"OUTPUT: %s\0A\00"
@.str.6 = [12 x i8] c"STATUS: %d\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 i8*
%7 = alloca [10240 x i8]
%8 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, 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]* %3, 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.1, i64 0, i64 0))
store i32 501, i32* %1
br label %96
18: ; preds = %12
%19 = call i32 (...) @fork()
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 501, i32* %1
br label %96
24: ; preds = %18
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %48
27: ; preds = %24
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%29 = load i32, i32* %28
%30 = load i32, i32* @STDOUT_FILENO
%31 = call i32 @dup2(i32 %29, i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%33 = load i32, i32* %32
%34 = load i32, i32* @STDIN_FILENO
%35 = call i32 @dup2(i32 %33, i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(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 i8*, i8** %6
%43 = load i8*, i8** %6
%44 = call i32 @execl(i8* %42, i8* %43, i32* null)
%45 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @errno
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %24
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = getelementptr inbounds [10240 x i8], [10240 x i8]* %7, i64 0, i64 0
%56 = call i32 @memset(i8* %55, i32 0, i32 10240)
br label %57
57: ; preds = %68, %48
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%59 = load i32, i32* %58
%60 = getelementptr inbounds [10240 x i8], [10240 x i8]* %7, i64 0, i64 0
%61 = call i64 @read(i32 %59, i8* %60, i32 10240)
store i64 %61, i64* %8
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %73
63: ; preds = %57
%64 = load i64, i64* %8
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i32 501, i32* %1
br label %96
68: ; preds = %63
%69 = getelementptr inbounds [10240 x i8], [10240 x i8]* %7, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = getelementptr inbounds [10240 x i8], [10240 x i8]* %7, i64 0, i64 0
%72 = call i32 @memset(i8* %71, i32 0, i32 10240)
br label %57
73: ; preds = %57
%74 = load i32, i32* %5
%75 = call i32 @waitpid(i32 %74, i32* %4, i32 0)
%76 = load i32, i32* %4
%77 = call i64 @WIFEXITED(i32 %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %89
79: ; preds = %73
%80 = load i32, i32* %4
%81 = call i32 @WEXITSTATUS(i32 %80)
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %89
83: ; preds = %79
%84 = load i32, i32* %4
%85 = call i32 @WEXITSTATUS(i32 %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %85)
%87 = load i32, i32* %4
%88 = call i32 @WEXITSTATUS(i32 %87)
store i32 %88, i32* %1
br label %96
89: ; preds = %79, %73
%90 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%91 = load i32, i32* %90
%92 = call i32 @close(i32 %91)
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%94 = load i32, i32* %93
%95 = call i32 @close(i32 %94)
store i32 0, i32* %1
br label %96
96: ; preds = %89, %83, %66, %22, %16
%97 = load i32, i32* %1
ret i32 %97
}

LLVM IR (-O2):
@.str = [23 x i8] c"site-package/index3.py\00"
@.str.1 = [5 x i8] c"pipe\00"
@.str.2 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
@.str.3 = [6 x i8] c"execl\00"
@errno = global i32 0
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [12 x i8] c"OUTPUT: %s\0A\00"
@.str.6 = [12 x i8] c"STATUS: %d\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [10240 x i8]
%5 = bitcast [2 x i32]* %1 to i8*
%6 = bitcast [2 x i32]* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%13 = call i64 @pipe(i32* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11, %0
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %86
17: ; preds = %11
%18 = call i32 (...) @fork()
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %86
22: ; preds = %17
%23 = icmp eq i32 %18, 0
br i1 %23, label %24, label %41
24: ; preds = %22
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%26 = load i32, i32* %25
%27 = load i32, i32* @STDOUT_FILENO
%28 = call i32 @dup2(i32 %26, i32 %27)
%29 = load i32, i32* %8
%30 = load i32, i32* @STDIN_FILENO
%31 = call i32 @dup2(i32 %29, i32 %30)
%32 = load i32, i32* %12
%33 = call i32 @close(i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = call i32 @execl(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32* null)
%38 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32, i32* @errno
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %22
%42 = getelementptr inbounds [10240 x i8], [10240 x i8]* %4, i64 0, i64 0
%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 = load i32, i32* %8
%47 = call i32 @close(i32 %46)
%48 = call i32 @memset(i8* %42, i32 0, i32 10240)
%49 = load i32, i32* %12
%50 = call i64 @read(i32 %49, i8* %42, i32 10240)
%51 = icmp eq i64 %50, 0
br i1 %51, label %63, label %52
52: ; preds = %41, %57
%53 = phi i64 [ %61, %57 ], [ %50, %41 ]
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %84
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %42)
%59 = call i32 @memset(i8* %42, i32 0, i32 10240)
%60 = load i32, i32* %12
%61 = call i64 @read(i32 %60, i8* %42, i32 10240)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %52
63: ; preds = %57, %41
%64 = call i32 @waitpid(i32 %18, i32* %3, i32 0)
%65 = load i32, i32* %3
%66 = call i64 @WIFEXITED(i32 %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %78, label %68
68: ; preds = %63
%69 = load i32, i32* %3
%70 = call i32 @WEXITSTATUS(i32 %69)
%71 = icmp eq i32 %70, 0
br i1 %71, label %78, label %72
72: ; preds = %68
%73 = load i32, i32* %3
%74 = call i32 @WEXITSTATUS(i32 %73)
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %3
%77 = call i32 @WEXITSTATUS(i32 %76)
br label %84
78: ; preds = %68, %63
%79 = load i32, i32* %12
%80 = call i32 @close(i32 %79)
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%82 = load i32, i32* %81
%83 = call i32 @close(i32 %82)
br label %84
84: ; preds = %78, %72, %55
%85 = phi i32 [ 501, %55 ], [ %77, %72 ], [ 0, %78 ]
br label %86
86: ; preds = %84, %20, %15
%87 = phi i32 [ 501, %15 ], [ 501, %20 ], [ %85, %84 ]
ret i32 %87
}