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

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
char *calloc(int, int);
int close(int);
int dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int pipe(int *);
int /*<<< orphan*/ pl_fatal(char *);
int read(int, char *, int);
size_t strcspn(char *, char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
char *_pl_check_output(char *argv[]) {
  int link[2];
  int status, exit_status;
  pid_t pid;
  char *output = calloc(4096, sizeof(char *));
  if (pipe(link) == -1)
    pl_fatal("pipe");
  switch (pid = fork()) {
  case -1:
    pl_fatal("fork");
  case 0:
    if (dup2(link[1], STDOUT_FILENO) == -1)
      pl_fatal("dup2");
    if (close(link[0]) == -1)
      pl_fatal("close");
    if (close(link[1]) == -1)
      pl_fatal("close");
    execvp(argv[0], argv);
    pl_fatal("exec");
  default:
    if (close(link[1]) == -1)
      pl_fatal("close");
    waitpid(pid, &status, 0);
    if (!WIFEXITED(status))
      pl_fatal("child exited abnormally");
    if (WEXITSTATUS(status))
      exit(1);
    if (read(link[0], output, 4096) == -1)
      pl_fatal("read");
    output[strcspn(output, "\n")] = 0;
    return output;
  }
}


x86 assembly (clang, -O0):
<_pl_check_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1000,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x28(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    120d <_pl_check_output+0x3d>
lea    0xdf8(%rip),%rdi
call   10c0 <pl_fatal@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     123a <_pl_check_output+0x6a>
jmp    122a <_pl_check_output+0x5a>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     1246 <_pl_check_output+0x76>
jmp    12c2 <_pl_check_output+0xf2>
lea    0xdc4(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0xc(%rbp),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    126c <_pl_check_output+0x9c>
lea    0xda3(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1289 <_pl_check_output+0xb9>
lea    0xd8b(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    12a6 <_pl_check_output+0xd6>
lea    0xd6e(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   10b0 <execvp@plt>
lea    0xd58(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    12df <_pl_check_output+0x10f>
lea    0xd35(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    -0x14(%rbp),%edi
call   10d0 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    130a <_pl_check_output+0x13a>
lea    0xd15(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0x14(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     1325 <_pl_check_output+0x155>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    134b <_pl_check_output+0x17b>
lea    0xcec(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xcd9(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pl_check_output>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0x1000,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1208 <_pl_check_output+0x38>
lea    0xdfd(%rip),%rdi
call   10c0 <pl_fatal@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1226 <_pl_check_output+0x56>
cmp    $0xffffffff,%ebp
jne    1294 <_pl_check_output+0xc4>
lea    0xde4(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    0xc(%rsp),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1249 <_pl_check_output+0x79>
lea    0xdc6(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1263 <_pl_check_output+0x93>
lea    0xdb1(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    127d <_pl_check_output+0xad>
lea    0xd97(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   10b0 <execvp@plt>
lea    0xd86(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    12ae <_pl_check_output+0xde>
lea    0xd66(%rip),%rdi
call   10c0 <pl_fatal@plt>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    0x4(%rsp),%edi
call   10d0 <WIFEXITED@plt>
test   %eax,%eax
jne    12d5 <_pl_check_output+0x105>
lea    0xd4a(%rip),%rdi
call   10c0 <pl_fatal@plt>
mov    0x4(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
test   %eax,%eax
jne    1323 <_pl_check_output+0x153>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    1304 <_pl_check_output+0x134>
lea    0xd33(%rip),%rdi
call   10c0 <pl_fatal@plt>
lea    0xd2c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [5 x i8] c"dup2\00"
@.str.3 = [6 x i8] c"close\00"
@.str.4 = [5 x i8] c"exec\00"
@.str.5 = [24 x i8] c"child exited abnormally\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [2 x i8] c"\0A\00"
define i8* @_pl_check_output(i8** %0) {
%2 = alloca i8**
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8** %0, i8*** %2
%8 = call i8* @calloc(i32 4096, i32 8)
store i8* %8, i8** %7
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = call i32 (...) @fork()
store i32 %15, i32* %6
switch i32 %15, label %47 [
i32 -1, label %16
i32 0, label %18
]
16: ; preds = %14
%17 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %14, %16
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%20 = load i32, i32* %19
%21 = load i32, i32* @STDOUT_FILENO
%22 = call i32 @dup2(i32 %20, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %18
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @pl_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %26
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @pl_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = load i8**, i8*** %2
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %2
%45 = call i32 @execvp(i8* %43, i8** %44)
%46 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %14, %40
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i32 @close(i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 @pl_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %47
%55 = load i32, i32* %6
%56 = call i32 @waitpid(i32 %55, i32* %4, i32 0)
%57 = load i32, i32* %4
%58 = call i32 @WIFEXITED(i32 %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %54
%61 = call i32 @pl_fatal(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %62
62: ; preds = %60, %54
%63 = load i32, i32* %4
%64 = call i32 @WEXITSTATUS(i32 %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %62
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%70 = load i32, i32* %69
%71 = load i8*, i8** %7
%72 = call i32 @read(i32 %70, i8* %71, i32 4096)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %76
74: ; preds = %68
%75 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %76
76: ; preds = %74, %68
%77 = load i8*, i8** %7
%78 = load i8*, i8** %7
%79 = call i64 @strcspn(i8* %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 0, i8* %80
%81 = load i8*, i8** %7
ret i8* %81
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [5 x i8] c"dup2\00"
@.str.3 = [6 x i8] c"close\00"
@.str.4 = [5 x i8] c"exec\00"
@.str.5 = [24 x i8] c"child exited abnormally\00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [2 x i8] c"\0A\00"
define noalias i8* @_pl_check_output(i8** %0) {
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = bitcast [2 x i32]* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call dereferenceable_or_null(32768) i8* @calloc(i32 4096, i32 8)
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = call i32 (...) @fork()
switch i32 %13, label %40 [
i32 -1, label %14
i32 0, label %16
]
14: ; preds = %12
%15 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %12, %14
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%18 = load i32, i32* %17
%19 = load i32, i32* @STDOUT_FILENO
%20 = call i32 @dup2(i32 %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* %7
%26 = call i32 @close(i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @pl_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* %17
%32 = call i32 @close(i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @pl_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = load i8*, i8** %0
%38 = call i32 @execvp(i8* %37, i8** %0)
%39 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %12, %36
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 @pl_fatal(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %40
%48 = call i32 @waitpid(i32 %13, i32* %3, i32 0)
%49 = load i32, i32* %3
%50 = call i32 @WIFEXITED(i32 %49)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 @pl_fatal(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %47
%55 = load i32, i32* %3
%56 = call i32 @WEXITSTATUS(i32 %55)
%57 = icmp eq i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %54
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %54
%61 = load i32, i32* %7
%62 = call i32 @read(i32 %61, i8* %6, i32 4096)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @pl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
%67 = call i64 @strcspn(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%68 = getelementptr inbounds i8, i8* %6, i64 %67
store i8 0, i8* %68
ret i8* %6
}