#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 */

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIGTTIN;
int /*<<< orphan*/ SIGTTOU;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
void initDaemon() {
  if (fork() != 0) {
    exit(0);
  }
  setsid();
  signal(SIGINT, SIG_IGN);
  signal(SIGHUP, SIG_IGN);
  signal(SIGQUIT, SIG_IGN);
  signal(SIGPIPE, SIG_IGN);
  signal(SIGCHLD, SIG_IGN);
  signal(SIGTTOU, SIG_IGN);
  signal(SIGTTIN, SIG_IGN);
  signal(SIGTERM, SIG_IGN);
  signal(SIGKILL, SIG_IGN);
  if (fork() != 0) {
    exit(0);
  }
}


x86 assembly (clang, -O0):
<initDaemon>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
je     115c <initDaemon+0x1c>
xor    %edi,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1030 <setsid@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
je     124a <initDaemon+0x10a>
xor    %edi,%edi
call   1050 <exit@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<initDaemon>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jne    11fd <initDaemon+0xbd>
xor    %eax,%eax
call   1030 <setsid@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rbx
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1040 <signal@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jne    11fd <initDaemon+0xbd>
pop    %rbx
ret
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@SIGQUIT = global i32 0
@SIGPIPE = global i32 0
@SIGCHLD = global i32 0
@SIGTTOU = global i32 0
@SIGTTIN = global i32 0
@SIGTERM = global i32 0
@SIGKILL = global i32 0
define void @initDaemon() {
%1 = call i64 (...) @fork()
%2 = icmp ne i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = call i32 @exit(i32 0)
unreachable
5: ; preds = %0
%6 = call i32 (...) @setsid()
%7 = load i32, i32* @SIGINT
%8 = load i32, i32* @SIG_IGN
%9 = call i32 @signal(i32 %7, i32 %8)
%10 = load i32, i32* @SIGHUP
%11 = load i32, i32* @SIG_IGN
%12 = call i32 @signal(i32 %10, i32 %11)
%13 = load i32, i32* @SIGQUIT
%14 = load i32, i32* @SIG_IGN
%15 = call i32 @signal(i32 %13, i32 %14)
%16 = load i32, i32* @SIGPIPE
%17 = load i32, i32* @SIG_IGN
%18 = call i32 @signal(i32 %16, i32 %17)
%19 = load i32, i32* @SIGCHLD
%20 = load i32, i32* @SIG_IGN
%21 = call i32 @signal(i32 %19, i32 %20)
%22 = load i32, i32* @SIGTTOU
%23 = load i32, i32* @SIG_IGN
%24 = call i32 @signal(i32 %22, i32 %23)
%25 = load i32, i32* @SIGTTIN
%26 = load i32, i32* @SIG_IGN
%27 = call i32 @signal(i32 %25, i32 %26)
%28 = load i32, i32* @SIGTERM
%29 = load i32, i32* @SIG_IGN
%30 = call i32 @signal(i32 %28, i32 %29)
%31 = load i32, i32* @SIGKILL
%32 = load i32, i32* @SIG_IGN
%33 = call i32 @signal(i32 %31, i32 %32)
%34 = call i64 (...) @fork()
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %5
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %5
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@SIGQUIT = global i32 0
@SIGPIPE = global i32 0
@SIGCHLD = global i32 0
@SIGTTOU = global i32 0
@SIGTTIN = global i32 0
@SIGTERM = global i32 0
@SIGKILL = global i32 0
define void @initDaemon() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @exit(i32 0)
unreachable
5: ; preds = %0
%6 = tail call i32 (...) @setsid()
%7 = load i32, i32* @SIGINT
%8 = load i32, i32* @SIG_IGN
%9 = tail call i32 @signal(i32 %7, i32 %8)
%10 = load i32, i32* @SIGHUP
%11 = load i32, i32* @SIG_IGN
%12 = tail call i32 @signal(i32 %10, i32 %11)
%13 = load i32, i32* @SIGQUIT
%14 = load i32, i32* @SIG_IGN
%15 = tail call i32 @signal(i32 %13, i32 %14)
%16 = load i32, i32* @SIGPIPE
%17 = load i32, i32* @SIG_IGN
%18 = tail call i32 @signal(i32 %16, i32 %17)
%19 = load i32, i32* @SIGCHLD
%20 = load i32, i32* @SIG_IGN
%21 = tail call i32 @signal(i32 %19, i32 %20)
%22 = load i32, i32* @SIGTTOU
%23 = load i32, i32* @SIG_IGN
%24 = tail call i32 @signal(i32 %22, i32 %23)
%25 = load i32, i32* @SIGTTIN
%26 = load i32, i32* @SIG_IGN
%27 = tail call i32 @signal(i32 %25, i32 %26)
%28 = load i32, i32* @SIGTERM
%29 = load i32, i32* @SIG_IGN
%30 = tail call i32 @signal(i32 %28, i32 %29)
%31 = load i32, i32* @SIGKILL
%32 = load i32, i32* @SIG_IGN
%33 = tail call i32 @signal(i32 %31, i32 %32)
%34 = tail call i64 (...) @fork()
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %5
%37 = tail call i32 @exit(i32 0)
unreachable
38: ; preds = %5
ret void
}