#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*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
void make_daemon() {
  pid_t rc;
  signal(SIGHUP, SIG_IGN);
  rc = fork();
  if (rc == 0) {
    chdir("/");
    close(0);
    close(1);
    close(2);
    setsid();
  } else {
    exit(0);
  }
}


x86 assembly (clang, -O0):
<make_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c8 <make_daemon+0x68>
lea    0xe64(%rip),%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    $0x2,%edi
call   1040 <close@plt>
mov    $0x0,%al
call   1050 <setsid@plt>
jmp    11cf <make_daemon+0x6f>
xor    %edi,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_daemon>:
push   %rax
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11b3 <make_daemon+0x53>
lea    0xe75(%rip),%rdi
call   1030 <chdir@plt>
xor    %edi,%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    $0x2,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rcx
jmp    1050 <setsid@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
@.str = [2 x i8] c"/\00"
define void @make_daemon() {
%1 = alloca i64
%2 = load i32, i32* @SIGHUP
%3 = load i32, i32* @SIG_IGN
%4 = call i32 @signal(i32 %2, i32 %3)
%5 = call i64 (...) @fork()
store i64 %5, i64* %1
%6 = load i64, i64* %1
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @close(i32 0)
%11 = call i32 @close(i32 1)
%12 = call i32 @close(i32 2)
%13 = call i32 (...) @setsid()
br label %16
14: ; preds = %0
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %8
ret void
}

LLVM IR (-O2):
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
@.str = [2 x i8] c"/\00"
define void @make_daemon() {
%1 = load i32, i32* @SIGHUP
%2 = load i32, i32* @SIG_IGN
%3 = tail call i32 @signal(i32 %1, i32 %2)
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @close(i32 0)
%9 = tail call i32 @close(i32 1)
%10 = tail call i32 @close(i32 2)
%11 = tail call i32 (...) @setsid()
ret void
12: ; preds = %0
%13 = tail call i32 @exit(i32 0)
unreachable
}