#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;

/* Variables and functions */
int /*<<< orphan*/ ConfigureSignalHandlers();
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ LOG_DAEMON;
int /*<<< orphan*/ LOG_NOTICE;
int /*<<< orphan*/ LOG_PID;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ _SC_OPEN_MAX;
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int);
int dup(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setpgrp();
scalar_t__ setsid();
int /*<<< orphan*/ stderr;
char *strerror(int);
int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
void toDaemon(const char *PidFilePath) {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    syslog(LOG_NOTICE, "fork() 1 error %d: %s\n", errno, strerror(errno));
    fprintf(stderr, "fork() 1 error %d: %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (pid > 0)
    exit(EXIT_SUCCESS);
  if (setsid() < 0) {
    syslog(LOG_NOTICE, "setsid() error %d: %s\n", errno, strerror(errno));
    fprintf(stderr, "setsid() error %d: %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  pid = fork();
  if (pid < 0) {
    syslog(LOG_NOTICE, "fork() 2 error %d: %s\n", errno, strerror(errno));
    fprintf(stderr, "fork() 2 error %d: %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (pid > 0)
    exit(EXIT_SUCCESS);
  ConfigureSignalHandlers();
  umask(0);
  if (chdir("/")) {
    syslog(LOG_NOTICE, "chdir('/'), error %d: %s\n", errno, strerror(errno));
    fprintf(stderr, "chdir('/'), error %d: %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  int x;
  for (x = sysconf(_SC_OPEN_MAX); x > 0; x--) {
    close(x);
  }
  int tmp = open("/dev/null", O_RDWR);
  if (dup(tmp) == -1) {
    syslog(LOG_NOTICE, "dup(1), error %d: %s\n", errno, strerror(errno));
    fprintf(stderr, "dup(1), error %d: %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (dup(tmp) == -1) {
    syslog(LOG_NOTICE, "dup(2), error %d: %s\n", errno, strerror(errno));
    fprintf(stderr, "dup(2), error %d: %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  setpgrp();
  openlog("glonassd", LOG_PID, LOG_DAEMON);
}


x86 assembly (clang, -O0):
<toDaemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1299 <toDaemon+0xa9>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xdb5(%rip),%rsi
call   10a0 <syslog@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %rax,%rcx
lea    0xd7a(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    12b2 <toDaemon+0xc2>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1060 <setsid@plt>
cmp    $0x0,%rax
jge    1347 <toDaemon+0x157>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
lea    0xd1e(%rip),%rsi
call   10a0 <syslog@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xce3(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    13e1 <toDaemon+0x1f1>
mov    0x2c44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2c48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
lea    0xc9b(%rip),%rsi
call   10a0 <syslog@plt>
mov    0x2c21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
lea    0xc60(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    13fa <toDaemon+0x20a>
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1090 <ConfigureSignalHandlers@plt>
xor    %edi,%edi
call   1080 <umask@plt>
lea    0xc36(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     14a2 <toDaemon+0x2b2>
mov    0x2b83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2b87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%edx
mov    %rax,%rcx
lea    0xbf3(%rip),%rsi
call   10a0 <syslog@plt>
mov    0x2b60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2b40(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%edx
mov    %rax,%rcx
lea    0xbb8(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2b15(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
call   10c0 <sysconf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    14d3 <toDaemon+0x2e3>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    14b3 <toDaemon+0x2c3>
mov    0x2b0e(%rip),%rax
mov    (%rax),%esi
lea    0xb7e(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <dup@plt>
cmp    $0xffffffff,%eax
jne    1580 <toDaemon+0x390>
mov    0x2aa5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2aa9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2a9d(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    -0x64(%rbp),%edx
mov    %rax,%rcx
lea    0xb39(%rip),%rsi
call   10a0 <syslog@plt>
mov    0x2a82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2a6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2a62(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    -0x5c(%rbp),%edx
mov    %rax,%rcx
lea    0xafe(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2a37(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <dup@plt>
cmp    $0xffffffff,%eax
jne    1615 <toDaemon+0x425>
mov    0x2a10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2a14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2a08(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    -0x74(%rbp),%edx
mov    %rax,%rcx
lea    0xaba(%rip),%rsi
call   10a0 <syslog@plt>
mov    0x29ed(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x29d9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x29cd(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    -0x6c(%rbp),%edx
mov    %rax,%rcx
lea    0xa7f(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x29a2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1100 <setpgrp@plt>
mov    0x29a5(%rip),%rax
mov    (%rax),%esi
mov    0x29b4(%rip),%rax
mov    (%rax),%edx
lea    0xa62(%rip),%rdi
call   10d0 <openlog@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toDaemon>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
js     12f5 <toDaemon+0x105>
jne    12e7 <toDaemon+0xf7>
xor    %eax,%eax
call   1060 <setsid@plt>
test   %rax,%rax
js     131b <toDaemon+0x12b>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
js     1341 <toDaemon+0x151>
jne    12e7 <toDaemon+0xf7>
xor    %eax,%eax
call   1090 <ConfigureSignalHandlers@plt>
xor    %edi,%edi
call   1080 <umask@plt>
lea    0xdfd(%rip),%rdi
call   1030 <chdir@plt>
test   %rax,%rax
jne    1364 <toDaemon+0x174>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   10c0 <sysconf@plt>
test   %eax,%eax
jle    1281 <toDaemon+0x91>
mov    %eax,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <close@plt>
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
mov    %eax,%ebx
ja     1270 <toDaemon+0x80>
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
lea    0xdd0(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <dup@plt>
cmp    $0xffffffff,%eax
je     1387 <toDaemon+0x197>
mov    %ebx,%edi
call   1040 <dup@plt>
cmp    $0xffffffff,%eax
je     13aa <toDaemon+0x1ba>
xor    %eax,%eax
call   1100 <setpgrp@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
mov    0x2d11(%rip),%rax
mov    (%rax),%edx
lea    0xdbf(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <openlog@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%ebx
mov    0x2cb3(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
lea    0xcea(%rip),%r14
jmp    13cb <toDaemon+0x1db>
mov    0x2c86(%rip),%rax
mov    (%rax),%ebx
mov    0x2c8d(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
lea    0xcdb(%rip),%r14
jmp    13cb <toDaemon+0x1db>
mov    0x2c60(%rip),%rax
mov    (%rax),%ebx
mov    0x2c67(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
lea    0xccc(%rip),%r14
jmp    13cb <toDaemon+0x1db>
mov    0x2c3d(%rip),%rax
mov    (%rax),%ebx
mov    0x2c44(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
lea    0xcc2(%rip),%r14
jmp    13cb <toDaemon+0x1db>
mov    0x2c1a(%rip),%rax
mov    (%rax),%ebx
mov    0x2c21(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
lea    0xcc3(%rip),%r14
jmp    13cb <toDaemon+0x1db>
mov    0x2bf7(%rip),%rax
mov    (%rax),%ebx
mov    0x2bfe(%rip),%r15
mov    (%r15),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
lea    0xcb6(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
call   10a0 <syslog@plt>
mov    0x2bdf(%rip),%rax
mov    (%rax),%ebx
mov    (%r15),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@LOG_NOTICE = global i32 0
@.str = [23 x i8] c"fork() 1 error %d: %s\0A\00"
@errno = global i32 0
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [23 x i8] c"setsid() error %d: %s\0A\00"
@.str.2 = [23 x i8] c"fork() 2 error %d: %s\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [26 x i8] c"chdir('/'), error %d: %s\0A\00"
@_SC_OPEN_MAX = global i32 0
@.str.5 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.6 = [22 x i8] c"dup(1), error %d: %s\0A\00"
@.str.7 = [22 x i8] c"dup(2), error %d: %s\0A\00"
@.str.8 = [9 x i8] c"glonassd\00"
@LOG_PID = global i32 0
@LOG_DAEMON = global i32 0
define void @toDaemon(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i64 (...) @fork()
store i64 %6, i64* %3
%7 = load i64, i64* %3
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %1
%10 = load i32, i32* @LOG_NOTICE
%11 = load i32, i32* @errno
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @syslog(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %13)
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %1
%23 = load i64, i64* %3
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @EXIT_SUCCESS
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %22
%29 = call i64 (...) @setsid()
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %44
31: ; preds = %28
%32 = load i32, i32* @LOG_NOTICE
%33 = load i32, i32* @errno
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @syslog(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %35)
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %28
%45 = call i64 (...) @fork()
store i64 %45, i64* %3
%46 = load i64, i64* %3
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %44
%49 = load i32, i32* @LOG_NOTICE
%50 = load i32, i32* @errno
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 @syslog(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %50, i8* %52)
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %55, i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %44
%62 = load i64, i64* %3
%63 = icmp sgt i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* @EXIT_SUCCESS
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %61
%68 = call i32 (...) @ConfigureSignalHandlers()
%69 = call i32 @umask(i32 0)
%70 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %85
72: ; preds = %67
%73 = load i32, i32* @LOG_NOTICE
%74 = load i32, i32* @errno
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 @syslog(i32 %73, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %74, i8* %76)
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %79, i8* %81)
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %67
%86 = load i32, i32* @_SC_OPEN_MAX
%87 = call i32 @sysconf(i32 %86)
store i32 %87, i32* %4
br label %88
88: ; preds = %94, %85
%89 = load i32, i32* %4
%90 = icmp sgt i32 %89, 0
br i1 %90, label %91, label %97
91: ; preds = %88
%92 = load i32, i32* %4
%93 = call i32 @close(i32 %92)
br label %94
94: ; preds = %91
%95 = load i32, i32* %4
%96 = add nsw i32 %95, -1
store i32 %96, i32* %4
br label %88
97: ; preds = %88
%98 = load i32, i32* @O_RDWR
%99 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %98)
store i32 %99, i32* %5
%100 = load i32, i32* %5
%101 = call i32 @dup(i32 %100)
%102 = icmp eq i32 %101, -1
br i1 %102, label %103, label %116
103: ; preds = %97
%104 = load i32, i32* @LOG_NOTICE
%105 = load i32, i32* @errno
%106 = load i32, i32* @errno
%107 = call i8* @strerror(i32 %106)
%108 = call i32 @syslog(i32 %104, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %105, i8* %107)
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 @fprintf(i32 %109, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %110, i8* %112)
%114 = load i32, i32* @EXIT_FAILURE
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %97
%117 = load i32, i32* %5
%118 = call i32 @dup(i32 %117)
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %133
120: ; preds = %116
%121 = load i32, i32* @LOG_NOTICE
%122 = load i32, i32* @errno
%123 = load i32, i32* @errno
%124 = call i8* @strerror(i32 %123)
%125 = call i32 @syslog(i32 %121, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %122, i8* %124)
%126 = load i32, i32* @stderr
%127 = load i32, i32* @errno
%128 = load i32, i32* @errno
%129 = call i8* @strerror(i32 %128)
%130 = call i32 @fprintf(i32 %126, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %127, i8* %129)
%131 = load i32, i32* @EXIT_FAILURE
%132 = call i32 @exit(i32 %131)
unreachable
133: ; preds = %116
%134 = call i32 (...) @setpgrp()
%135 = load i32, i32* @LOG_PID
%136 = load i32, i32* @LOG_DAEMON
%137 = call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %135, i32 %136)
ret void
}

LLVM IR (-O2):
@LOG_NOTICE = global i32 0
@.str = [23 x i8] c"fork() 1 error %d: %s\0A\00"
@errno = global i32 0
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [23 x i8] c"setsid() error %d: %s\0A\00"
@.str.2 = [23 x i8] c"fork() 2 error %d: %s\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [26 x i8] c"chdir('/'), error %d: %s\0A\00"
@_SC_OPEN_MAX = global i32 0
@.str.5 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.6 = [22 x i8] c"dup(1), error %d: %s\0A\00"
@.str.7 = [22 x i8] c"dup(2), error %d: %s\0A\00"
@.str.8 = [9 x i8] c"glonassd\00"
@LOG_PID = global i32 0
@LOG_DAEMON = global i32 0
define void @toDaemon(i8* nocapture readnone %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = load i32, i32* @LOG_NOTICE
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @syslog(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %7)
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = icmp eq i64 %2, 0
br i1 %16, label %20, label %17
17: ; preds = %15
%18 = load i32, i32* @EXIT_SUCCESS
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %15
%21 = tail call i64 (...) @setsid()
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %20
%24 = load i32, i32* @LOG_NOTICE
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 @syslog(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %26)
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %29, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %20
%35 = tail call i64 (...) @fork()
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = load i32, i32* @LOG_NOTICE
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 @syslog(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %39, i8* %40)
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = tail call i8* @strerror(i32 %43)
%45 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %43, i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %34
%49 = icmp eq i64 %35, 0
br i1 %49, label %53, label %50
50: ; preds = %48
%51 = load i32, i32* @EXIT_SUCCESS
%52 = tail call i32 @exit(i32 %51)
unreachable
53: ; preds = %48
%54 = tail call i32 (...) @ConfigureSignalHandlers()
%55 = tail call i32 @umask(i32 0)
%56 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %69, label %58
58: ; preds = %53
%59 = load i32, i32* @LOG_NOTICE
%60 = load i32, i32* @errno
%61 = tail call i8* @strerror(i32 %60)
%62 = tail call i32 @syslog(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %60, i8* %61)
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = tail call i8* @strerror(i32 %64)
%66 = tail call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %64, i8* %65)
%67 = load i32, i32* @EXIT_FAILURE
%68 = tail call i32 @exit(i32 %67)
unreachable
69: ; preds = %53
%70 = load i32, i32* @_SC_OPEN_MAX
%71 = tail call i32 @sysconf(i32 %70)
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %69, %73
%74 = phi i32 [ %76, %73 ], [ %71, %69 ]
%75 = tail call i32 @close(i32 %74)
%76 = add nsw i32 %74, -1
%77 = icmp ugt i32 %74, 1
br i1 %77, label %73, label %78
78: ; preds = %73, %69
%79 = load i32, i32* @O_RDWR
%80 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %79)
%81 = tail call i32 @dup(i32 %80)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %94
83: ; preds = %78
%84 = load i32, i32* @LOG_NOTICE
%85 = load i32, i32* @errno
%86 = tail call i8* @strerror(i32 %85)
%87 = tail call i32 @syslog(i32 %84, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %85, i8* %86)
%88 = load i32, i32* @stderr
%89 = load i32, i32* @errno
%90 = tail call i8* @strerror(i32 %89)
%91 = tail call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %89, i8* %90)
%92 = load i32, i32* @EXIT_FAILURE
%93 = tail call i32 @exit(i32 %92)
unreachable
94: ; preds = %78
%95 = tail call i32 @dup(i32 %80)
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %108
97: ; preds = %94
%98 = load i32, i32* @LOG_NOTICE
%99 = load i32, i32* @errno
%100 = tail call i8* @strerror(i32 %99)
%101 = tail call i32 @syslog(i32 %98, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %99, i8* %100)
%102 = load i32, i32* @stderr
%103 = load i32, i32* @errno
%104 = tail call i8* @strerror(i32 %103)
%105 = tail call i32 @fprintf(i32 %102, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %103, i8* %104)
%106 = load i32, i32* @EXIT_FAILURE
%107 = tail call i32 @exit(i32 %106)
unreachable
108: ; preds = %94
%109 = tail call i32 (...) @setpgrp()
%110 = load i32, i32* @LOG_PID
%111 = load i32, i32* @LOG_DAEMON
%112 = tail call i32 @openlog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %110, i32 %111)
ret void
}