#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ LOG_CONS;
int /*<<< orphan*/ LOG_DAEMON;
int /*<<< orphan*/ LOG_ERR;
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*/ exit(int);
scalar_t__ fork();
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ openlog(char const *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setsid();
scalar_t__ sigaction(int /*<<< orphan*/, struct sigaction *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, int, int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int daemonize(int nochdir, int noclose, const char *cmd) {
  umask(0);
  struct rlimit rl;
  if (getrlimit(RLIMIT_NOFILE, &rl) < 0) {
    do {
      perror("cann't get file limit");
      exit(EXIT_FAILURE);
    } while (0);
  }
  pid_t pid;
  if ((pid = fork()) < 0) {
    do {
      perror("fork error");
      exit(EXIT_FAILURE);
    } while (0);
  } else if (pid != 0) {
    exit(EXIT_SUCCESS);
  }
  setsid();
  struct sigaction sa;
  sa.sa_handler = SIG_IGN;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  if (sigaction(SIGHUP, &sa, NULL) < 0) {
    do {
      perror("cann't ignore SIGHUP");
      exit(EXIT_FAILURE);
    } while (0);
  }
  if ((pid = fork()) < 0) {
    do {
      perror("cann't fork");
      exit(EXIT_FAILURE);
    } while (0);
  } else if (pid != 0) {
    exit(EXIT_SUCCESS);
  }
  if (nochdir == 0) {
    if (chdir("/") < 0) {
      do {
        perror("can't change directory to /");
        exit(EXIT_FAILURE);
      } while (0);
    }
  }
  if (noclose == 0) {
    if (rl.rlim_max == RLIM_INFINITY) {
      rl.rlim_max = 1024;
    }
    for (int i = 0; i < rl.rlim_max; ++i) {
      close(i);
    }
  }
  int fd0 = open("/dev/null", O_RDWR);
  int fd1 = dup(fd0);
  int fd2 = dup(fd0);
  openlog(cmd, LOG_CONS, LOG_DAEMON);
  if (fd0 != 0 || fd1 != 1 || fd2 != 2) {
    syslog(LOG_ERR, "unexpected file descriptors %d %d %d", fd0, fd1, fd2);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
xor    %edi,%edi
call   1090 <umask@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   10f0 <getrlimit@plt>
cmp    $0x0,%rax
jge    1234 <daemonize+0x54>
jmp    121a <daemonize+0x3a>
lea    0xddf(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1268 <daemonize+0x88>
jmp    124e <daemonize+0x6e>
lea    0xdc1(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
je     1281 <daemonize+0xa1>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    1286 <daemonize+0xa6>
mov    $0x0,%al
call   1070 <setsid@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
call   1080 <sigemptyset@plt>
movq   $0x0,-0x30(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    12ed <daemonize+0x10d>
jmp    12d3 <daemonize+0xf3>
lea    0xd47(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1321 <daemonize+0x141>
jmp    1307 <daemonize+0x127>
lea    0xd28(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
je     133a <daemonize+0x15a>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    133f <daemonize+0x15f>
cmpl   $0x0,-0x4(%rbp)
jne    1383 <daemonize+0x1a3>
lea    0xd0c(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jge    137e <daemonize+0x19e>
jmp    1364 <daemonize+0x184>
lea    0xcd7(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    1383 <daemonize+0x1a3>
cmpl   $0x0,-0x8(%rbp)
jne    13d4 <daemonize+0x1f4>
mov    -0x18(%rbp),%eax
mov    0x2c11(%rip),%rcx
cmp    (%rcx),%eax
jne    13a6 <daemonize+0x1c6>
movl   $0x400,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13cf <daemonize+0x1ef>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    13ad <daemonize+0x1cd>
jmp    13d4 <daemonize+0x1f4>
mov    0x2c05(%rip),%rax
mov    (%rax),%esi
lea    0xc7a(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1050 <dup@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
call   1050 <dup@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2bab(%rip),%rax
mov    (%rax),%esi
mov    0x2bc2(%rip),%rax
mov    (%rax),%edx
call   10d0 <openlog@plt>
cmpl   $0x0,-0x38(%rbp)
jne    143b <daemonize+0x25b>
cmpl   $0x1,-0x3c(%rbp)
jne    143b <daemonize+0x25b>
cmpl   $0x2,-0x40(%rbp)
je     1464 <daemonize+0x284>
mov    0x2b4e(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
lea    0xc13(%rip),%rsi
call   10a0 <syslog@plt>
mov    $0x1,%edi
call   10e0 <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    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
xor    %edi,%edi
call   1090 <umask@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   10f0 <getrlimit@plt>
test   %rax,%rax
js     133d <daemonize+0x15d>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     1346 <daemonize+0x166>
jne    132f <daemonize+0x14f>
xor    %eax,%eax
call   1070 <setsid@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rdi
call   1080 <sigemptyset@plt>
movq   $0x0,0x8(%rsp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
js     134f <daemonize+0x16f>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     1358 <daemonize+0x178>
jne    132f <daemonize+0x14f>
test   %ebx,%ebx
jne    129c <daemonize+0xbc>
lea    0xdce(%rip),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
js     1388 <daemonize+0x1a8>
test   %ebp,%ebp
jne    12cf <daemonize+0xef>
mov    (%rsp),%eax
mov    0x2cfe(%rip),%rcx
cmp    (%rcx),%eax
jne    12b7 <daemonize+0xd7>
movl   $0x400,(%rsp)
jmp    12bb <daemonize+0xdb>
test   %eax,%eax
jle    12cf <daemonize+0xef>
xor    %ebx,%ebx
nopl   (%rax)
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     12c0 <daemonize+0xe0>
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
lea    0xd7f(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <dup@plt>
mov    %eax,%r15d
mov    %ebx,%edi
call   1050 <dup@plt>
mov    %eax,%ebp
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
mov    0x2ccf(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   10d0 <openlog@plt>
test   %ebx,%ebx
jne    1361 <daemonize+0x181>
cmp    $0x1,%r15d
jne    1361 <daemonize+0x181>
cmp    $0x2,%ebp
jne    1361 <daemonize+0x181>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xcbc(%rip),%rdi
jmp    138f <daemonize+0x1af>
lea    0xcc9(%rip),%rdi
jmp    138f <daemonize+0x1af>
lea    0xccb(%rip),%rdi
jmp    138f <daemonize+0x1af>
lea    0xcd7(%rip),%rdi
jmp    138f <daemonize+0x1af>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
lea    0xcf7(%rip),%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
call   10a0 <syslog@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xcb3(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i32 }
%struct.sigaction = type { i64, i32, i32 }
@RLIMIT_NOFILE = global i32 0
@.str = [22 x i8] c"cann't get file limit\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"fork error\00"
@EXIT_SUCCESS = global i32 0
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str.2 = [21 x i8] c"cann't ignore SIGHUP\00"
@.str.3 = [12 x i8] c"cann't fork\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [28 x i8] c"can't change directory to /\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 = [37 x i8] c"unexpected file descriptors %d %d %d\00"
define i32 @daemonize(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.rlimit
%8 = alloca i64
%9 = alloca %struct.sigaction
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%14 = call i32 @umask(i32 0)
%15 = load i32, i32* @RLIMIT_NOFILE
%16 = call i64 @getrlimit(i32 %15, %struct.rlimit* %7)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %3
br label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %3
%25 = call i64 (...) @fork()
store i64 %25, i64* %8
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
br label %28
28: ; preds = %27
%29 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; No predecessors!
br label %40
33: ; preds = %24
%34 = load i64, i64* %8
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %33
br label %40
40: ; preds = %39, %32
%41 = call i32 (...) @setsid()
%42 = load i32, i32* @SIG_IGN
%43 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 2
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 1
%45 = call i32 @sigemptyset(i32* %44)
%46 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 0
store i64 0, i64* %46
%47 = load i32, i32* @SIGHUP
%48 = call i64 @sigaction(i32 %47, %struct.sigaction* %9, i32* null)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %40
br label %51
51: ; preds = %50
%52 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; No predecessors!
br label %56
56: ; preds = %55, %40
%57 = call i64 (...) @fork()
store i64 %57, i64* %8
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %56
br label %60
60: ; preds = %59
%61 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; No predecessors!
br label %72
65: ; preds = %56
%66 = load i64, i64* %8
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* @EXIT_SUCCESS
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %65
br label %72
72: ; preds = %71, %64
%73 = load i32, i32* %4
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %72
%76 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %84
78: ; preds = %75
br label %79
79: ; preds = %78
%80 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; No predecessors!
br label %84
84: ; preds = %83, %75
br label %85
85: ; preds = %84, %72
%86 = load i32, i32* %5
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %108
88: ; preds = %85
%89 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 0
%90 = load i32, i32* %89
%91 = load i32, i32* @RLIM_INFINITY
%92 = icmp eq i32 %90, %91
br i1 %92, label %93, label %95
93: ; preds = %88
%94 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 0
store i32 1024, i32* %94
br label %95
95: ; preds = %93, %88
store i32 0, i32* %10
br label %96
96: ; preds = %104, %95
%97 = load i32, i32* %10
%98 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 0
%99 = load i32, i32* %98
%100 = icmp slt i32 %97, %99
br i1 %100, label %101, label %107
101: ; preds = %96
%102 = load i32, i32* %10
%103 = call i32 @close(i32 %102)
br label %104
104: ; preds = %101
%105 = load i32, i32* %10
%106 = add nsw i32 %105, 1
store i32 %106, i32* %10
br label %96
107: ; preds = %96
br label %108
108: ; preds = %107, %85
%109 = load i32, i32* @O_RDWR
%110 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %109)
store i32 %110, i32* %11
%111 = load i32, i32* %11
%112 = call i32 @dup(i32 %111)
store i32 %112, i32* %12
%113 = load i32, i32* %11
%114 = call i32 @dup(i32 %113)
store i32 %114, i32* %13
%115 = load i8*, i8** %6
%116 = load i32, i32* @LOG_CONS
%117 = load i32, i32* @LOG_DAEMON
%118 = call i32 @openlog(i8* %115, i32 %116, i32 %117)
%119 = load i32, i32* %11
%120 = icmp ne i32 %119, 0
br i1 %120, label %127, label %121
121: ; preds = %108
%122 = load i32, i32* %12
%123 = icmp ne i32 %122, 1
br i1 %123, label %127, label %124
124: ; preds = %121
%125 = load i32, i32* %13
%126 = icmp ne i32 %125, 2
br i1 %126, label %127, label %134
127: ; preds = %124, %121, %108
%128 = load i32, i32* @LOG_ERR
%129 = load i32, i32* %11
%130 = load i32, i32* %12
%131 = load i32, i32* %13
%132 = call i32 @syslog(i32 %128, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i32 %129, i32 %130, i32 %131)
%133 = call i32 @exit(i32 1)
unreachable
134: ; preds = %124
ret i32 0
}

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