#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;
typedef int /*<<< orphan*/ child2;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ close(int);
int dup2(int, int /*<<< orphan*/);
int execvp(char *const, char *const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int read(int, int *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int *);
int write(int, int *, int);
pid_t daemonize(char *const cmd[], int outfd, int errfd) {
  pid_t child1, child2;
  int child1_st = 0;
  int pipefd[2];
  if (pipe(pipefd) == -1) {
    perror("pipe");
    return -1;
  }
  child1 = fork();
  if (child1 == -1) {
    perror("fork");
    return -1;
  }
  if (child1 > 0) {
    close(pipefd[1]);
    if (read(pipefd[0], &child2, sizeof(child2)) == -1) {
      perror("read");
      return -1;
    }
    wait(&child1_st);
    close(pipefd[0]);
    if (!WIFEXITED(child1_st) || WEXITSTATUS(child1_st) != 0) {
      return -1;
    }
    return child2;
  } else {
    child2 = fork();
    if (child2 == -1) {
      perror("fork");
      exit(EXIT_FAILURE);
    }
    if (child2 > 0) {
      close(pipefd[0]);
      if (write(pipefd[1], &child2, sizeof(child2)) == -1) {
        perror("write");
        exit(EXIT_FAILURE);
      }
      sleep(1);
      close(pipefd[1]);
      exit(EXIT_SUCCESS);
    } else {
      close(pipefd[0]);
      close(pipefd[1]);
      if (outfd > 0) {
        if (dup2(outfd, STDOUT_FILENO) == -1) {
          perror("dup2");
        }
        close(outfd);
      }
      if (errfd > 0) {
        if (dup2(errfd, STDERR_FILENO) == -1) {
          perror("dup2");
        }
        close(errfd);
      }
      if (execvp(cmd[0], cmd) == -1) {
        perror("execlp");
        exit(EXIT_FAILURE);
      }
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x2c(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1213 <daemonize+0x43>
lea    0xdfe(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1423 <daemonize+0x253>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    123f <daemonize+0x6f>
lea    0xdd7(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1423 <daemonize+0x253>
cmpl   $0x0,-0x1c(%rbp)
jle    12ce <daemonize+0xfe>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x2c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    1283 <daemonize+0xb3>
lea    0xd98(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1423 <daemonize+0x253>
lea    -0x24(%rbp),%rdi
call   10e0 <wait@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%eax
je     12b7 <daemonize+0xe7>
mov    -0x24(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     12c3 <daemonize+0xf3>
movl   $0xffffffff,-0x4(%rbp)
jmp    1423 <daemonize+0x253>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1423 <daemonize+0x253>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12fc <daemonize+0x12c>
lea    0xd1c(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jle    1362 <daemonize+0x192>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1342 <daemonize+0x172>
lea    0xce0(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jle    13aa <daemonize+0x1da>
mov    -0x14(%rbp),%edi
mov    0x2c6a(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    13a2 <daemonize+0x1d2>
lea    0xc78(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jle    13e2 <daemonize+0x212>
mov    -0x18(%rbp),%edi
mov    0x2c1a(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    13da <daemonize+0x20a>
lea    0xc40(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1415 <daemonize+0x245>
lea    0xc18(%rip),%rdi
call   1090 <perror@plt>
mov    0x2bc2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
movl   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     1261 <daemonize+0x91>
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     126a <daemonize+0x9a>
test   %eax,%eax
jle    128f <daemonize+0xbf>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
mov    0x10(%rsp),%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1273 <daemonize+0xa3>
lea    0x8(%rsp),%rdi
call   10e0 <wait@plt>
mov    0x10(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
call   10b0 <WIFEXITED@plt>
test   %eax,%eax
je     127f <daemonize+0xaf>
mov    0x8(%rsp),%edi
call   1080 <WEXITSTATUS@plt>
neg    %rax
sbb    %eax,%eax
or     0xc(%rsp),%eax
jmp    1284 <daemonize+0xb4>
lea    0xd98(%rip),%rdi
jmp    127a <daemonize+0xaa>
lea    0xd94(%rip),%rdi
jmp    127a <daemonize+0xaa>
lea    0xd90(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    12ab <daemonize+0xdb>
lea    0xd5f(%rip),%rdi
jmp    1355 <daemonize+0x185>
mov    %eax,%r15d
mov    0x10(%rsp),%edi
call   1050 <close@plt>
mov    0x14(%rsp),%edi
test   %r15d,%r15d
jle    12e1 <daemonize+0x111>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1368 <daemonize+0x198>
lea    0xd30(%rip),%rdi
jmp    1355 <daemonize+0x185>
call   1050 <close@plt>
test   %ebx,%ebx
jle    1312 <daemonize+0x142>
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    130b <daemonize+0x13b>
lea    0xd0f(%rip),%rdi
call   1090 <perror@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   %ebp,%ebp
jle    133e <daemonize+0x16e>
mov    0x2cbb(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1337 <daemonize+0x167>
lea    0xce3(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   10a0 <execvp@plt>
cmp    $0xffffffff,%eax
jne    135a <daemonize+0x18a>
lea    0xcc5(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
@STDOUT_FILENO = global i32 0
@.str.4 = [5 x i8] c"dup2\00"
@STDERR_FILENO = global i32 0
@.str.5 = [7 x i8] c"execlp\00"
define i32 @daemonize(i8** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2 x i32]
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %10
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %127
17: ; preds = %3
%18 = call i32 (...) @fork()
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %127
23: ; preds = %17
%24 = load i32, i32* %8
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %51
26: ; preds = %23
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%31 = load i32, i32* %30
%32 = call i32 @read(i32 %31, i32* %9, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %127
36: ; preds = %26
%37 = call i32 @wait(i32* %10)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %10
%42 = call i32 @WIFEXITED(i32 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %36
%45 = load i32, i32* %10
%46 = call i64 @WEXITSTATUS(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44, %36
store i32 -1, i32* %4
br label %127
49: ; preds = %44
%50 = load i32, i32* %9
store i32 %50, i32* %4
br label %127
51: ; preds = %23
%52 = call i32 (...) @fork()
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %51
%60 = load i32, i32* %9
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %81
62: ; preds = %59
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%64 = load i32, i32* %63
%65 = call i32 @close(i32 %64)
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%67 = load i32, i32* %66
%68 = call i32 @write(i32 %67, i32* %9, i32 4)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %74
70: ; preds = %62
%71 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %62
%75 = call i32 @sleep(i32 1)
%76 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%77 = load i32, i32* %76
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* @EXIT_SUCCESS
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %59
%82 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%83 = load i32, i32* %82
%84 = call i32 @close(i32 %83)
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%86 = load i32, i32* %85
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* %6
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %100
90: ; preds = %81
%91 = load i32, i32* %6
%92 = load i32, i32* @STDOUT_FILENO
%93 = call i32 @dup2(i32 %91, i32 %92)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %97
95: ; preds = %90
%96 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %97
97: ; preds = %95, %90
%98 = load i32, i32* %6
%99 = call i32 @close(i32 %98)
br label %100
100: ; preds = %97, %81
%101 = load i32, i32* %7
%102 = icmp sgt i32 %101, 0
br i1 %102, label %103, label %113
103: ; preds = %100
%104 = load i32, i32* %7
%105 = load i32, i32* @STDERR_FILENO
%106 = call i32 @dup2(i32 %104, i32 %105)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %110
108: ; preds = %103
%109 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %110
110: ; preds = %108, %103
%111 = load i32, i32* %7
%112 = call i32 @close(i32 %111)
br label %113
113: ; preds = %110, %100
%114 = load i8**, i8*** %5
%115 = getelementptr inbounds i8*, i8** %114, i64 0
%116 = load i8*, i8** %115
%117 = load i8**, i8*** %5
%118 = call i32 @execvp(i8* %116, i8** %117)
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %124
120: ; preds = %113
%121 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%122 = load i32, i32* @EXIT_FAILURE
%123 = call i32 @exit(i32 %122)
unreachable
124: ; preds = %113
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %49, %48, %34, %21, %15
%128 = load i32, i32* %4
ret i32 %128
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
@STDOUT_FILENO = global i32 0
@.str.4 = [5 x i8] c"dup2\00"
@STDERR_FILENO = global i32 0
@.str.5 = [7 x i8] c"execlp\00"
define i32 @daemonize(i8** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i32]
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%9 = bitcast [2 x i32]* %6 to i8*
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %102
15: ; preds = %3
%16 = call i32 (...) @fork()
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %102
20: ; preds = %15
%21 = icmp sgt i32 %16, 0
br i1 %21, label %22, label %44
22: ; preds = %20
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %10
%27 = call i32 @read(i32 %26, i32* %4, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %102
31: ; preds = %22
%32 = call i32 @wait(i32* %5)
%33 = load i32, i32* %10
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %5
%36 = call i32 @WIFEXITED(i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %102, label %38
38: ; preds = %31
%39 = load i32, i32* %5
%40 = call i64 @WEXITSTATUS(i32 %39)
%41 = icmp eq i64 %40, 0
%42 = load i32, i32* %4
%43 = select i1 %41, i32 %42, i32 -1
br label %102
44: ; preds = %20
%45 = call i32 (...) @fork()
store i32 %45, i32* %4
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %44
%52 = icmp sgt i32 %45, 0
%53 = load i32, i32* %10
%54 = call i32 @close(i32 %53)
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%56 = load i32, i32* %55
br i1 %52, label %57, label %70
57: ; preds = %51
%58 = call i32 @write(i32 %56, i32* %4, i32 4)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %57
%65 = call i32 @sleep(i32 1)
%66 = load i32, i32* %55
%67 = call i32 @close(i32 %66)
%68 = load i32, i32* @EXIT_SUCCESS
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %51
%71 = call i32 @close(i32 %56)
%72 = icmp sgt i32 %1, 0
br i1 %72, label %73, label %81
73: ; preds = %70
%74 = load i32, i32* @STDOUT_FILENO
%75 = call i32 @dup2(i32 %1, i32 %74)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %79
79: ; preds = %77, %73
%80 = call i32 @close(i32 %1)
br label %81
81: ; preds = %79, %70
%82 = icmp sgt i32 %2, 0
br i1 %82, label %83, label %91
83: ; preds = %81
%84 = load i32, i32* @STDERR_FILENO
%85 = call i32 @dup2(i32 %2, i32 %84)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %89
89: ; preds = %87, %83
%90 = call i32 @close(i32 %2)
br label %91
91: ; preds = %89, %81
%92 = load i8*, i8** %0
%93 = call i32 @execvp(i8* %92, i8** %0)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %99
95: ; preds = %91
%96 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %91
%100 = load i32, i32* @EXIT_FAILURE
%101 = call i32 @exit(i32 %100)
unreachable
102: ; preds = %38, %31, %29, %18, %13
%103 = phi i32 [ -1, %13 ], [ -1, %18 ], [ -1, %29 ], [ -1, %31 ], [ %43, %38 ]
ret i32 %103
}