#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 /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ dprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ eventio(int, int);
int fork_exec(char **, int *);
int filter_exec(char *argv[], int sigout, int sigerr) {
  int io[3];
  pid_t pid;
  pid = fork_exec(argv, io);
  if (pid == -1) {
    dprintf(STDERR_FILENO,
            "ERROR"
            " "
            "failed to fork filter %s"
            "\n",
            argv[0]);
    return -1;
  }
  if (eventio(io[1], sigout)) {
    dprintf(STDERR_FILENO, "ERROR"
                           " "
                           "failed to set event I/O for filter stdout"
                           "\n");
    return -1;
  }
  if (eventio(io[2], sigerr)) {
    dprintf(STDERR_FILENO, "ERROR"
                           " "
                           "failed to set event I/O for filter stderr"
                           "\n");
    return -1;
  }
  do {
  } while (0);
  return io[0];
}


x86 assembly (clang, -O0):
<filter_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1050 <fork_exec@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1186 <filter_exec+0x56>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1040 <dprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <filter_exec+0xd6>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <eventio@plt>
cmp    $0x0,%rax
je     11be <filter_exec+0x8e>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <dprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <filter_exec+0xd6>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <eventio@plt>
cmp    $0x0,%rax
je     11f6 <filter_exec+0xc6>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1040 <dprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <filter_exec+0xd6>
jmp    11fb <filter_exec+0xcb>
jmp    1200 <filter_exec+0xd0>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_exec>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x4(%rsp),%rsi
call   1050 <fork_exec@plt>
cmp    $0xffffffff,%eax
je     1171 <filter_exec+0x41>
mov    0x8(%rsp),%edi
mov    %ebp,%esi
call   1030 <eventio@plt>
test   %rax,%rax
je     118d <filter_exec+0x5d>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xeb1(%rip),%rsi
jmp    11ae <filter_exec+0x7e>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe7c(%rip),%rsi
xor    %eax,%eax
call   1040 <dprintf@plt>
jmp    11b5 <filter_exec+0x85>
mov    0xc(%rsp),%edi
mov    %r14d,%esi
call   1030 <eventio@plt>
test   %rax,%rax
je     11c3 <filter_exec+0x93>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
xor    %eax,%eax
call   1040 <dprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x4(%rsp),%eax
jmp    11ba <filter_exec+0x8a>

LLVM IR (-O0):
@STDERR_FILENO = global i32 0
@.str = [32 x i8] c"ERROR failed to fork filter %s\0A\00"
@.str.1 = [49 x i8] c"ERROR failed to set event I/O for filter stdout\0A\00"
@.str.2 = [49 x i8] c"ERROR failed to set event I/O for filter stderr\0A\00"
define i32 @filter_exec(i8** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i32]
%9 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%12 = call i32 @fork_exec(i8** %10, i32* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i32, i32* @STDERR_FILENO
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @dprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 -1, i32* %4
br label %44
21: ; preds = %3
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 1
%23 = load i32, i32* %22
%24 = load i32, i32* %6
%25 = call i64 @eventio(i32 %23, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* @STDERR_FILENO
%29 = call i32 (i32, i8*, ...) @dprintf(i32 %28, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %44
30: ; preds = %21
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 2
%32 = load i32, i32* %31
%33 = load i32, i32* %7
%34 = call i64 @eventio(i32 %32, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32, i32* @STDERR_FILENO
%38 = call i32 (i32, i8*, ...) @dprintf(i32 %37, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %44
39: ; preds = %30
br label %40
40: ; preds = %39
br label %41
41: ; preds = %40
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%43 = load i32, i32* %42
store i32 %43, i32* %4
br label %44
44: ; preds = %41, %36, %27, %15
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@STDERR_FILENO = global i32 0
@.str = [32 x i8] c"ERROR failed to fork filter %s\0A\00"
@.str.1 = [49 x i8] c"ERROR failed to set event I/O for filter stdout\0A\00"
@.str.2 = [49 x i8] c"ERROR failed to set event I/O for filter stderr\0A\00"
define i32 @filter_exec(i8** %0, i32 %1, i32 %2) {
%4 = alloca [3 x i32]
%5 = bitcast [3 x i32]* %4 to i8*
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%7 = call i32 @fork_exec(i8** %0, i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @STDERR_FILENO
%11 = load i8*, i8** %0
%12 = call i32 (i32, i8*, ...) @dprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %31
13: ; preds = %3
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i64 @eventio(i32 %15, i32 %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* @STDERR_FILENO
%20 = call i32 (i32, i8*, ...) @dprintf(i32 %19, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %31
21: ; preds = %13
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%23 = load i32, i32* %22
%24 = call i64 @eventio(i32 %23, i32 %2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* @STDERR_FILENO
%28 = call i32 (i32, i8*, ...) @dprintf(i32 %27, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
br label %31
29: ; preds = %21
%30 = load i32, i32* %6
br label %31
31: ; preds = %29, %26, %18, %9
%32 = phi i32 [ -1, %9 ], [ -1, %18 ], [ -1, %26 ], [ %30, %29 ]
ret i32 %32
}