#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ chdir(char *);
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ daemon_init();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ setsid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid, sid;
  pid = fork();
  if (pid < 0) {
    exit(EXIT_FAILURE);
  }
  if (pid > 0) {
    exit(EXIT_SUCCESS);
  }
  umask(0);
  sid = setsid();
  if (sid < 0) {
    exit(EXIT_FAILURE);
  }
  if ((chdir("/")) < 0) {
    exit(EXIT_FAILURE);
  }
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  daemon_init();
  while (1) {
    sleep(30);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11ba <main+0x3a>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jle    11d3 <main+0x53>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1070 <umask@plt>
mov    $0x0,%al
call   1050 <setsid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11fe <main+0x7e>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdfb(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    1222 <main+0xa2>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    $0x0,%al
call   1060 <daemon_init@plt>
mov    $0x1e,%edi
call   1090 <sleep@plt>
jmp    1253 <main+0xd3>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     11fc <main+0x7c>
jne    120a <main+0x8a>
xor    %edi,%edi
call   1070 <umask@plt>
xor    %eax,%eax
call   1050 <setsid@plt>
test   %rax,%rax
js     11fc <main+0x7c>
lea    0xe57(%rip),%rdi
call   1030 <chdir@plt>
test   %rax,%rax
js     11fc <main+0x7c>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
xor    %eax,%eax
call   1060 <daemon_init@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1e,%edi
call   1090 <sleep@plt>
jmp    11f0 <main+0x70>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str = [2 x i8] c"/\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i64, i64* %6
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @EXIT_SUCCESS
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %14
%21 = call i32 @umask(i32 0)
%22 = call i64 (...) @setsid()
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %20
%29 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %28
%35 = load i32, i32* @STDIN_FILENO
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* @STDOUT_FILENO
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* @STDERR_FILENO
%40 = call i32 @close(i32 %39)
%41 = call i32 (...) @daemon_init()
br label %42
42: ; preds = %34, %42
%43 = call i32 @sleep(i32 30)
br label %42
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@.str = [2 x i8] c"/\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = icmp eq i64 %3, 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 %20
17: ; preds = %13
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
%21 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %20
%27 = load i32, i32* @STDIN_FILENO
%28 = tail call i32 @close(i32 %27)
%29 = load i32, i32* @STDOUT_FILENO
%30 = tail call i32 @close(i32 %29)
%31 = load i32, i32* @STDERR_FILENO
%32 = tail call i32 @close(i32 %31)
%33 = tail call i32 (...) @daemon_init()
br label %34
34: ; preds = %34, %26
%35 = tail call i32 @sleep(i32 30)
br label %34
}