#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*/ F_OK;
int O_APPEND;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ WUNTRACED;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int execvp(char *, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int run_process(char *command, char **args, int flags, char *inputFile,
                char *outputFile) {
  int pid = fork();
  if (pid < 0) {
    fprintf(stderr, "%s\n", strerror(errno));
    return 1143;
  }
  int status = 0;
  if (pid != 0) {
    waitpid(pid, &status, WUNTRACED);
    return 0;
  } else {
    int fd_in = 0;
    int fd_out = 1;
    if (flags & 1) {
      if (access(inputFile, F_OK) == -1) {
        fprintf(stderr, "%s\n", strerror(errno));
        kill(getpid(), SIGTERM);
        return 1143;
      }
      fd_in = open(inputFile, O_RDWR);
      if (fd_in == -1) {
        fprintf(stderr, "%s\n", strerror(errno));
        kill(getpid(), SIGTERM);
        return 1143;
      }
      dup2(fd_in, STDIN_FILENO);
      close(fd_in);
    }
    if ((flags & 2)) {
      fd_out = open(outputFile, O_RDWR | O_CREAT | O_TRUNC,
                    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | S_IWGRP | S_IWOTH);
      if (fd_out == -1) {
        fprintf(stderr, "%s\n", strerror(errno));
        kill(getpid(), SIGTERM);
        return 1143;
      }
      dup2(fd_out, STDOUT_FILENO);
      close(fd_out);
    }
    if ((flags & 4)) {
      fd_out = open(outputFile, O_RDWR | O_CREAT | O_APPEND,
                    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | S_IWGRP | S_IWOTH);
      if (fd_out == -1) {
        fprintf(stderr, "%s\n", strerror(errno));
        kill(getpid(), SIGTERM);
        return 1143;
      }
      dup2(fd_out, STDOUT_FILENO);
      close(fd_out);
    }
    if (execvp(command, args) == -1) {
      fprintf(stderr, "%s\n", strerror(errno));
      kill(getpid(), SIGTERM);
      return 1143;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<run_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1217 <run_process+0x67>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xdfa(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x477,-0x4(%rbp)
jmp    158a <run_process+0x3da>
movl   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1249 <run_process+0x99>
mov    -0x34(%rbp),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rsi
call   1080 <waitpid@plt>
movl   $0x0,-0x4(%rbp)
jmp    158a <run_process+0x3da>
movl   $0x0,-0x3c(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1359 <run_process+0x1a9>
mov    -0x28(%rbp),%rdi
mov    0x2ce7(%rip),%rax
mov    (%rax),%esi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    12d0 <run_process+0x120>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd58(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
movl   $0x477,-0x4(%rbp)
jmp    158a <run_process+0x3da>
mov    -0x28(%rbp),%rdi
mov    0x2cf5(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1340 <run_process+0x190>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xce8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
movl   $0x477,-0x4(%rbp)
jmp    158a <run_process+0x3da>
mov    -0x3c(%rbp),%edi
mov    0x2c2e(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1439 <run_process+0x289>
mov    -0x30(%rbp),%rdi
mov    0x2c5d(%rip),%rax
mov    (%rax),%esi
mov    0x2c7c(%rip),%rax
or     (%rax),%esi
mov    0x2c6b(%rip),%rax
or     (%rax),%esi
mov    0x2bf2(%rip),%rax
mov    (%rax),%edx
mov    0x2c21(%rip),%rax
or     (%rax),%edx
mov    0x2bf0(%rip),%rax
or     (%rax),%edx
mov    0x2bdf(%rip),%rax
or     (%rax),%edx
mov    0x2c0e(%rip),%rax
or     (%rax),%edx
mov    0x2ba5(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    1420 <run_process+0x270>
mov    0x2bc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rdx
lea    0xc08(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2bbb(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
movl   $0x477,-0x4(%rbp)
jmp    158a <run_process+0x3da>
mov    -0x40(%rbp),%edi
mov    0x2bb6(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x40(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1519 <run_process+0x369>
mov    -0x30(%rbp),%rdi
mov    0x2b7d(%rip),%rax
mov    (%rax),%esi
mov    0x2b9c(%rip),%rax
or     (%rax),%esi
mov    0x2b03(%rip),%rax
or     (%rax),%esi
mov    0x2b12(%rip),%rax
mov    (%rax),%edx
mov    0x2b41(%rip),%rax
or     (%rax),%edx
mov    0x2b10(%rip),%rax
or     (%rax),%edx
mov    0x2aff(%rip),%rax
or     (%rax),%edx
mov    0x2b2e(%rip),%rax
or     (%rax),%edx
mov    0x2ac5(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    1500 <run_process+0x350>
mov    0x2ae8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2ad4(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xb28(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2adb(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
movl   $0x477,-0x4(%rbp)
jmp    158a <run_process+0x3da>
mov    -0x40(%rbp),%edi
mov    0x2ad6(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x40(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <execvp@plt>
cmp    $0xffffffff,%eax
jne    157e <run_process+0x3ce>
mov    0x2a6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2a56(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xaaa(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2a5d(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
movl   $0x477,-0x4(%rbp)
jmp    158a <run_process+0x3da>
jmp    1583 <run_process+0x3d3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_process>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r12
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
js     11fb <run_process+0x4b>
movl   $0x0,0xc(%rsp)
je     1228 <run_process+0x78>
mov    0x2dc2(%rip),%rcx
mov    (%rcx),%edx
lea    0xc(%rsp),%rsi
mov    %eax,%edi
call   1080 <waitpid@plt>
xor    %eax,%eax
jmp    13d7 <run_process+0x227>
mov    0x2d9e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xde7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
jmp    13d2 <run_process+0x222>
test   $0x1,%bpl
je     127d <run_process+0xcd>
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
je     1393 <run_process+0x1e3>
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1393 <run_process+0x1e3>
mov    %eax,%ebx
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   $0x2,%bpl
je     1300 <run_process+0x150>
mov    0x2d46(%rip),%rax
mov    0x2d67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d54(%rip),%rax
or     (%rax),%esi
mov    0x2cdb(%rip),%rax
mov    0x2d0c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cd9(%rip),%rax
or     (%rax),%edx
mov    0x2cc8(%rip),%rax
or     (%rax),%edx
mov    0x2cf7(%rip),%rax
or     (%rax),%edx
mov    0x2c8e(%rip),%rax
or     (%rax),%edx
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1393 <run_process+0x1e3>
mov    %eax,%ebx
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   $0x4,%bpl
je     137f <run_process+0x1cf>
mov    0x2cc3(%rip),%rax
mov    0x2ce4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c49(%rip),%rax
or     (%rax),%esi
mov    0x2c58(%rip),%rax
mov    0x2c89(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c56(%rip),%rax
or     (%rax),%edx
mov    0x2c45(%rip),%rax
or     (%rax),%edx
mov    0x2c74(%rip),%rax
or     (%rax),%edx
mov    0x2c0b(%rip),%rax
or     (%rax),%edx
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1393 <run_process+0x1e3>
mov    %eax,%ebx
mov    0x2c71(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10b0 <execvp@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    13d7 <run_process+0x227>
mov    0x2c06(%rip),%rax
mov    (%rax),%ebx
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc4f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x2bff(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <kill@plt>
mov    $0x477,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@WUNTRACED = global i32 0
@F_OK = global i32 0
@SIGTERM = global i32 0
@O_RDWR = global i32 0
@STDIN_FILENO = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@STDOUT_FILENO = global i32 0
@O_APPEND = global i32 0
define i32 @run_process(i8* %0, i8** %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %7
store i8** %1, i8*** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = call i32 (...) @fork()
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 1143, i32* %6
br label %161
24: ; preds = %5
store i32 0, i32* %13
%25 = load i32, i32* %12
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %12
%29 = load i32, i32* @WUNTRACED
%30 = call i32 @waitpid(i32 %28, i32* %13, i32 %29)
store i32 0, i32* %6
br label %161
31: ; preds = %24
store i32 0, i32* %14
store i32 1, i32* %15
%32 = load i32, i32* %9
%33 = and i32 %32, 1
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %68
35: ; preds = %31
%36 = load i8*, i8** %10
%37 = load i32, i32* @F_OK
%38 = call i32 @access(i8* %36, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %43)
%45 = call i32 (...) @getpid()
%46 = load i32, i32* @SIGTERM
%47 = call i32 @kill(i32 %45, i32 %46)
store i32 1143, i32* %6
br label %161
48: ; preds = %35
%49 = load i8*, i8** %10
%50 = load i32, i32* @O_RDWR
%51 = call i32 (i8*, i32, ...) @open(i8* %49, i32 %50)
store i32 %51, i32* %14
%52 = load i32, i32* %14
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %62
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %57)
%59 = call i32 (...) @getpid()
%60 = load i32, i32* @SIGTERM
%61 = call i32 @kill(i32 %59, i32 %60)
store i32 1143, i32* %6
br label %161
62: ; preds = %48
%63 = load i32, i32* %14
%64 = load i32, i32* @STDIN_FILENO
%65 = call i32 @dup2(i32 %63, i32 %64)
%66 = load i32, i32* %14
%67 = call i32 @close(i32 %66)
br label %68
68: ; preds = %62, %31
%69 = load i32, i32* %9
%70 = and i32 %69, 2
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %107
72: ; preds = %68
%73 = load i8*, i8** %11
%74 = load i32, i32* @O_RDWR
%75 = load i32, i32* @O_CREAT
%76 = or i32 %74, %75
%77 = load i32, i32* @O_TRUNC
%78 = or i32 %76, %77
%79 = load i32, i32* @S_IRUSR
%80 = load i32, i32* @S_IWUSR
%81 = or i32 %79, %80
%82 = load i32, i32* @S_IRGRP
%83 = or i32 %81, %82
%84 = load i32, i32* @S_IROTH
%85 = or i32 %83, %84
%86 = load i32, i32* @S_IWGRP
%87 = or i32 %85, %86
%88 = load i32, i32* @S_IWOTH
%89 = or i32 %87, %88
%90 = call i32 (i8*, i32, ...) @open(i8* %73, i32 %78, i32 %89)
store i32 %90, i32* %15
%91 = load i32, i32* %15
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %101
93: ; preds = %72
%94 = load i32, i32* @stderr
%95 = load i32, i32* @errno
%96 = call i8* @strerror(i32 %95)
%97 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %96)
%98 = call i32 (...) @getpid()
%99 = load i32, i32* @SIGTERM
%100 = call i32 @kill(i32 %98, i32 %99)
store i32 1143, i32* %6
br label %161
101: ; preds = %72
%102 = load i32, i32* %15
%103 = load i32, i32* @STDOUT_FILENO
%104 = call i32 @dup2(i32 %102, i32 %103)
%105 = load i32, i32* %15
%106 = call i32 @close(i32 %105)
br label %107
107: ; preds = %101, %68
%108 = load i32, i32* %9
%109 = and i32 %108, 4
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %146
111: ; preds = %107
%112 = load i8*, i8** %11
%113 = load i32, i32* @O_RDWR
%114 = load i32, i32* @O_CREAT
%115 = or i32 %113, %114
%116 = load i32, i32* @O_APPEND
%117 = or i32 %115, %116
%118 = load i32, i32* @S_IRUSR
%119 = load i32, i32* @S_IWUSR
%120 = or i32 %118, %119
%121 = load i32, i32* @S_IRGRP
%122 = or i32 %120, %121
%123 = load i32, i32* @S_IROTH
%124 = or i32 %122, %123
%125 = load i32, i32* @S_IWGRP
%126 = or i32 %124, %125
%127 = load i32, i32* @S_IWOTH
%128 = or i32 %126, %127
%129 = call i32 (i8*, i32, ...) @open(i8* %112, i32 %117, i32 %128)
store i32 %129, i32* %15
%130 = load i32, i32* %15
%131 = icmp eq i32 %130, -1
br i1 %131, label %132, label %140
132: ; preds = %111
%133 = load i32, i32* @stderr
%134 = load i32, i32* @errno
%135 = call i8* @strerror(i32 %134)
%136 = call i32 @fprintf(i32 %133, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %135)
%137 = call i32 (...) @getpid()
%138 = load i32, i32* @SIGTERM
%139 = call i32 @kill(i32 %137, i32 %138)
store i32 1143, i32* %6
br label %161
140: ; preds = %111
%141 = load i32, i32* %15
%142 = load i32, i32* @STDOUT_FILENO
%143 = call i32 @dup2(i32 %141, i32 %142)
%144 = load i32, i32* %15
%145 = call i32 @close(i32 %144)
br label %146
146: ; preds = %140, %107
%147 = load i8*, i8** %7
%148 = load i8**, i8*** %8
%149 = call i32 @execvp(i8* %147, i8** %148)
%150 = icmp eq i32 %149, -1
br i1 %150, label %151, label %159
151: ; preds = %146
%152 = load i32, i32* @stderr
%153 = load i32, i32* @errno
%154 = call i8* @strerror(i32 %153)
%155 = call i32 @fprintf(i32 %152, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %154)
%156 = call i32 (...) @getpid()
%157 = load i32, i32* @SIGTERM
%158 = call i32 @kill(i32 %156, i32 %157)
store i32 1143, i32* %6
br label %161
159: ; preds = %146
br label %160
160: ; preds = %159
store i32 0, i32* %6
br label %161
161: ; preds = %160, %151, %132, %93, %54, %40, %27, %19
%162 = load i32, i32* %6
ret i32 %162
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@WUNTRACED = global i32 0
@F_OK = global i32 0
@SIGTERM = global i32 0
@O_RDWR = global i32 0
@STDIN_FILENO = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@STDOUT_FILENO = global i32 0
@O_APPEND = global i32 0
define i32 @run_process(i8* %0, i8** %1, i32 %2, i8* nocapture %3, i8* nocapture %4) {
%6 = alloca i32
%7 = tail call i32 (...) @fork()
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %132
14: ; preds = %5
%15 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%16 = icmp eq i32 %7, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @WUNTRACED
%19 = call i32 @waitpid(i32 %7, i32* %6, i32 %18)
br label %130
20: ; preds = %14
%21 = and i32 %2, 1
%22 = icmp eq i32 %21, 0
br i1 %22, label %51, label %23
23: ; preds = %20
%24 = load i32, i32* @F_OK
%25 = tail call i32 @access(i8* %3, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = tail call i32 (...) @getpid()
%33 = load i32, i32* @SIGTERM
%34 = tail call i32 @kill(i32 %32, i32 %33)
br label %130
35: ; preds = %23
%36 = load i32, i32* @O_RDWR
%37 = tail call i32 (i8*, i32, ...) @open(i8* %3, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = tail call i8* @strerror(i32 %41)
%43 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = tail call i32 (...) @getpid()
%45 = load i32, i32* @SIGTERM
%46 = tail call i32 @kill(i32 %44, i32 %45)
br label %130
47: ; preds = %35
%48 = load i32, i32* @STDIN_FILENO
%49 = tail call i32 @dup2(i32 %37, i32 %48)
%50 = tail call i32 @close(i32 %37)
br label %51
51: ; preds = %47, %20
%52 = and i32 %2, 2
%53 = icmp eq i32 %52, 0
br i1 %53, label %85, label %54
54: ; preds = %51
%55 = load i32, i32* @O_RDWR
%56 = load i32, i32* @O_CREAT
%57 = or i32 %56, %55
%58 = load i32, i32* @O_TRUNC
%59 = or i32 %57, %58
%60 = load i32, i32* @S_IRUSR
%61 = load i32, i32* @S_IWUSR
%62 = or i32 %61, %60
%63 = load i32, i32* @S_IRGRP
%64 = or i32 %62, %63
%65 = load i32, i32* @S_IROTH
%66 = or i32 %64, %65
%67 = load i32, i32* @S_IWGRP
%68 = or i32 %66, %67
%69 = load i32, i32* @S_IWOTH
%70 = or i32 %68, %69
%71 = tail call i32 (i8*, i32, ...) @open(i8* %4, i32 %59, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %81
73: ; preds = %54
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = tail call i8* @strerror(i32 %75)
%77 = tail call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %76)
%78 = tail call i32 (...) @getpid()
%79 = load i32, i32* @SIGTERM
%80 = tail call i32 @kill(i32 %78, i32 %79)
br label %130
81: ; preds = %54
%82 = load i32, i32* @STDOUT_FILENO
%83 = tail call i32 @dup2(i32 %71, i32 %82)
%84 = tail call i32 @close(i32 %71)
br label %85
85: ; preds = %81, %51
%86 = and i32 %2, 4
%87 = icmp eq i32 %86, 0
br i1 %87, label %119, label %88
88: ; preds = %85
%89 = load i32, i32* @O_RDWR
%90 = load i32, i32* @O_CREAT
%91 = or i32 %90, %89
%92 = load i32, i32* @O_APPEND
%93 = or i32 %91, %92
%94 = load i32, i32* @S_IRUSR
%95 = load i32, i32* @S_IWUSR
%96 = or i32 %95, %94
%97 = load i32, i32* @S_IRGRP
%98 = or i32 %96, %97
%99 = load i32, i32* @S_IROTH
%100 = or i32 %98, %99
%101 = load i32, i32* @S_IWGRP
%102 = or i32 %100, %101
%103 = load i32, i32* @S_IWOTH
%104 = or i32 %102, %103
%105 = tail call i32 (i8*, i32, ...) @open(i8* %4, i32 %93, i32 %104)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %115
107: ; preds = %88
%108 = load i32, i32* @stderr
%109 = load i32, i32* @errno
%110 = tail call i8* @strerror(i32 %109)
%111 = tail call i32 @fprintf(i32 %108, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %110)
%112 = tail call i32 (...) @getpid()
%113 = load i32, i32* @SIGTERM
%114 = tail call i32 @kill(i32 %112, i32 %113)
br label %130
115: ; preds = %88
%116 = load i32, i32* @STDOUT_FILENO
%117 = tail call i32 @dup2(i32 %105, i32 %116)
%118 = tail call i32 @close(i32 %105)
br label %119
119: ; preds = %115, %85
%120 = tail call i32 @execvp(i8* %0, i8** %1)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %130
122: ; preds = %119
%123 = load i32, i32* @stderr
%124 = load i32, i32* @errno
%125 = tail call i8* @strerror(i32 %124)
%126 = tail call i32 @fprintf(i32 %123, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %125)
%127 = tail call i32 (...) @getpid()
%128 = load i32, i32* @SIGTERM
%129 = tail call i32 @kill(i32 %127, i32 %128)
br label %130
130: ; preds = %27, %39, %73, %107, %122, %119, %17
%131 = phi i32 [ 0, %17 ], [ 0, %119 ], [ 1143, %122 ], [ 1143, %107 ], [ 1143, %73 ], [ 1143, %39 ], [ 1143, %27 ]
br label %132
132: ; preds = %130, %9
%133 = phi i32 [ 1143, %9 ], [ %131, %130 ]
ret i32 %133
}