#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int setsid();
int /*<<< orphan*/ sniffer_trace(char *);
int /*<<< orphan*/ umask(int /*<<< orphan*/);
void daemonize() {
  if (1) {
    sniffer_trace("ENTERING: daemonize");
  }
  umask(0);
  int sid = setsid();
  if (sid < 0) {
    exit(0);
  }
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  if (1) {
    sniffer_trace("LEAVING: daemonize");
  }
}


x86 assembly (clang, -O0):
<daemonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1060 <sniffer_trace@plt>
xor    %edi,%edi
call   1050 <umask@plt>
mov    $0x0,%al
call   1040 <setsid@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1186 <daemonize+0x36>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
lea    0xe5d(%rip),%rdi
call   1060 <sniffer_trace@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemonize>:
push   %rax
lea    0xea8(%rip),%rdi
call   1060 <sniffer_trace@plt>
xor    %edi,%edi
call   1050 <umask@plt>
xor    %eax,%eax
call   1040 <setsid@plt>
test   %eax,%eax
js     11a6 <daemonize+0x56>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1030 <close@plt>
lea    0xe74(%rip),%rdi
pop    %rax
jmp    1060 <sniffer_trace@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"ENTERING: daemonize\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [19 x i8] c"LEAVING: daemonize\00"
define void @daemonize() {
%1 = alloca i32
%2 = call i32 @sniffer_trace(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @umask(i32 0)
%4 = call i32 (...) @setsid()
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = load i32, i32* @STDIN_FILENO
%11 = call i32 @close(i32 %10)
%12 = load i32, i32* @STDOUT_FILENO
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* @STDERR_FILENO
%15 = call i32 @close(i32 %14)
%16 = call i32 @sniffer_trace(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"ENTERING: daemonize\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [19 x i8] c"LEAVING: daemonize\00"
define void @daemonize() {
%1 = tail call i32 @sniffer_trace(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @umask(i32 0)
%3 = tail call i32 (...) @setsid()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %0
%8 = load i32, i32* @STDIN_FILENO
%9 = tail call i32 @close(i32 %8)
%10 = load i32, i32* @STDOUT_FILENO
%11 = tail call i32 @close(i32 %10)
%12 = load i32, i32* @STDERR_FILENO
%13 = tail call i32 @close(i32 %12)
%14 = tail call i32 @sniffer_trace(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
ret void
}