#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 */
struct sigaction {
  scalar_t__ sa_flags;
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_handler;
};
struct rlimit {
  int rlim_max;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_CONS;
int /*<<< orphan*/ LOG_DAEMON;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ RLIMIT_NOFILE;
int RLIM_INFINITY;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int);
int dup(int);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ errno;
scalar_t__ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setsid();
scalar_t__ sigaction(int /*<<< orphan*/, struct sigaction *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ xlog(char *);
int daemonize(char *cmd) {
  int i, fd0, fd1, fd2;
  pid_t pid = 0;
  struct rlimit rl;
  struct sigaction sa;
  umask(0);
  if ((pid = fork()) < 0)
    err_sys("fork err");
  else if (pid > 0)
    exit(0);
  setsid();
  sa.sa_handler = SIG_IGN;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  if (sigaction(SIGHUP, &sa, NULL) < 0)
    err_sys("cant catch SIGHUP");
  if ((pid = fork()) < 0) {
    err_sys("cant fork twice");
    xlog("cant fork twice");
    xlog(strerror(errno));
  } else if (pid > 0)
    exit(0);
  if (chdir("/") < 0)
    err_sys("cant chdir to /");
  if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
    err_sys("cant get getrlimit ");
  if (rl.rlim_max == RLIM_INFINITY)
    rl.rlim_max = 1024;
  for (i = 0; i < rl.rlim_max; ++i)
    close(i);
  fd0 = open("/dev/null", O_RDWR);
  fd1 = dup(fd0);
  fd2 = dup(fd0);
  openlog(cmd, LOG_CONS, LOG_DAEMON);
  if (fd0 != 0 || fd1 != 1 || fd2 != 2) {
    syslog(LOG_ERR, "unexpected fds: %d, %d, %d", fd0, fd1, fd2);
    exit(1);
  }
  syslog(LOG_INFO, "app(%s) daemonized", cmd);
  if (execl(cmd, cmd, (char *)0) < 0) {
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %edi,%edi
call   10b0 <umask@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1251 <daemonize+0x41>
lea    0xdb9(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1268 <daemonize+0x58>
cmpq   $0x0,-0x20(%rbp)
jle    1263 <daemonize+0x53>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    1268 <daemonize+0x58>
mov    $0x0,%al
call   1090 <setsid@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x38(%rbp),%rdi
add    $0x8,%rdi
call   10a0 <sigemptyset@plt>
movq   $0x0,-0x38(%rbp)
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    12bc <daemonize+0xac>
lea    0xd52(%rip),%rdi
call   1040 <err_sys@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1304 <daemonize+0xf4>
lea    0xd43(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xd37(%rip),%rdi
call   1080 <xlog@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rdi
call   1080 <xlog@plt>
jmp    131b <daemonize+0x10b>
cmpq   $0x0,-0x20(%rbp)
jle    1316 <daemonize+0x106>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    131b <daemonize+0x10b>
lea    0xd17(%rip),%rdi
call   1050 <chdir@plt>
cmp    $0x0,%rax
jge    133d <daemonize+0x12d>
lea    0xcf3(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1100 <getrlimit@plt>
cmp    $0x0,%rax
jge    1365 <daemonize+0x155>
lea    0xcdb(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x28(%rbp),%eax
mov    0x2c39(%rip),%rcx
cmp    (%rcx),%eax
jne    137e <daemonize+0x16e>
movl   $0x400,-0x28(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13a7 <daemonize+0x197>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1385 <daemonize+0x175>
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
lea    0xc98(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <dup@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <dup@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2bd0(%rip),%rax
mov    (%rax),%esi
mov    0x2bef(%rip),%rax
mov    (%rax),%edx
call   10e0 <openlog@plt>
cmpl   $0x0,-0x10(%rbp)
jne    140e <daemonize+0x1fe>
cmpl   $0x1,-0x14(%rbp)
jne    140e <daemonize+0x1fe>
cmpl   $0x2,-0x18(%rbp)
je     1439 <daemonize+0x229>
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xc31(%rip),%rsi
mov    $0x0,%al
call   10c0 <syslog@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2b60(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xc27(%rip),%rsi
mov    $0x0,%al
call   10c0 <syslog@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1120 <execl@plt>
cmp    $0x0,%rax
jge    1479 <daemonize+0x269>
mov    $0x1,%edi
call   10f0 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %edi,%edi
call   10b0 <umask@plt>
xor    %eax,%eax
call   1130 <fork@plt>
test   %rax,%rax
js     1234 <daemonize+0x24>
je     1240 <daemonize+0x30>
jmp    129b <daemonize+0x8b>
lea    0xdc5(%rip),%rdi
call   1040 <err_sys@plt>
xor    %eax,%eax
call   1090 <setsid@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rdi
call   10a0 <sigemptyset@plt>
movq   $0x0,0x8(%rsp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jns    128d <daemonize+0x7d>
lea    0xd81(%rip),%rdi
call   1040 <err_sys@plt>
xor    %eax,%eax
call   1130 <fork@plt>
test   %rax,%rax
js     12a2 <daemonize+0x92>
je     12cf <daemonize+0xbf>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xd72(%rip),%rbx
mov    %rbx,%rdi
call   1040 <err_sys@plt>
mov    %rbx,%rdi
call   1080 <xlog@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rdi
call   1080 <xlog@plt>
lea    0xd63(%rip),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
jns    12ec <daemonize+0xdc>
lea    0xd44(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1100 <getrlimit@plt>
test   %rax,%rax
jns    130e <daemonize+0xfe>
lea    0xd32(%rip),%rdi
call   1040 <err_sys@plt>
mov    (%rsp),%eax
mov    0x2c90(%rip),%rcx
cmp    (%rcx),%eax
jne    1325 <daemonize+0x115>
movl   $0x400,(%rsp)
jmp    1329 <daemonize+0x119>
test   %eax,%eax
jle    133f <daemonize+0x12f>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1070 <close@plt>
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     1330 <daemonize+0x120>
mov    0x2c9a(%rip),%rax
mov    (%rax),%esi
lea    0xd00(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <dup@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1060 <dup@plt>
mov    %eax,%ebx
mov    0x2c40(%rip),%rax
mov    (%rax),%esi
mov    0x2c5f(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   10e0 <openlog@plt>
test   %ebp,%ebp
jne    13cb <daemonize+0x1bb>
cmp    $0x1,%r15d
jne    13cb <daemonize+0x1bb>
cmp    $0x2,%ebx
jne    13cb <daemonize+0x1bb>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10c0 <syslog@plt>
mov    %r14,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1120 <execl@plt>
test   %rax,%rax
js     13ea <daemonize+0x1da>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
lea    0xc7e(%rip),%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   10c0 <syslog@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i32 }
%struct.sigaction = type { i64, i32, i32 }
@.str = [9 x i8] c"fork err\00"
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str.1 = [18 x i8] c"cant catch SIGHUP\00"
@.str.2 = [16 x i8] c"cant fork twice\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [16 x i8] c"cant chdir to /\00"
@RLIMIT_NOFILE = global i32 0
@.str.5 = [20 x i8] c"cant get getrlimit \00"
@RLIM_INFINITY = global i32 0
@.str.6 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@LOG_CONS = global i32 0
@LOG_DAEMON = global i32 0
@LOG_ERR = global i32 0
@.str.7 = [27 x i8] c"unexpected fds: %d, %d, %d\00"
@LOG_INFO = global i32 0
@.str.8 = [19 x i8] c"app(%s) daemonized\00"
define i32 @daemonize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca %struct.rlimit
%9 = alloca %struct.sigaction
store i8* %0, i8** %2
store i64 0, i64* %7
%10 = call i32 @umask(i32 0)
%11 = call i64 (...) @fork()
store i64 %11, i64* %7
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @err_sys(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %21
15: ; preds = %1
%16 = load i64, i64* %7
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %15
br label %21
21: ; preds = %20, %13
%22 = call i32 (...) @setsid()
%23 = load i32, i32* @SIG_IGN
%24 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 2
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 1
%26 = call i32 @sigemptyset(i32* %25)
%27 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 0
store i64 0, i64* %27
%28 = load i32, i32* @SIGHUP
%29 = call i64 @sigaction(i32 %28, %struct.sigaction* %9, i32* null)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 @err_sys(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %21
%34 = call i64 (...) @fork()
store i64 %34, i64* %7
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @xlog(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 @xlog(i8* %40)
br label %48
42: ; preds = %33
%43 = load i64, i64* %7
%44 = icmp sgt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %42
br label %48
48: ; preds = %47, %36
%49 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = load i32, i32* @RLIMIT_NOFILE
%55 = call i64 @getrlimit(i32 %54, %struct.rlimit* %8)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @err_sys(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %8, i32 0, i32 0
%61 = load i32, i32* %60
%62 = load i32, i32* @RLIM_INFINITY
%63 = icmp eq i32 %61, %62
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %8, i32 0, i32 0
store i32 1024, i32* %65
br label %66
66: ; preds = %64, %59
store i32 0, i32* %3
br label %67
67: ; preds = %75, %66
%68 = load i32, i32* %3
%69 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %8, i32 0, i32 0
%70 = load i32, i32* %69
%71 = icmp slt i32 %68, %70
br i1 %71, label %72, label %78
72: ; preds = %67
%73 = load i32, i32* %3
%74 = call i32 @close(i32 %73)
br label %75
75: ; preds = %72
%76 = load i32, i32* %3
%77 = add nsw i32 %76, 1
store i32 %77, i32* %3
br label %67
78: ; preds = %67
%79 = load i32, i32* @O_RDWR
%80 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %79)
store i32 %80, i32* %4
%81 = load i32, i32* %4
%82 = call i32 @dup(i32 %81)
store i32 %82, i32* %5
%83 = load i32, i32* %4
%84 = call i32 @dup(i32 %83)
store i32 %84, i32* %6
%85 = load i8*, i8** %2
%86 = load i32, i32* @LOG_CONS
%87 = load i32, i32* @LOG_DAEMON
%88 = call i32 @openlog(i8* %85, i32 %86, i32 %87)
%89 = load i32, i32* %4
%90 = icmp ne i32 %89, 0
br i1 %90, label %97, label %91
91: ; preds = %78
%92 = load i32, i32* %5
%93 = icmp ne i32 %92, 1
br i1 %93, label %97, label %94
94: ; preds = %91
%95 = load i32, i32* %6
%96 = icmp ne i32 %95, 2
br i1 %96, label %97, label %104
97: ; preds = %94, %91, %78
%98 = load i32, i32* @LOG_ERR
%99 = load i32, i32* %4
%100 = load i32, i32* %5
%101 = load i32, i32* %6
%102 = call i32 (i32, i8*, ...) @syslog(i32 %98, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %99, i32 %100, i32 %101)
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %94
%105 = load i32, i32* @LOG_INFO
%106 = load i8*, i8** %2
%107 = call i32 (i32, i8*, ...) @syslog(i32 %105, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %106)
%108 = load i8*, i8** %2
%109 = load i8*, i8** %2
%110 = call i64 @execl(i8* %108, i8* %109, i8* null)
%111 = icmp slt i64 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %104
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %104
ret i32 0
}

LLVM IR (-O2):
%struct.rlimit = type { i32 }
%struct.sigaction = type { i64, i32, i32 }
@.str = [9 x i8] c"fork err\00"
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str.1 = [18 x i8] c"cant catch SIGHUP\00"
@.str.2 = [16 x i8] c"cant fork twice\00"
@errno = global i32 0
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [16 x i8] c"cant chdir to /\00"
@RLIMIT_NOFILE = global i32 0
@.str.5 = [20 x i8] c"cant get getrlimit \00"
@RLIM_INFINITY = global i32 0
@.str.6 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@LOG_CONS = global i32 0
@LOG_DAEMON = global i32 0
@LOG_ERR = global i32 0
@.str.7 = [27 x i8] c"unexpected fds: %d, %d, %d\00"
@LOG_INFO = global i32 0
@.str.8 = [19 x i8] c"app(%s) daemonized\00"
define i32 @daemonize(i8* %0) {
%2 = alloca %struct.rlimit
%3 = alloca %struct.sigaction
%4 = bitcast %struct.rlimit* %2 to i8*
%5 = bitcast %struct.sigaction* %3 to i8*
%6 = tail call i32 @umask(i32 0)
%7 = tail call i64 (...) @fork()
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @err_sys(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %1
%12 = icmp eq i64 %7, 0
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %11, %9
%16 = tail call i32 (...) @setsid()
%17 = load i32, i32* @SIG_IGN
%18 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
%20 = call i32 @sigemptyset(i32* %19)
%21 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store i64 0, i64* %21
%22 = load i32, i32* @SIGHUP
%23 = call i64 @sigaction(i32 %22, %struct.sigaction* %3, i32* null)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %15
%26 = call i32 @err_sys(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %15
%28 = call i64 (...) @fork()
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @xlog(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @xlog(i8* %34)
br label %40
36: ; preds = %27
%37 = icmp eq i64 %28, 0
br i1 %37, label %40, label %38
38: ; preds = %36
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %36, %30
%41 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = load i32, i32* @RLIMIT_NOFILE
%47 = call i64 @getrlimit(i32 %46, %struct.rlimit* %2)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @err_sys(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
%52 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
%53 = load i32, i32* %52
%54 = load i32, i32* @RLIM_INFINITY
%55 = icmp eq i32 %53, %54
br i1 %55, label %56, label %57
56: ; preds = %51
store i32 1024, i32* %52
br label %59
57: ; preds = %51
%58 = icmp sgt i32 %53, 0
br i1 %58, label %59, label %66
59: ; preds = %56, %57
br label %60
60: ; preds = %59, %60
%61 = phi i32 [ %63, %60 ], [ 0, %59 ]
%62 = call i32 @close(i32 %61)
%63 = add nuw nsw i32 %61, 1
%64 = load i32, i32* %52
%65 = icmp slt i32 %63, %64
br i1 %65, label %60, label %66
66: ; preds = %60, %57
%67 = load i32, i32* @O_RDWR
%68 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %67)
%69 = call i32 @dup(i32 %68)
%70 = call i32 @dup(i32 %68)
%71 = load i32, i32* @LOG_CONS
%72 = load i32, i32* @LOG_DAEMON
%73 = call i32 @openlog(i8* %0, i32 %71, i32 %72)
%74 = icmp ne i32 %68, 0
%75 = icmp ne i32 %69, 1
%76 = select i1 %74, i1 true, i1 %75
%77 = icmp ne i32 %70, 2
%78 = select i1 %76, i1 true, i1 %77
br i1 %78, label %79, label %83
79: ; preds = %66
%80 = load i32, i32* @LOG_ERR
%81 = call i32 (i32, i8*, ...) @syslog(i32 %80, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %68, i32 %69, i32 %70)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %66
%84 = load i32, i32* @LOG_INFO
%85 = call i32 (i32, i8*, ...) @syslog(i32 %84, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%86 = call i64 @execl(i8* %0, i8* %0, i8* null)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %83
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %83
ret i32 0
}