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

/* Variables and functions */
int FD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
scalar_t__ dup2(int, int);
int execvp(char *, char **);
int fcntl(int, int /*<<< orphan*/, ...);
int fork();
char **get_command(char const *);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int setup_remote_filter(int sSocket, const char *cCommand) {
  if (sSocket < 0 || !cCommand)
    return -1;
  int new_sockets[2] = {-1, -1};
  if (socketpair(PF_LOCAL, SOCK_STREAM, 0, new_sockets) < 0)
    return -1;
  int current_state = 0;
  current_state = fcntl(new_sockets[0], F_GETFL);
  fcntl(new_sockets[0], F_SETFL, current_state | O_NONBLOCK);
  current_state = fcntl(new_sockets[1], F_GETFL);
  fcntl(new_sockets[1], F_SETFL, current_state | O_NONBLOCK);
  pid_t new_process = -1;
  if ((new_process = fork()) < 0) {
    close(new_sockets[0]);
    close(new_sockets[1]);
    return -1;
  } else if (new_process) {
    close(new_sockets[1]);
    current_state = fcntl(new_sockets[0], F_GETFD);
    fcntl(new_sockets[0], F_SETFD, current_state | FD_CLOEXEC);
    return new_sockets[0];
  } else {
    close(new_sockets[0]);
    if (dup2(sSocket, STDIN_FILENO) < 0)
      _exit(1);
    if (dup2(new_sockets[1], STDOUT_FILENO) < 0)
      _exit(1);
    int current_state = 0;
    current_state = fcntl(STDOUT_FILENO, F_GETFD);
    fcntl(STDOUT_FILENO, F_SETFD, current_state & ~FD_CLOEXEC);
    current_state = fcntl(STDIN_FILENO, F_GETFD);
    fcntl(STDIN_FILENO, F_SETFD, current_state & ~FD_CLOEXEC);
    if (sSocket != STDOUT_FILENO && sSocket != STDIN_FILENO)
      close(sSocket);
    if (new_sockets[1] != STDOUT_FILENO && new_sockets[1] != STDIN_FILENO)
      close(new_sockets[1]);
    char **command = get_command(cCommand);
    if (!command)
      return -1;
    _exit(execvp(command[0], command));
  }
  return -1;
}


