#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*/ SIGUSR2;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ setsid();
void ezd_daemon_started(void) {
  int i;
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  for (i = 0; i < 3; i++)
    open("/dev/null", 0);
  kill(getppid(), SIGUSR2);
  setsid();
}


x86 assembly (clang, -O0):
<ezd_daemon_started>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jge    11af <ezd_daemon_started+0x5f>
lea    0xe66(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <ezd_daemon_started+0x39>
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %eax,%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    $0x0,%al
call   1040 <setsid@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ezd_daemon_started>:
push   %rbx
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
lea    0xe7e(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <open@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <kill@plt>
xor    %eax,%eax
pop    %rbx
jmp    1040 <setsid@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [10 x i8] c"/dev/null\00"
@SIGUSR2 = global i32 0
define void @ezd_daemon_started() {
%1 = alloca i32
%2 = load i32, i32* @STDIN_FILENO
%3 = call i32 @close(i32 %2)
%4 = load i32, i32* @STDOUT_FILENO
%5 = call i32 @close(i32 %4)
%6 = load i32, i32* @STDERR_FILENO
%7 = call i32 @close(i32 %6)
store i32 0, i32* %1
br label %8
8: ; preds = %13, %0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
br label %13
13: ; preds = %11
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %8
16: ; preds = %8
%17 = call i32 (...) @getppid()
%18 = load i32, i32* @SIGUSR2
%19 = call i32 @kill(i32 %17, i32 %18)
%20 = call i32 (...) @setsid()
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str = [10 x i8] c"/dev/null\00"
@SIGUSR2 = global i32 0
define void @ezd_daemon_started() {
%1 = load i32, i32* @STDIN_FILENO
%2 = tail call i32 @close(i32 %1)
%3 = load i32, i32* @STDOUT_FILENO
%4 = tail call i32 @close(i32 %3)
%5 = load i32, i32* @STDERR_FILENO
%6 = tail call i32 @close(i32 %5)
%7 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = tail call i32 (...) @getppid()
%11 = load i32, i32* @SIGUSR2
%12 = tail call i32 @kill(i32 %10, i32 %11)
%13 = tail call i32 (...) @setsid()
ret void
}