#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ setsid();
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int daemon_initalizer() {
  pid_t pid;
  pid_t sid;
  pid = fork();
  if (pid < 0) {
    syslog(LOG_ERR, "floded child process unable to be forked -- exiting...");
    exit(EXIT_FAILURE);
  }
  if (pid > 0) {
    exit(EXIT_SUCCESS);
  }
  umask(0);
  sid = setsid();
  if (sid < 0) {
    syslog(LOG_ERR, "floded child process unable to obtain proper session ID "
                    "-- exiting...");
    exit(EXIT_FAILURE);
  }
  if (chdir("/") < 0) {
    syslog(
        LOG_ERR,
        "floded child process unable to change directories to / -- exiting...");
    exit(EXIT_FAILURE);
  }
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  return 0;
}


x86 assembly (clang, -O0):
<daemon_initalizer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    11b1 <daemon_initalizer+0x41>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1070 <syslog@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
jle    11ca <daemon_initalizer+0x5a>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1060 <umask@plt>
mov    $0x0,%al
call   1050 <setsid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    120a <daemon_initalizer+0x9a>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1070 <syslog@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe6c(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    1243 <daemon_initalizer+0xd3>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1070 <syslog@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemon_initalizer>:
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11d1 <daemon_initalizer+0x61>
jne    11e3 <daemon_initalizer+0x73>
xor    %edi,%edi
call   1060 <umask@plt>
xor    %eax,%eax
call   1050 <setsid@plt>
test   %rax,%rax
js     11f1 <daemon_initalizer+0x81>
lea    0xee4(%rip),%rdi
call   1030 <chdir@plt>
test   %rax,%rax
js     1203 <daemon_initalizer+0x93>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
jmp    1213 <daemon_initalizer+0xa3>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
jmp    1213 <daemon_initalizer+0xa3>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1070 <syslog@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [55 x i8] c"floded child process unable to be forked -- exiting...\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [70 x i8] c"floded child process unable to obtain proper session ID -- exiting...\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [69 x i8] c"floded child process unable to change directories to / -- exiting...\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @daemon_initalizer() {
%1 = alloca i64
%2 = alloca i64
%3 = call i64 (...) @fork()
store i64 %3, i64* %1
%4 = load i64, i64* %1
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @LOG_ERR
%8 = call i32 @syslog(i32 %7, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i64, i64* %1
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @EXIT_SUCCESS
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %11
%18 = call i32 @umask(i32 0)
%19 = call i64 (...) @setsid()
store i64 %19, i64* %2
%20 = load i64, i64* %2
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @LOG_ERR
%24 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %17
%28 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* @LOG_ERR
%32 = call i32 @syslog(i32 %31, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %27
%36 = load i32, i32* @STDIN_FILENO
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* @STDOUT_FILENO
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* @STDERR_FILENO
%41 = call i32 @close(i32 %40)
ret i32 0
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [55 x i8] c"floded child process unable to be forked -- exiting...\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.1 = [70 x i8] c"floded child process unable to obtain proper session ID -- exiting...\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [69 x i8] c"floded child process unable to change directories to / -- exiting...\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @daemon_initalizer() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %8
3: ; preds = %0
%4 = load i32, i32* @LOG_ERR
%5 = tail call i32 @syslog(i32 %4, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = icmp eq i64 %1, 0
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = load i32, i32* @EXIT_SUCCESS
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %8
%14 = tail call i32 @umask(i32 0)
%15 = tail call i64 (...) @setsid()
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* @LOG_ERR
%19 = tail call i32 @syslog(i32 %18, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @LOG_ERR
%27 = tail call i32 @syslog(i32 %26, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = load i32, i32* @STDIN_FILENO
%32 = tail call i32 @close(i32 %31)
%33 = load i32, i32* @STDOUT_FILENO
%34 = tail call i32 @close(i32 %33)
%35 = load i32, i32* @STDERR_FILENO
%36 = tail call i32 @close(i32 %35)
ret i32 0
}