#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 /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *, ...);
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*/ printids(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 /*<<< orphan*/ umask(int /*<<< orphan*/);
void daemonize(char const *cmd) {
  int i, fd0, fd1, fd2;
  pid_t pid;
  struct rlimit rl;
  struct sigaction sa;
  umask(0);
  printids("after umask      ");
  if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
    err_quit("%s: can't get file limit", cmd);
  if ((pid = fork()) < 0)
    err_quit("%s: can't fork", cmd);
  else if (pid != 0) {
    printids("after fork p1    ");
    exit(0);
  }
  printids("after fork c1    ");
  setsid();
  printids("after setsid     ");
  sa.sa_handler = SIG_IGN;
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  if (sigaction(SIGHUP, &sa, NULL) < 0)
    err_quit("%s: can't ignore SIGHUP");
  if ((pid = fork()) < 0)
    err_quit("%s: can't fork", cmd);
  else if (pid != 0) {
    printids("after fork p2    ");
    exit(0);
  }
  printids("after fork c2    ");
  if (chdir("/") < 0)
    err_quit("%s: can't change directory to /");
  syslog(LOG_INFO, "rlimit max files: %ld\n", rl.rlim_max);
  if (rl.rlim_max == RLIM_INFINITY)
    rl.rlim_max = 1024;
  syslog(LOG_INFO, "rlimit max files: %ld\n", rl.rlim_max);
  for (i = 0; i < rl.rlim_max; ++i)
    close(i);
  fd0 = open("/dev/null", O_RDWR);
  fd1 = dup(0);
  fd2 = dup(0);
  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);
  }
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xor    %edi,%edi
call   10a0 <umask@plt>
lea    0xdf6(%rip),%rdi
call   10c0 <printids@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1100 <getrlimit@plt>
cmp    $0x0,%rax
jge    123d <daemonize+0x4d>
mov    -0x8(%rbp),%rsi
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1080 <err_quit@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1269 <daemonize+0x79>
mov    -0x8(%rbp),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1080 <err_quit@plt>
jmp    128c <daemonize+0x9c>
cmpq   $0x0,-0x20(%rbp)
je     1287 <daemonize+0x97>
lea    0xdbf(%rip),%rdi
call   10c0 <printids@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    128c <daemonize+0x9c>
lea    0xdb9(%rip),%rdi
call   10c0 <printids@plt>
mov    $0x0,%al
call   1070 <setsid@plt>
lea    0xdb8(%rip),%rdi
call   10c0 <printids@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x38(%rbp),%rdi
add    $0x8,%rdi
call   1090 <sigemptyset@plt>
movq   $0x0,-0x38(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0x0,%rax
jge    12fa <daemonize+0x10a>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1080 <err_quit@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1326 <daemonize+0x136>
mov    -0x8(%rbp),%rsi
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1080 <err_quit@plt>
jmp    1349 <daemonize+0x159>
cmpq   $0x0,-0x20(%rbp)
je     1344 <daemonize+0x154>
lea    0xd50(%rip),%rdi
call   10c0 <printids@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    1349 <daemonize+0x159>
lea    0xd4a(%rip),%rdi
call   10c0 <printids@plt>
lea    0xd6e(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jge    1379 <daemonize+0x189>
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1080 <err_quit@plt>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
mov    -0x28(%rbp),%eax
mov    0x2c13(%rip),%rcx
cmp    (%rcx),%eax
jne    13ac <daemonize+0x1bc>
movl   $0x400,-0x28(%rbp)
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13ef <daemonize+0x1ff>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    13cd <daemonize+0x1dd>
mov    0x2bea(%rip),%rax
mov    (%rax),%esi
lea    0xce4(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x10(%rbp)
xor    %edi,%edi
call   1050 <dup@plt>
mov    %eax,-0x14(%rbp)
xor    %edi,%edi
call   1050 <dup@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2b92(%rip),%rax
mov    (%rax),%esi
mov    0x2ba9(%rip),%rax
mov    (%rax),%edx
call   10e0 <openlog@plt>
cmpl   $0x0,-0x10(%rbp)
jne    1454 <daemonize+0x264>
cmpl   $0x1,-0x14(%rbp)
jne    1454 <daemonize+0x264>
cmpl   $0x2,-0x18(%rbp)
je     147f <daemonize+0x28f>
mov    0x2b3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xc7f(%rip),%rsi
mov    $0x0,%al
call   10b0 <syslog@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
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   10a0 <umask@plt>
lea    0xdf5(%rip),%rdi
call   10c0 <printids@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1100 <getrlimit@plt>
test   %rax,%rax
jns    1237 <daemonize+0x47>
lea    0xde5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <err_quit@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
js     1251 <daemonize+0x61>
je     1262 <daemonize+0x72>
lea    0xdee(%rip),%rdi
jmp    12de <daemonize+0xee>
lea    0xdd3(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <err_quit@plt>
lea    0xde3(%rip),%rdi
call   10c0 <printids@plt>
xor    %eax,%eax
call   1070 <setsid@plt>
lea    0xde2(%rip),%rdi
call   10c0 <printids@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rdi
call   1090 <sigemptyset@plt>
movq   $0x0,0x8(%rsp)
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
test   %rax,%rax
jns    12c9 <daemonize+0xd9>
lea    0xdae(%rip),%rdi
xor    %eax,%eax
call   1080 <err_quit@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
js     12ea <daemonize+0xfa>
je     12fb <daemonize+0x10b>
lea    0xdaa(%rip),%rdi
call   10c0 <printids@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xd3a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <err_quit@plt>
lea    0xd98(%rip),%rdi
call   10c0 <printids@plt>
lea    0xdbc(%rip),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
jns    1326 <daemonize+0x136>
lea    0xd8d(%rip),%rdi
xor    %eax,%eax
call   1080 <err_quit@plt>
mov    0x2c7b(%rip),%rbx
mov    (%rbx),%edi
mov    (%rsp),%edx
lea    0xd93(%rip),%rsi
xor    %eax,%eax
call   10b0 <syslog@plt>
mov    (%rsp),%edx
mov    0x2c66(%rip),%rax
cmp    (%rax),%edx
jne    135a <daemonize+0x16a>
movl   $0x400,(%rsp)
mov    $0x400,%edx
mov    (%rbx),%edi
lea    0xd69(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <syslog@plt>
cmpl   $0x0,(%rsp)
jle    138f <daemonize+0x19f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     1380 <daemonize+0x190>
mov    0x2c4a(%rip),%rax
mov    (%rax),%esi
lea    0xd44(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,%r15d
xor    %edi,%edi
call   1050 <dup@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1050 <dup@plt>
mov    %eax,%ebp
mov    0x2bf8(%rip),%rax
mov    (%rax),%esi
mov    0x2c0f(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   10e0 <openlog@plt>
test   %r15d,%r15d
jne    13ed <daemonize+0x1fd>
cmp    $0x1,%ebx
jne    13ed <daemonize+0x1fd>
cmp    $0x2,%ebp
jne    13ed <daemonize+0x1fd>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ba4(%rip),%rax
mov    (%rax),%edi
lea    0xcf0(%rip),%rsi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   10b0 <syslog@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

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

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