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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ cctools_fatal(char *, char const *, ...);
int chdir(char *);
int /*<<< orphan*/ debug_reopen();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fd_nonstd_close();
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
scalar_t__ getpid();
scalar_t__ setsid();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
void daemonize(int cdroot, const char *pidfile) {
  pid_t pid = fork();
  if (pid < 0) {
    cctools_fatal("could not fork: %s", strerror(errno));
  } else if (pid > 0) {
    exit(EXIT_SUCCESS);
  }
  pid_t group = setsid();
  if (group == (pid_t)-1) {
    cctools_fatal("could not create session: %s", strerror(errno));
  }
  pid = fork();
  if (pid < 0) {
    cctools_fatal("could not fork: %s", strerror(errno));
  } else if (pid > 0) {
    exit(EXIT_SUCCESS);
  }
  if (pidfile && strlen(pidfile)) {
    FILE *file = fopen(pidfile, "w");
    if (file) {
      fprintf(file, "%ld", (long)getpid());
      fclose(file);
    } else {
      cctools_fatal("could not open `%s' for writing: %s", pidfile,
                    strerror(errno));
    }
  }
  if (cdroot) {
    int status = chdir("/");
    if (status == -1) {
      cctools_fatal("could not chdir to `/': %s", strerror(errno));
    }
  }
  umask(0);
  fd_nonstd_close();
  FILE *file0 = freopen("/dev/null", "r", stdin);
  if (file0 == NULL) {
    cctools_fatal("could not reopen stdin: %s", strerror(errno));
  }
  FILE *file1 = freopen("/dev/null", "w", stdout);
  if (file1 == NULL) {
    cctools_fatal("could not reopen stdout: %s", strerror(errno));
  }
  FILE *file2 = freopen("/dev/null", "w", stderr);
  if (file2 == NULL) {
    cctools_fatal("could not reopen stderr: %s", strerror(errno));
  }
  debug_reopen();
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1239 <daemonize+0x49>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
movslq %eax,%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
jmp    1257 <daemonize+0x67>
cmpq   $0x0,-0x18(%rbp)
jle    1252 <daemonize+0x62>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    1257 <daemonize+0x67>
mov    $0x0,%al
call   1080 <setsid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    128c <daemonize+0x9c>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
movslq %eax,%rsi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    12c6 <daemonize+0xd6>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
movslq %eax,%rsi
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
jmp    12e4 <daemonize+0xf4>
cmpq   $0x0,-0x18(%rbp)
jle    12df <daemonize+0xef>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    12e4 <daemonize+0xf4>
cmpq   $0x0,-0x10(%rbp)
je     1380 <daemonize+0x190>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     1380 <daemonize+0x190>
mov    -0x10(%rbp),%rdi
lea    0xd23(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1351 <daemonize+0x161>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xcf4(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
jmp    137b <daemonize+0x18b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
jmp    1380 <daemonize+0x190>
cmpl   $0x0,-0x4(%rbp)
je     13c7 <daemonize+0x1d7>
lea    0xcc9(%rip),%rdi
call   1060 <chdir@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    13c2 <daemonize+0x1d2>
mov    0x2c26(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
movslq %eax,%rsi
lea    0xca1(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
jmp    13c7 <daemonize+0x1d7>
xor    %edi,%edi
call   10c0 <umask@plt>
mov    $0x0,%al
call   1110 <fd_nonstd_close@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%edx
lea    0xc92(%rip),%rdi
lea    0xc95(%rip),%rsi
call   1070 <freopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    141f <daemonize+0x22f>
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
movslq %eax,%rsi
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edx
lea    0xc48(%rip),%rdi
lea    0xbfa(%rip),%rsi
call   1070 <freopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1469 <daemonize+0x279>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
movslq %eax,%rsi
lea    0xc3c(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
mov    0x2b68(%rip),%rax
mov    (%rax),%edx
lea    0xbfe(%rip),%rdi
lea    0xbb0(%rip),%rsi
call   1070 <freopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    14b3 <daemonize+0x2c3>
mov    0x2b35(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
movslq %eax,%rsi
lea    0xc0e(%rip),%rdi
mov    $0x0,%al
call   1090 <cctools_fatal@plt>
mov    $0x0,%al
call   10a0 <debug_reopen@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
js     11fd <daemonize+0x1d>
je     121c <daemonize+0x3c>
jmp    1403 <daemonize+0x223>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
movslq %eax,%rsi
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
xor    %eax,%eax
call   1070 <setsid@plt>
cmp    $0xffffffffffffffff,%rax
jne    1248 <daemonize+0x68>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
movslq %eax,%rsi
lea    0xdd2(%rip),%rdi
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
js     1261 <daemonize+0x81>
jne    1403 <daemonize+0x223>
test   %rbx,%rbx
jne    1285 <daemonize+0xa5>
jmp    12c6 <daemonize+0xe6>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
movslq %eax,%rsi
lea    0xd87(%rip),%rdi
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
test   %rbx,%rbx
je     12c6 <daemonize+0xe6>
cmpb   $0x0,(%rbx)
je     12c6 <daemonize+0xe6>
lea    0xd9f(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     13d4 <daemonize+0x1f4>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd7f(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %r14d,%r14d
je     12fb <daemonize+0x11b>
lea    0xd88(%rip),%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    12fb <daemonize+0x11b>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
movslq %eax,%rsi
lea    0xd68(%rip),%rdi
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
xor    %edi,%edi
call   10b0 <umask@plt>
xor    %eax,%eax
call   1100 <fd_nonstd_close@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edx
lea    0xd5e(%rip),%rdi
lea    0xd61(%rip),%rsi
call   1060 <freopen@plt>
test   %rax,%rax
jne    1349 <daemonize+0x169>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
movslq %eax,%rsi
lea    0xd41(%rip),%rdi
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
lea    0xd1e(%rip),%rdi
lea    0xcd0(%rip),%rsi
call   1060 <freopen@plt>
test   %rax,%rax
jne    1389 <daemonize+0x1a9>
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
movslq %eax,%rsi
lea    0xd1c(%rip),%rdi
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%edx
lea    0xcde(%rip),%rdi
lea    0xc90(%rip),%rsi
call   1060 <freopen@plt>
test   %rax,%rax
jne    13c9 <daemonize+0x1e9>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
movslq %eax,%rsi
lea    0xcf8(%rip),%rdi
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <debug_reopen@plt>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc4d(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <cctools_fatal@plt>
test   %r14d,%r14d
jne    12cb <daemonize+0xeb>
jmp    12fb <daemonize+0x11b>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"could not fork: %s\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [29 x i8] c"could not create session: %s\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [36 x i8] c"could not open `%s' for writing: %s\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [27 x i8] c"could not chdir to `/': %s\00"
@.str.7 = [10 x i8] c"/dev/null\00"
@.str.8 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.9 = [27 x i8] c"could not reopen stdin: %s\00"
@stdout = global i32 0
@.str.10 = [28 x i8] c"could not reopen stdout: %s\00"
@stderr = global i32 0
@.str.11 = [28 x i8] c"could not reopen stderr: %s\00"
define void @daemonize(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
store i32 %0, i32* %3
store i8* %1, i8** %4
%12 = call i64 (...) @fork()
store i64 %12, i64* %5
%13 = load i64, i64* %5
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
%20 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %28
21: ; preds = %2
%22 = load i64, i64* %5
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %21
br label %28
28: ; preds = %27, %15
%29 = call i64 (...) @setsid()
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = icmp eq i64 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8*
%37 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %32, %28
%39 = call i64 (...) @fork()
store i64 %39, i64* %5
%40 = load i64, i64* %5
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* @errno
%44 = call i32 @strerror(i32 %43)
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i8*
%47 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %46)
br label %55
48: ; preds = %38
%49 = load i64, i64* %5
%50 = icmp sgt i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* @EXIT_SUCCESS
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %48
br label %55
55: ; preds = %54, %42
%56 = load i8*, i8** %4
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %79
58: ; preds = %55
%59 = load i8*, i8** %4
%60 = call i64 @strlen(i8* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %79
62: ; preds = %58
%63 = load i8*, i8** %4
%64 = call i32* @fopen(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %64, i32** %7
%65 = load i32*, i32** %7
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %73
67: ; preds = %62
%68 = load i32*, i32** %7
%69 = call i64 (...) @getpid()
%70 = call i32 @fprintf(i32* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %69)
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
br label %78
73: ; preds = %62
%74 = load i8*, i8** %4
%75 = load i32, i32* @errno
%76 = call i32 @strerror(i32 %75)
%77 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %74, i32 %76)
br label %78
78: ; preds = %73, %67
br label %79
79: ; preds = %78, %58, %55
%80 = load i32, i32* %3
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %93
82: ; preds = %79
%83 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 %83, i32* %8
%84 = load i32, i32* %8
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %92
86: ; preds = %82
%87 = load i32, i32* @errno
%88 = call i32 @strerror(i32 %87)
%89 = sext i32 %88 to i64
%90 = inttoptr i64 %89 to i8*
%91 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %90)
br label %92
92: ; preds = %86, %82
br label %93
93: ; preds = %92, %79
%94 = call i32 @umask(i32 0)
%95 = call i32 (...) @fd_nonstd_close()
%96 = load i32, i32* @stdin
%97 = call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 %96)
store i32* %97, i32** %9
%98 = load i32*, i32** %9
%99 = icmp eq i32* %98, null
br i1 %99, label %100, label %106
100: ; preds = %93
%101 = load i32, i32* @errno
%102 = call i32 @strerror(i32 %101)
%103 = sext i32 %102 to i64
%104 = inttoptr i64 %103 to i8*
%105 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %104)
br label %106
106: ; preds = %100, %93
%107 = load i32, i32* @stdout
%108 = call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %107)
store i32* %108, i32** %10
%109 = load i32*, i32** %10
%110 = icmp eq i32* %109, null
br i1 %110, label %111, label %117
111: ; preds = %106
%112 = load i32, i32* @errno
%113 = call i32 @strerror(i32 %112)
%114 = sext i32 %113 to i64
%115 = inttoptr i64 %114 to i8*
%116 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i8* %115)
br label %117
117: ; preds = %111, %106
%118 = load i32, i32* @stderr
%119 = call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %118)
store i32* %119, i32** %11
%120 = load i32*, i32** %11
%121 = icmp eq i32* %120, null
br i1 %121, label %122, label %128
122: ; preds = %117
%123 = load i32, i32* @errno
%124 = call i32 @strerror(i32 %123)
%125 = sext i32 %124 to i64
%126 = inttoptr i64 %125 to i8*
%127 = call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i8* %126)
br label %128
128: ; preds = %122, %117
%129 = call i32 (...) @debug_reopen()
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"could not fork: %s\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [29 x i8] c"could not create session: %s\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [36 x i8] c"could not open `%s' for writing: %s\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [27 x i8] c"could not chdir to `/': %s\00"
@.str.7 = [10 x i8] c"/dev/null\00"
@.str.8 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.9 = [27 x i8] c"could not reopen stdin: %s\00"
@stdout = global i32 0
@.str.10 = [28 x i8] c"could not reopen stdout: %s\00"
@stderr = global i32 0
@.str.11 = [28 x i8] c"could not reopen stderr: %s\00"
define void @daemonize(i32 %0, i8* %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %16
11: ; preds = %2
%12 = icmp eq i64 %3, 0
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = load i32, i32* @EXIT_SUCCESS
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %11, %5
%17 = tail call i64 (...) @setsid()
%18 = icmp eq i64 %17, -1
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* @errno
%21 = tail call i32 @strerror(i32 %20)
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %19, %16
%26 = tail call i64 (...) @fork()
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* @errno
%30 = tail call i32 @strerror(i32 %29)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
%33 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %39
34: ; preds = %25
%35 = icmp eq i64 %26, 0
br i1 %35, label %39, label %36
36: ; preds = %34
%37 = load i32, i32* @EXIT_SUCCESS
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %34, %28
%40 = icmp eq i8* %1, null
br i1 %40, label %55, label %41
41: ; preds = %39
%42 = load i8, i8* %1
%43 = icmp eq i8 %42, 0
br i1 %43, label %55, label %44
44: ; preds = %41
%45 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp eq i32* %45, null
br i1 %46, label %51, label %47
47: ; preds = %44
%48 = tail call i64 (...) @getpid()
%49 = tail call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %48)
%50 = tail call i32 @fclose(i32* %45)
br label %55
51: ; preds = %44
%52 = load i32, i32* @errno
%53 = tail call i32 @strerror(i32 %52)
%54 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %53)
br label %55
55: ; preds = %47, %51, %41, %39
%56 = icmp eq i32 %0, 0
br i1 %56, label %66, label %57
57: ; preds = %55
%58 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %66
60: ; preds = %57
%61 = load i32, i32* @errno
%62 = tail call i32 @strerror(i32 %61)
%63 = sext i32 %62 to i64
%64 = inttoptr i64 %63 to i8*
%65 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %57, %60, %55
%67 = tail call i32 @umask(i32 0)
%68 = tail call i32 (...) @fd_nonstd_close()
%69 = load i32, i32* @stdin
%70 = tail call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 %69)
%71 = icmp eq i32* %70, null
br i1 %71, label %72, label %78
72: ; preds = %66
%73 = load i32, i32* @errno
%74 = tail call i32 @strerror(i32 %73)
%75 = sext i32 %74 to i64
%76 = inttoptr i64 %75 to i8*
%77 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %72, %66
%79 = load i32, i32* @stdout
%80 = tail call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %79)
%81 = icmp eq i32* %80, null
br i1 %81, label %82, label %88
82: ; preds = %78
%83 = load i32, i32* @errno
%84 = tail call i32 @strerror(i32 %83)
%85 = sext i32 %84 to i64
%86 = inttoptr i64 %85 to i8*
%87 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %82, %78
%89 = load i32, i32* @stderr
%90 = tail call i32* @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %89)
%91 = icmp eq i32* %90, null
br i1 %91, label %92, label %98
92: ; preds = %88
%93 = load i32, i32* @errno
%94 = tail call i32 @strerror(i32 %93)
%95 = sext i32 %94 to i64
%96 = inttoptr i64 %95 to i8*
%97 = tail call i32 (i8*, i8*, ...) @cctools_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i8* %96)
br label %98
98: ; preds = %92, %88
%99 = tail call i32 (...) @debug_reopen()
ret void
}