#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTTIN;
int /*<<< orphan*/ SIGTTOU;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
void InitDaemon() {
  pid_t pid;
  if ((pid = fork()) != 0)
    exit(0);
  setpgid(0, 0);
  signal(SIGINT, SIG_IGN);
  signal(SIGHUP, SIG_IGN);
  signal(SIGQUIT, SIG_IGN);
  signal(SIGPIPE, SIG_IGN);
  signal(SIGTTOU, SIG_IGN);
  signal(SIGTTIN, SIG_IGN);
  signal(SIGCHLD, SIG_IGN);
  if ((pid = fork()) != 0)
    exit(0);
  umask(0);
}


x86 assembly (clang, -O0):
<InitDaemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     1172 <InitDaemon+0x22>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1050 <setpgid@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
call   1030 <signal@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     1236 <InitDaemon+0xe6>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1040 <umask@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InitDaemon>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    11f3 <InitDaemon+0xa3>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <setpgid@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    0x2e3f(%rip),%rbx
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   1030 <signal@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    11f3 <InitDaemon+0xa3>
xor    %edi,%edi
pop    %rbx
jmp    1040 <umask@plt>
xor    %edi,%edi
call   1060 <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
@SIGTTOU = global i32 0
@SIGTTIN = global i32 0
@SIGCHLD = global i32 0
define void @InitDaemon() {
%1 = alloca i32
%2 = call i32 (...) @fork()
store i32 %2, i32* %1
%3 = icmp ne i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @exit(i32 0)
unreachable
6: ; preds = %0
%7 = call i32 @setpgid(i32 0, i32 0)
%8 = load i32, i32* @SIGINT
%9 = load i32, i32* @SIG_IGN
%10 = call i32 @signal(i32 %8, i32 %9)
%11 = load i32, i32* @SIGHUP
%12 = load i32, i32* @SIG_IGN
%13 = call i32 @signal(i32 %11, i32 %12)
%14 = load i32, i32* @SIGQUIT
%15 = load i32, i32* @SIG_IGN
%16 = call i32 @signal(i32 %14, i32 %15)
%17 = load i32, i32* @SIGPIPE
%18 = load i32, i32* @SIG_IGN
%19 = call i32 @signal(i32 %17, i32 %18)
%20 = load i32, i32* @SIGTTOU
%21 = load i32, i32* @SIG_IGN
%22 = call i32 @signal(i32 %20, i32 %21)
%23 = load i32, i32* @SIGTTIN
%24 = load i32, i32* @SIG_IGN
%25 = call i32 @signal(i32 %23, i32 %24)
%26 = load i32, i32* @SIGCHLD
%27 = load i32, i32* @SIG_IGN
%28 = call i32 @signal(i32 %26, i32 %27)
%29 = call i32 (...) @fork()
store i32 %29, i32* %1
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %6
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %6
%34 = call i32 @umask(i32 0)
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
@SIGTTOU = global i32 0
@SIGTTIN = global i32 0
@SIGCHLD = global i32 0
define void @InitDaemon() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %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 @setpgid(i32 0, i32 0)
%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* @SIGTTOU
%20 = load i32, i32* @SIG_IGN
%21 = tail call i32 @signal(i32 %19, i32 %20)
%22 = load i32, i32* @SIGTTIN
%23 = load i32, i32* @SIG_IGN
%24 = tail call i32 @signal(i32 %22, i32 %23)
%25 = load i32, i32* @SIGCHLD
%26 = load i32, i32* @SIG_IGN
%27 = tail call i32 @signal(i32 %25, i32 %26)
%28 = tail call i32 (...) @fork()
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %5
%31 = tail call i32 @exit(i32 0)
unreachable
32: ; preds = %5
%33 = tail call i32 @umask(i32 0)
ret void
}