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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
scalar_t__ daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
scalar_t__ getuid();
scalar_t__ setup_sigmask();
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void daemon_init(const char *prog, int nofork) {
  uid_t uid;
  pid_t pid;
  uid = getuid();
  if (uid) {
    syslog(LOG_ERR, "daemon_init: Sorry, only root wants to run this.\n");
    exit(1);
  }
  if (setup_sigmask() < 0) {
    syslog(LOG_ERR, "daemon_init: Unable to set signal mask.\n");
    exit(1);
  }
  if (!nofork && daemon(0, 0)) {
    syslog(LOG_ERR, "daemon_init: Unable to daemonize.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<daemon_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1194 <daemon_init+0x44>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1070 <setup_sigmask@plt>
cmp    $0x0,%rax
jge    11c4 <daemon_init+0x74>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1200 <daemon_init+0xb0>
xor    %esi,%esi
mov    %esi,%edi
call   1050 <daemon@plt>
cmp    $0x0,%rax
je     1200 <daemon_init+0xb0>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemon_init>:
push   %rbx
mov    %esi,%ebx
xor    %eax,%eax
call   1030 <getuid@plt>
test   %rax,%rax
jne    117f <daemon_init+0x2f>
xor    %eax,%eax
call   1070 <setup_sigmask@plt>
test   %rax,%rax
js     1191 <daemon_init+0x41>
test   %ebx,%ebx
jne    117d <daemon_init+0x2d>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <daemon@plt>
test   %rax,%rax
jne    11a3 <daemon_init+0x53>
pop    %rbx
ret
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
jmp    11b3 <daemon_init+0x63>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
jmp    11b3 <daemon_init+0x63>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [50 x i8] c"daemon_init: Sorry, only root wants to run this.\0A\00"
@.str.1 = [41 x i8] c"daemon_init: Unable to set signal mask.\0A\00"
@.str.2 = [35 x i8] c"daemon_init: Unable to daemonize.\0A\00"
define void @daemon_init(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i64 (...) @getuid()
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @LOG_ERR
%12 = call i32 @syslog(i32 %11, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i64 (...) @setup_sigmask()
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @LOG_ERR
%19 = call i32 @syslog(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = call i64 @daemon(i32 0, i32 0)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @LOG_ERR
%29 = call i32 @syslog(i32 %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24, %21
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [50 x i8] c"daemon_init: Sorry, only root wants to run this.\0A\00"
@.str.1 = [41 x i8] c"daemon_init: Unable to set signal mask.\0A\00"
@.str.2 = [35 x i8] c"daemon_init: Unable to daemonize.\0A\00"
define void @daemon_init(i8* nocapture readnone %0, i32 %1) {
%3 = tail call i64 (...) @getuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @LOG_ERR
%7 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i64 (...) @setup_sigmask()
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @LOG_ERR
%14 = tail call i32 @syslog(i32 %13, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = icmp eq i32 %1, 0
br i1 %17, label %18, label %25
18: ; preds = %16
%19 = tail call i64 @daemon(i32 0, i32 0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @LOG_ERR
%23 = tail call i32 @syslog(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %18, %16
ret void
}