#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*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int fork();
scalar_t__ pipe(int *);
int /*<<< orphan*/ read(int, char *, int);
int stub1(int, char **);
void runone(int (*fun)(int argc, char *argv[])) {
  int pfd[2];
  char c;
  if (pipe(pfd) < 0)
    exit(2);
  switch (fork()) {
  case -1:
    exit(2);
  default:
    break;
  case 0:
    close(pfd[0]);
    dup2(pfd[1], 0);
    close(pfd[1]);
    (*fun)(0, NULL);
    exit(1);
  }
  close(pfd[1]);
  read(pfd[0], &c, 1);
  close(pfd[0]);
}


x86 assembly (clang, -O0):
<runone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
jge    1189 <runone+0x29>
mov    $0x2,%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
sub    $0xffffffff,%eax
je     11b3 <runone+0x53>
jmp    11a3 <runone+0x43>
mov    -0x18(%rbp),%eax
test   %eax,%eax
je     11c2 <runone+0x62>
jmp    11bd <runone+0x5d>
mov    $0x2,%edi
call   1070 <exit@plt>
jmp    11ef <runone+0x8f>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   *-0x8(%rbp)
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runone>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
test   %rax,%rax
js     11b2 <runone+0x52>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11bc <runone+0x5c>
cmp    $0xffffffff,%eax
je     11b2 <runone+0x52>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x2,%edi
call   1070 <exit@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
xor    %edi,%edi
xor    %esi,%esi
call   *%rbx
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
define void @runone(i32 (i32, i8**)* %0) {
%2 = alloca i32 (i32, i8**)*
%3 = alloca [2 x i32]
%4 = alloca i8
store i32 (i32, i8**)* %0, i32 (i32, i8**)** %2
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @exit(i32 2)
unreachable
10: ; preds = %1
%11 = call i32 (...) @fork()
switch i32 %11, label %14 [
i32 -1, label %12
i32 0, label %15
]
12: ; preds = %10
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %10
br label %28
15: ; preds = %10
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @dup2(i32 %20, i32 0)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = load i32 (i32, i8**)*, i32 (i32, i8**)** %2
%26 = call i32 %25(i32 0, i8** null)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %14
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @read(i32 %33, i8* %4, i32 1)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
ret void
}

LLVM IR (-O2):
define void @runone(i32 (i32, i8**)* nocapture %0) {
%2 = alloca [2 x i32]
%3 = alloca i8
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @exit(i32 2)
unreachable
10: ; preds = %1
%11 = call i32 (...) @fork()
switch i32 %11, label %24 [
i32 -1, label %12
i32 0, label %14
]
12: ; preds = %10
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %10
%15 = load i32, i32* %5
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @dup2(i32 %18, i32 0)
%20 = load i32, i32* %17
%21 = call i32 @close(i32 %20)
%22 = call i32 %0(i32 0, i8** null)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %10
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %5
%29 = call i32 @read(i32 %28, i8* %3, i32 1)
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
ret void
}