x86 assembly (clang, -O0):
<setup_remote_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11a4 <setup_remote_filter+0x24>
cmpq   $0x0,-0x10(%rbp)
jne    11b0 <setup_remote_filter+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <setup_remote_filter+0x2df>
mov    0xe49(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rcx
xor    %edx,%edx
call   1080 <socketpair@plt>
cmp    $0x0,%rax
jge    11ee <setup_remote_filter+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <setup_remote_filter+0x2df>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    0x2dbf(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0x14(%rbp),%edi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    0x2d8a(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1295 <setup_remote_filter+0x115>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <setup_remote_filter+0x2df>
cmpl   $0x0,-0x20(%rbp)
je     12e7 <setup_remote_filter+0x167>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    0x2ce5(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    145f <setup_remote_filter+0x2df>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
cmp    $0x0,%rax
jge    1314 <setup_remote_filter+0x194>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
cmp    $0x0,%rax
jge    1339 <setup_remote_filter+0x1b9>
mov    $0x1,%edi
call   1030 <_exit@plt>
movl   $0x0,-0x24(%rbp)
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
mov    0x2c60(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x24(%rbp)
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
mov    0x2c40(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
mov    0x2c1a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x24(%rbp)
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
mov    0x2bfa(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0x8(%rbp),%eax
mov    0x2c1a(%rip),%rcx
cmp    (%rcx),%eax
je     13f8 <setup_remote_filter+0x278>
mov    -0x8(%rbp),%eax
mov    0x2bb0(%rip),%rcx
cmp    (%rcx),%eax
je     13f8 <setup_remote_filter+0x278>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%eax
mov    0x2bee(%rip),%rcx
cmp    (%rcx),%eax
je     1424 <setup_remote_filter+0x2a4>
mov    -0x14(%rbp),%eax
mov    0x2b84(%rip),%rcx
cmp    (%rcx),%eax
je     1424 <setup_remote_filter+0x2a4>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rdi
call   1070 <get_command@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1448 <setup_remote_filter+0x2c8>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <setup_remote_filter+0x2df>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <execvp@plt>
mov    %eax,%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_remote_filter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
test   %edi,%edi
js     1381 <setup_remote_filter+0x201>
mov    %rsi,%r14
test   %rsi,%rsi
je     1381 <setup_remote_filter+0x201>
mov    %edi,%ebp
movq   $0xffffffffffffffff,(%rsp)
ff
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
xor    %edx,%edx
call   1080 <socketpair@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     1381 <setup_remote_filter+0x201>
mov    (%rsp),%edi
mov    0x2dc6(%rip),%r15
mov    (%r15),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    (%rsp),%edi
mov    0x2dd2(%rip),%r12
mov    (%r12),%esi
mov    0x2ddf(%rip),%r13
or     0x0(%r13),%eax
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x4(%rsp),%edi
mov    (%r15),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x4(%rsp),%edi
mov    (%r12),%esi
or     0x0(%r13),%eax
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
js     1280 <setup_remote_filter+0x100>
je     1296 <setup_remote_filter+0x116>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    (%rsp),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    (%rsp),%edi
mov    0x2d6c(%rip),%rcx
mov    (%rcx),%esi
mov    0x2d4b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    (%rsp),%ebx
jmp    1381 <setup_remote_filter+0x201>
mov    (%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
jmp    1381 <setup_remote_filter+0x201>
mov    (%rsp),%edi
call   1060 <close@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1050 <dup2@plt>
test   %rax,%rax
js     1392 <setup_remote_filter+0x212>
mov    0x4(%rsp),%edi
mov    0x2d2e(%rip),%r15
mov    (%r15),%esi
call   1050 <dup2@plt>
test   %rax,%rax
js     1392 <setup_remote_filter+0x212>
mov    (%r15),%edi
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    (%r15),%edi
mov    0x2ce0(%rip),%r15
mov    (%r15),%esi
mov    0x2cbe(%rip),%r12
mov    (%r12),%edx
not    %edx
and    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x2c88(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2c95(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x0(%r13),%edi
mov    (%r15),%esi
mov    0x2cbe(%rip),%r15
mov    (%r12),%edx
not    %edx
and    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    (%r15),%ecx
mov    0x0(%r13),%eax
cmp    %ebp,%ecx
je     1363 <setup_remote_filter+0x1e3>
cmp    %ebp,%eax
je     1363 <setup_remote_filter+0x1e3>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%r15),%ecx
mov    0x2c37(%rip),%rax
mov    (%rax),%eax
mov    0x4(%rsp),%edi
cmp    %ecx,%edi
je     1374 <setup_remote_filter+0x1f4>
cmp    %eax,%edi
je     1374 <setup_remote_filter+0x1f4>
call   1060 <close@plt>
mov    %r14,%rdi
call   1070 <get_command@plt>
test   %rax,%rax
jne    139c <setup_remote_filter+0x21c>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    (%rax),%rdi
mov    %rax,%rsi
call   1090 <execvp@plt>
mov    %eax,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@__const.setup_remote_filter.new_sockets = [2 x i32] [i32 -1, i32 -1]
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_GETFD = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @setup_remote_filter(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8**
store i32 %0, i32* %4
store i8* %1, i8** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13, %2
store i32 -1, i32* %3
br label %153
17: ; preds = %13
%18 = bitcast [2 x i32]* %6 to i8*
%19 = load i32, i32* @PF_LOCAL
%20 = load i32, i32* @SOCK_STREAM
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%22 = call i64 @socketpair(i32 %19, i32 %20, i32 0, i32* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 -1, i32* %3
br label %153
25: ; preds = %17
store i32 0, i32* %7
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%27 = load i32, i32* %26
%28 = load i32, i32* @F_GETFL
%29 = call i32 (i32, i32, ...) @fcntl(i32 %27, i32 %28)
store i32 %29, i32* %7
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%31 = load i32, i32* %30
%32 = load i32, i32* @F_SETFL
%33 = load i32, i32* %7
%34 = load i32, i32* @O_NONBLOCK
%35 = or i32 %33, %34
%36 = call i32 (i32, i32, ...) @fcntl(i32 %31, i32 %32, i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%38 = load i32, i32* %37
%39 = load i32, i32* @F_GETFL
%40 = call i32 (i32, i32, ...) @fcntl(i32 %38, i32 %39)
store i32 %40, i32* %7
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%42 = load i32, i32* %41
%43 = load i32, i32* @F_SETFL
%44 = load i32, i32* %7
%45 = load i32, i32* @O_NONBLOCK
%46 = or i32 %44, %45
%47 = call i32 (i32, i32, ...) @fcntl(i32 %42, i32 %43, i32 %46)
store i32 -1, i32* %8
%48 = call i32 (...) @fork()
store i32 %48, i32* %8
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %25
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i32 @close(i32 %55)
store i32 -1, i32* %3
br label %153
57: ; preds = %25
%58 = load i32, i32* %8
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %77
60: ; preds = %57
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%62 = load i32, i32* %61
%63 = call i32 @close(i32 %62)
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%65 = load i32, i32* %64
%66 = load i32, i32* @F_GETFD
%67 = call i32 (i32, i32, ...) @fcntl(i32 %65, i32 %66)
store i32 %67, i32* %7
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%69 = load i32, i32* %68
%70 = load i32, i32* @F_SETFD
%71 = load i32, i32* %7
%72 = load i32, i32* @FD_CLOEXEC
%73 = or i32 %71, %72
%74 = call i32 (i32, i32, ...) @fcntl(i32 %69, i32 %70, i32 %73)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%76 = load i32, i32* %75
store i32 %76, i32* %3
br label %153
77: ; preds = %57
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = load i32, i32* %4
%82 = load i32, i32* @STDIN_FILENO
%83 = call i64 @dup2(i32 %81, i32 %82)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %77
%86 = call i32 @_exit(i32 1)
unreachable
87: ; preds = %77
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%89 = load i32, i32* %88
%90 = load i32, i32* @STDOUT_FILENO
%91 = call i64 @dup2(i32 %89, i32 %90)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %87
%94 = call i32 @_exit(i32 1)
unreachable
95: ; preds = %87
store i32 0, i32* %9
%96 = load i32, i32* @STDOUT_FILENO
%97 = load i32, i32* @F_GETFD
%98 = call i32 (i32, i32, ...) @fcntl(i32 %96, i32 %97)
store i32 %98, i32* %9
%99 = load i32, i32* @STDOUT_FILENO
%100 = load i32, i32* @F_SETFD
%101 = load i32, i32* %9
%102 = load i32, i32* @FD_CLOEXEC
%103 = xor i32 %102, -1
%104 = and i32 %101, %103
%105 = call i32 (i32, i32, ...) @fcntl(i32 %99, i32 %100, i32 %104)
%106 = load i32, i32* @STDIN_FILENO
%107 = load i32, i32* @F_GETFD
%108 = call i32 (i32, i32, ...) @fcntl(i32 %106, i32 %107)
store i32 %108, i32* %9
%109 = load i32, i32* @STDIN_FILENO
%110 = load i32, i32* @F_SETFD
%111 = load i32, i32* %9
%112 = load i32, i32* @FD_CLOEXEC
%113 = xor i32 %112, -1
%114 = and i32 %111, %113
%115 = call i32 (i32, i32, ...) @fcntl(i32 %109, i32 %110, i32 %114)
%116 = load i32, i32* %4
%117 = load i32, i32* @STDOUT_FILENO
%118 = icmp ne i32 %116, %117
br i1 %118, label %119, label %126
119: ; preds = %95
%120 = load i32, i32* %4
%121 = load i32, i32* @STDIN_FILENO
%122 = icmp ne i32 %120, %121
br i1 %122, label %123, label %126
123: ; preds = %119
%124 = load i32, i32* %4
%125 = call i32 @close(i32 %124)
br label %126
126: ; preds = %123, %119, %95
%127 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%128 = load i32, i32* %127
%129 = load i32, i32* @STDOUT_FILENO
%130 = icmp ne i32 %128, %129
br i1 %130, label %131, label %140
131: ; preds = %126
%132 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%133 = load i32, i32* %132
%134 = load i32, i32* @STDIN_FILENO
%135 = icmp ne i32 %133, %134
br i1 %135, label %136, label %140
136: ; preds = %131
%137 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%138 = load i32, i32* %137
%139 = call i32 @close(i32 %138)
br label %140
140: ; preds = %136, %131, %126
%141 = load i8*, i8** %5
%142 = call i8** @get_command(i8* %141)
store i8** %142, i8*** %10
%143 = load i8**, i8*** %10
%144 = icmp ne i8** %143, null
br i1 %144, label %146, label %145
145: ; preds = %140
store i32 -1, i32* %3
br label %153
146: ; preds = %140
%147 = load i8**, i8*** %10
%148 = getelementptr inbounds i8*, i8** %147, i64 0
%149 = load i8*, i8** %148
%150 = load i8**, i8*** %10
%151 = call i32 @execvp(i8* %149, i8** %150)
%152 = call i32 @_exit(i32 %151)
unreachable
153: ; preds = %145, %60, %50, %24, %16
%154 = load i32, i32* %3
ret i32 %154
}

LLVM IR (-O2):
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_GETFD = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @setup_remote_filter(i32 %0, i8* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to [2 x i32]*
%5 = icmp sgt i32 %0, -1
%6 = icmp ne i8* %1, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %115
8: ; preds = %2
%9 = bitcast i64* %3 to i8*
store i64 -1, i64* %3
%10 = load i32, i32* @PF_LOCAL
%11 = load i32, i32* @SOCK_STREAM
%12 = bitcast i64* %3 to i32*
%13 = call i64 @socketpair(i32 %10, i32 %11, i32 0, i32* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %113, label %15
15: ; preds = %8
%16 = load i32, i32* %12
%17 = load i32, i32* @F_GETFL
%18 = call i32 (i32, i32, ...) @fcntl(i32 %16, i32 %17)
%19 = load i32, i32* %12
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* @O_NONBLOCK
%22 = or i32 %21, %18
%23 = call i32 (i32, i32, ...) @fcntl(i32 %19, i32 %20, 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* @F_GETFL
%27 = call i32 (i32, i32, ...) @fcntl(i32 %25, i32 %26)
%28 = load i32, i32* %24
%29 = load i32, i32* @F_SETFL
%30 = load i32, i32* @O_NONBLOCK
%31 = or i32 %30, %27
%32 = call i32 (i32, i32, ...) @fcntl(i32 %28, i32 %29, i32 %31)
%33 = call i32 (...) @fork()
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %15
%36 = load i32, i32* %12
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %24
%39 = call i32 @close(i32 %38)
br label %113
40: ; preds = %15
%41 = icmp eq i32 %33, 0
br i1 %41, label %54, label %42
42: ; preds = %40
%43 = load i32, i32* %24
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %12
%46 = load i32, i32* @F_GETFD
%47 = call i32 (i32, i32, ...) @fcntl(i32 %45, i32 %46)
%48 = load i32, i32* %12
%49 = load i32, i32* @F_SETFD
%50 = load i32, i32* @FD_CLOEXEC
%51 = or i32 %50, %47
%52 = call i32 (i32, i32, ...) @fcntl(i32 %48, i32 %49, i32 %51)
%53 = load i32, i32* %12
br label %113
54: ; preds = %40
%55 = load i32, i32* %12
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* @STDIN_FILENO
%58 = call i64 @dup2(i32 %0, i32 %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = call i32 @_exit(i32 1)
unreachable
62: ; preds = %54
%63 = load i32, i32* %24
%64 = load i32, i32* @STDOUT_FILENO
%65 = call i64 @dup2(i32 %63, i32 %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = call i32 @_exit(i32 1)
unreachable
69: ; preds = %62
%70 = load i32, i32* @STDOUT_FILENO
%71 = load i32, i32* @F_GETFD
%72 = call i32 (i32, i32, ...) @fcntl(i32 %70, i32 %71)
%73 = load i32, i32* @STDOUT_FILENO
%74 = load i32, i32* @F_SETFD
%75 = load i32, i32* @FD_CLOEXEC
%76 = xor i32 %75, -1
%77 = and i32 %72, %76
%78 = call i32 (i32, i32, ...) @fcntl(i32 %73, i32 %74, i32 %77)
%79 = load i32, i32* @STDIN_FILENO
%80 = load i32, i32* @F_GETFD
%81 = call i32 (i32, i32, ...) @fcntl(i32 %79, i32 %80)
%82 = load i32, i32* @STDIN_FILENO
%83 = load i32, i32* @F_SETFD
%84 = load i32, i32* @FD_CLOEXEC
%85 = xor i32 %84, -1
%86 = and i32 %81, %85
%87 = call i32 (i32, i32, ...) @fcntl(i32 %82, i32 %83, i32 %86)
%88 = load i32, i32* @STDOUT_FILENO
%89 = icmp eq i32 %88, %0
%90 = load i32, i32* @STDIN_FILENO
%91 = icmp eq i32 %90, %0
%92 = select i1 %89, i1 true, i1 %91
br i1 %92, label %97, label %93
93: ; preds = %69
%94 = call i32 @close(i32 %0)
%95 = load i32, i32* @STDOUT_FILENO
%96 = load i32, i32* @STDIN_FILENO
br label %97
97: ; preds = %93, %69
%98 = phi i32 [ %96, %93 ], [ %90, %69 ]
%99 = phi i32 [ %95, %93 ], [ %88, %69 ]
%100 = load i32, i32* %24
%101 = icmp eq i32 %100, %99
%102 = icmp eq i32 %100, %98
%103 = select i1 %101, i1 true, i1 %102
br i1 %103, label %106, label %104
104: ; preds = %97
%105 = call i32 @close(i32 %100)
br label %106
106: ; preds = %104, %97
%107 = call i8** @get_command(i8* %1)
%108 = icmp eq i8** %107, null
br i1 %108, label %113, label %109
109: ; preds = %106
%110 = load i8*, i8** %107
%111 = call i32 @execvp(i8* %110, i8** %107)
%112 = call i32 @_exit(i32 %111)
unreachable
113: ; preds = %35, %42, %106, %8
%114 = phi i32 [ -1, %8 ], [ -1, %35 ], [ %53, %42 ], [ -1, %106 ]
br label %115
115: ; preds = %2, %113
%116 = phi i32 [ %114, %113 ], [ -1, %2 ]
ret i32 %116
}