#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 WEXITSTATUS(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int strlen(char const *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char const *, int);
int run_test(int (*testfunc)(void), const char *request, int expected) {
  int toch[2];
  int topa[2];
  pid_t child;
  int status;
  pipe(toch);
  pipe(topa);
  if ((child = fork())) {
    int to, from, c;
    char buffer[4096];
    close(toch[0]);
    close(topa[1]);
    to = toch[1];
    from = topa[0];
    write(to, request, strlen(request));
    while ((c = read(from, buffer, 4096)) > 0) {
      write(1, buffer, c);
    }
    waitpid(child, &status, 0);
    if (WEXITSTATUS(status)) {
      printf("Exit status: %d\n", WEXITSTATUS(status));
    }
    return WEXITSTATUS(status);
  } else {
    close(0);
    close(1);
    dup(toch[0]);
    dup(topa[1]);
    close(topa[0]);
    close(topa[1]);
    close(toch[0]);
    close(toch[1]);
    exit(expected != testfunc());
  }
}


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x1c(%rbp),%rdi
call   1080 <pipe@plt>
lea    -0x24(%rbp),%rdi
call   1080 <pipe@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     12b7 <run_test+0x107>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x104c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1048(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x104c(%rbp),%edi
mov    -0x1048(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x34(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jle    1271 <run_test+0xc1>
lea    -0x1040(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1238 <run_test+0x88>
mov    -0x28(%rbp),%edi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
mov    -0x2c(%rbp),%edi
call   10a0 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     12a6 <run_test+0xf6>
mov    -0x2c(%rbp),%edi
call   10a0 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xd5f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
call   10a0 <WEXITSTATUS@plt>
add    $0x1050,%rsp
pop    %rbp
ret
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%edi
call   1060 <dup@plt>
mov    -0x20(%rbp),%edi
call   1060 <dup@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1050(%rbp)
call   *-0x8(%rbp)
mov    %eax,%ecx
mov    -0x1050(%rbp),%eax
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<run_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1020,%rsp
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0x18(%rsp),%rdi
call   1080 <pipe@plt>
lea    0x10(%rsp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     12ae <run_test+0xfe>
mov    %eax,%r15d
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x1c(%rsp),%ebx
mov    0x10(%rsp),%ebp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1000,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1262 <run_test+0xb2>
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
test   %eax,%eax
jg     1240 <run_test+0x90>
lea    0xc(%rsp),%rsi
mov    %r15d,%edi
xor    %edx,%edx
call   10b0 <waitpid@plt>
mov    0xc(%rsp),%edi
call   10a0 <WEXITSTATUS@plt>
test   %eax,%eax
je     1295 <run_test+0xe5>
mov    0xc(%rsp),%edi
call   10a0 <WEXITSTATUS@plt>
lea    0xd72(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   10a0 <WEXITSTATUS@plt>
add    $0x1020,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1060 <dup@plt>
mov    0x14(%rsp),%edi
call   1060 <dup@plt>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
call   *%rbp
xor    %edi,%edi
cmp    %r14d,%eax
setne  %dil
call   10c0 <exit@plt>

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

LLVM IR (-O2):
@.str = [17 x i8] c"Exit status: %d\0A\00"
define i32 @run_test(i32 ()* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = bitcast [2 x i32]* %4 to i8*
%9 = bitcast [2 x i32]* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = call i32 (...) @fork()
%16 = icmp eq i32 %15, 0
br i1 %16, label %48, label %17
17: ; preds = %3
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* %11
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%25 = load i32, i32* %24
%26 = load i32, i32* %13
%27 = call i32 @strlen(i8* %1)
%28 = call i32 @write(i32 %25, i8* %1, i32 %27)
%29 = call i32 @read(i32 %26, i8* %18, i32 4096)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %17, %31
%32 = phi i32 [ %34, %31 ], [ %29, %17 ]
%33 = call i32 @write(i32 1, i8* %18, i32 %32)
%34 = call i32 @read(i32 %26, i8* %18, i32 4096)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %31, label %36
36: ; preds = %31, %17
%37 = call i32 @waitpid(i32 %15, i32* %6, i32 0)
%38 = load i32, i32* %6
%39 = call i32 @WEXITSTATUS(i32 %38)
%40 = icmp eq i32 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %36
%42 = load i32, i32* %6
%43 = call i32 @WEXITSTATUS(i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %36
%46 = load i32, i32* %6
%47 = call i32 @WEXITSTATUS(i32 %46)
ret i32 %47
48: ; preds = %3
%49 = call i32 @close(i32 0)
%50 = call i32 @close(i32 1)
%51 = load i32, i32* %11
%52 = call i32 @dup(i32 %51)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @dup(i32 %54)
%56 = load i32, i32* %13
%57 = call i32 @close(i32 %56)
%58 = load i32, i32* %53
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* %11
%61 = call i32 @close(i32 %60)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = call i32 %0()
%66 = icmp ne i32 %65, %2
%67 = zext i1 %66 to i32
%68 = call i32 @exit(i32 %67)
unreachable
}