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

/* Variables and functions */
int /*<<< orphan*/ __execute_filter_hook(int, int, int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ setpgid(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ transpose_data(int, int);
int fork_remote(const char *pProgram, int eExecute, int uUp, int dDown,
                pid_t *pProcess1, pid_t *pProcess2, int cClientIn,
                int cClientOut, int fFarIn, int fFarOut) {
  if (!pProcess1 || !pProcess2) {
    fprintf(stderr, "%s: internal error\n", pProgram);
    return -1;
  }
  if ((*pProcess1 = fork()) < 0) {
    fprintf(stderr, "%s: could not create downstream fork: %s\n", pProgram,
            strerror(errno));
    return -1;
  }
  if (*pProcess1 == 0)
    _exit(uUp ? __execute_filter_hook(fFarIn, cClientOut, 2)
              : transpose_data(fFarIn, cClientOut));
  else if (eExecute)
    setpgid(*pProcess1, getpid());
  else
    setpgid(*pProcess1, getppid());
  if ((*pProcess2 = fork()) < 0) {
    fprintf(stderr, "%s: could not create downstream fork: %s\n", pProgram,
            strerror(errno));
    return -1;
  }
  if (*pProcess2 == 0)
    _exit(dDown ? __execute_filter_hook(cClientIn, fFarOut, 1)
                : transpose_data(cClientIn, fFarOut));
  else if (eExecute)
    setpgid(*pProcess2, getpid());
  else
    setpgid(*pProcess2, getppid());
  return 0;
}


x86 assembly (clang, -O0):
<fork_remote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cf <fork_remote+0x3f>
cmpq   $0x0,-0x30(%rbp)
jne    11f6 <fork_remote+0x66>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e1 <fork_remote+0x251>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jge    1254 <fork_remote+0xc4>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e1 <fork_remote+0x251>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    129a <fork_remote+0x10a>
cmpl   $0x0,-0x18(%rbp)
je     1284 <fork_remote+0xf4>
mov    0x20(%rbp),%edi
mov    0x18(%rbp),%esi
mov    $0x2,%edx
call   1070 <__execute_filter_hook@plt>
mov    %eax,-0x40(%rbp)
jmp    1292 <fork_remote+0x102>
mov    0x20(%rbp),%edi
mov    0x18(%rbp),%esi
call   1030 <transpose_data@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
call   1040 <_exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     12c6 <fork_remote+0x136>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1080 <setpgid@plt>
jmp    12e3 <fork_remote+0x153>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1090 <getppid@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1080 <setpgid@plt>
jmp    12e8 <fork_remote+0x158>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jge    1346 <fork_remote+0x1b6>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xce1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e1 <fork_remote+0x251>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    138c <fork_remote+0x1fc>
cmpl   $0x0,-0x1c(%rbp)
je     1376 <fork_remote+0x1e6>
mov    0x10(%rbp),%edi
mov    0x28(%rbp),%esi
mov    $0x1,%edx
call   1070 <__execute_filter_hook@plt>
mov    %eax,-0x60(%rbp)
jmp    1384 <fork_remote+0x1f4>
mov    0x10(%rbp),%edi
mov    0x28(%rbp),%esi
call   1030 <transpose_data@plt>
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%edi
call   1040 <_exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     13b8 <fork_remote+0x228>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
call   1080 <setpgid@plt>
jmp    13d5 <fork_remote+0x245>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1090 <getppid@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
call   1080 <setpgid@plt>
jmp    13da <fork_remote+0x24a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_remote>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
test   %r8,%r8
je     11de <fork_remote+0x4e>
mov    %r9,%rbx
test   %r9,%r9
je     11de <fork_remote+0x4e>
mov    %r8,%r14
mov    %edx,%r13d
mov    %esi,%r12d
mov    %ecx,0x4(%rsp)
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %rax,(%r14)
test   %rax,%rax
js     1232 <fork_remote+0xa2>
je     1286 <fork_remote+0xf6>
mov    %rax,%rbp
xor    %eax,%eax
test   %r12d,%r12d
je     11ff <fork_remote+0x6f>
call   1050 <getpid@plt>
jmp    1204 <fork_remote+0x74>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1275 <fork_remote+0xe5>
call   1090 <getppid@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1080 <setpgid@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %rax,(%rbx)
test   %rax,%rax
js     1232 <fork_remote+0xa2>
je     129a <fork_remote+0x10a>
mov    %rax,%rbp
xor    %ebx,%ebx
xor    %eax,%eax
test   %r12d,%r12d
je     1266 <fork_remote+0xd6>
call   1050 <getpid@plt>
jmp    126b <fork_remote+0xdb>
mov    0x2da7(%rip),%rax
mov    (%rax),%ebx
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdc4(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1275 <fork_remote+0xe5>
call   1090 <getppid@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1080 <setpgid@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x50(%rsp),%edi
mov    0x48(%rsp),%esi
test   %r13d,%r13d
je     12a9 <fork_remote+0x119>
mov    $0x2,%edx
jmp    12ba <fork_remote+0x12a>
mov    0x58(%rsp),%esi
mov    0x40(%rsp),%edi
cmpl   $0x0,0x4(%rsp)
jne    12b5 <fork_remote+0x125>
call   1030 <transpose_data@plt>
mov    %eax,%edi
call   1040 <_exit@plt>
mov    $0x1,%edx
call   1070 <__execute_filter_hook@plt>
mov    %eax,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"%s: internal error\0A\00"
@.str.1 = [42 x i8] c"%s: could not create downstream fork: %s\0A\00"
@errno = global i32 0
define i32 @fork_remote(i8* %0, i32 %1, i32 %2, i32 %3, i64* %4, i64* %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64*
%17 = alloca i64*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store i32 %3, i32* %15
store i64* %4, i64** %16
store i64* %5, i64** %17
store i32 %6, i32* %18
store i32 %7, i32* %19
store i32 %8, i32* %20
store i32 %9, i32* %21
%22 = load i64*, i64** %16
%23 = icmp ne i64* %22, null
br i1 %23, label %24, label %27
24: ; preds = %10
%25 = load i64*, i64** %17
%26 = icmp ne i64* %25, null
br i1 %26, label %31, label %27
27: ; preds = %24, %10
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %12
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 -1, i32* %11
br label %116
31: ; preds = %24
%32 = call i64 (...) @fork()
%33 = load i64*, i64** %16
store i64 %32, i64* %33
%34 = icmp slt i64 %32, 0
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %12
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %39)
store i32 -1, i32* %11
br label %116
41: ; preds = %31
%42 = load i64*, i64** %16
%43 = load i64, i64* %42
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %59
45: ; preds = %41
%46 = load i32, i32* %14
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %20
%50 = load i32, i32* %19
%51 = call i32 @__execute_filter_hook(i32 %49, i32 %50, i32 2)
br label %56
52: ; preds = %45
%53 = load i32, i32* %20
%54 = load i32, i32* %19
%55 = call i32 @transpose_data(i32 %53, i32 %54)
br label %56
56: ; preds = %52, %48
%57 = phi i32 [ %51, %48 ], [ %55, %52 ]
%58 = call i32 @_exit(i32 %57)
unreachable
59: ; preds = %41
%60 = load i32, i32* %13
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %59
%63 = load i64*, i64** %16
%64 = load i64, i64* %63
%65 = call i32 (...) @getpid()
%66 = call i32 @setpgid(i64 %64, i32 %65)
br label %72
67: ; preds = %59
%68 = load i64*, i64** %16
%69 = load i64, i64* %68
%70 = call i32 (...) @getppid()
%71 = call i32 @setpgid(i64 %69, i32 %70)
br label %72
72: ; preds = %67, %62
br label %73
73: ; preds = %72
%74 = call i64 (...) @fork()
%75 = load i64*, i64** %17
store i64 %74, i64* %75
%76 = icmp slt i64 %74, 0
br i1 %76, label %77, label %83
77: ; preds = %73
%78 = load i32, i32* @stderr
%79 = load i8*, i8** %12
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %79, i8* %81)
store i32 -1, i32* %11
br label %116
83: ; preds = %73
%84 = load i64*, i64** %17
%85 = load i64, i64* %84
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %101
87: ; preds = %83
%88 = load i32, i32* %15
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %87
%91 = load i32, i32* %18
%92 = load i32, i32* %21
%93 = call i32 @__execute_filter_hook(i32 %91, i32 %92, i32 1)
br label %98
94: ; preds = %87
%95 = load i32, i32* %18
%96 = load i32, i32* %21
%97 = call i32 @transpose_data(i32 %95, i32 %96)
br label %98
98: ; preds = %94, %90
%99 = phi i32 [ %93, %90 ], [ %97, %94 ]
%100 = call i32 @_exit(i32 %99)
unreachable
101: ; preds = %83
%102 = load i32, i32* %13
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %101
%105 = load i64*, i64** %17
%106 = load i64, i64* %105
%107 = call i32 (...) @getpid()
%108 = call i32 @setpgid(i64 %106, i32 %107)
br label %114
109: ; preds = %101
%110 = load i64*, i64** %17
%111 = load i64, i64* %110
%112 = call i32 (...) @getppid()
%113 = call i32 @setpgid(i64 %111, i32 %112)
br label %114
114: ; preds = %109, %104
br label %115
115: ; preds = %114
store i32 0, i32* %11
br label %116
116: ; preds = %115, %77, %35, %27
%117 = load i32, i32* %11
ret i32 %117
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"%s: internal error\0A\00"
@.str.1 = [42 x i8] c"%s: could not create downstream fork: %s\0A\00"
@errno = global i32 0
define i32 @fork_remote(i8* %0, i32 %1, i32 %2, i32 %3, i64* writeonly %4, i64* writeonly %5, i32 %6, i32 %7, i32 %8, i32 %9) {
%11 = icmp ne i64* %4, null
%12 = icmp ne i64* %5, null
%13 = and i1 %11, %12
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %70
17: ; preds = %10
%18 = tail call i64 (...) @fork()
store i64 %18, i64* %4
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %23)
br label %70
25: ; preds = %17
%26 = icmp eq i64 %18, 0
br i1 %26, label %27, label %36
27: ; preds = %25
%28 = icmp eq i32 %2, 0
br i1 %28, label %31, label %29
29: ; preds = %27
%30 = tail call i32 @__execute_filter_hook(i32 %8, i32 %7, i32 2)
br label %33
31: ; preds = %27
%32 = tail call i32 @transpose_data(i32 %8, i32 %7)
br label %33
33: ; preds = %31, %29
%34 = phi i32 [ %30, %29 ], [ %32, %31 ]
%35 = tail call i32 @_exit(i32 %34)
unreachable
36: ; preds = %25
%37 = icmp eq i32 %1, 0
br i1 %37, label %40, label %38
38: ; preds = %36
%39 = tail call i32 (...) @getpid()
br label %42
40: ; preds = %36
%41 = tail call i32 (...) @getppid()
br label %42
42: ; preds = %38, %40
%43 = phi i32 [ %39, %38 ], [ %41, %40 ]
%44 = tail call i32 @setpgid(i64 %18, i32 %43)
%45 = tail call i64 (...) @fork()
store i64 %45, i64* %5
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = tail call i8* @strerror(i32 %49)
%51 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %50)
br label %70
52: ; preds = %42
%53 = icmp eq i64 %45, 0
br i1 %53, label %54, label %63
54: ; preds = %52
%55 = icmp eq i32 %3, 0
br i1 %55, label %58, label %56
56: ; preds = %54
%57 = tail call i32 @__execute_filter_hook(i32 %6, i32 %9, i32 1)
br label %60
58: ; preds = %54
%59 = tail call i32 @transpose_data(i32 %6, i32 %9)
br label %60
60: ; preds = %58, %56
%61 = phi i32 [ %57, %56 ], [ %59, %58 ]
%62 = tail call i32 @_exit(i32 %61)
unreachable
63: ; preds = %52
br i1 %37, label %67, label %64
64: ; preds = %63
%65 = tail call i32 (...) @getpid()
%66 = tail call i32 @setpgid(i64 %45, i32 %65)
br label %70
67: ; preds = %63
%68 = tail call i32 (...) @getppid()
%69 = tail call i32 @setpgid(i64 %45, i32 %68)
br label %70
70: ; preds = %67, %64, %47, %20, %14
%71 = phi i32 [ -1, %20 ], [ -1, %47 ], [ -1, %14 ], [ 0, %64 ], [ 0, %67 ]
ret i32 %71
}