#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*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ daemonize();
int /*<<< orphan*/ errno;
char *getlogin();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigsuspend(int /*<<< orphan*/ *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
int main(void) {
  printf("Started %s\n", "my_daemon");
  daemonize();
  char *login_name = getlogin();
  if (login_name == NULL) {
    syslog(LOG_INFO, "getlogin(3) error: %s\n", strerror(errno));
  } else {
    syslog(LOG_INFO, "getlogin(3) returned %s\n", login_name);
  }
  while (1) {
    sigset_t mask;
    sigemptyset(&mask);
    sigsuspend(&mask);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <daemonize@plt>
mov    $0x0,%al
call   1070 <getlogin@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e0 <main+0x70>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1060 <syslog@plt>
jmp    11f9 <main+0x89>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1060 <syslog@plt>
jmp    11fe <main+0x8e>
lea    -0x14(%rbp),%rdi
call   1050 <sigemptyset@plt>
lea    -0x14(%rbp),%rdi
call   1080 <sigsuspend@plt>
jmp    11fe <main+0x8e>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <daemonize@plt>
xor    %eax,%eax
call   1070 <getlogin@plt>
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%ebx
test   %rax,%rax
je     11ad <main+0x3d>
lea    0xe82(%rip),%rsi
jmp    11c2 <main+0x52>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe54(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <syslog@plt>
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    %rbx,%rdi
call   1080 <sigsuspend@plt>
jmp    11e0 <main+0x70>

LLVM IR (-O0):
@.str = [12 x i8] c"Started %s\0A\00"
@.str.1 = [10 x i8] c"my_daemon\00"
@LOG_INFO = global i32 0
@.str.2 = [23 x i8] c"getlogin(3) error: %s\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"getlogin(3) returned %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (...) @daemonize()
%6 = call i8* (...) @getlogin()
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @LOG_INFO
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @syslog(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %18
14: ; preds = %0
%15 = load i32, i32* @LOG_INFO
%16 = load i8*, i8** %2
%17 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %14, %9
br label %19
19: ; preds = %18, %19
%20 = call i32 @sigemptyset(i32* %3)
%21 = call i32 @sigsuspend(i32* %3)
br label %19
}

LLVM IR (-O2):
@.str = [12 x i8] c"Started %s\0A\00"
@.str.1 = [10 x i8] c"my_daemon\00"
@LOG_INFO = global i32 0
@.str.2 = [23 x i8] c"getlogin(3) error: %s\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"getlogin(3) returned %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 (...) @daemonize()
%4 = tail call i8* (...) @getlogin()
%5 = icmp eq i8* %4, null
%6 = load i32, i32* @LOG_INFO
br i1 %5, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %13
11: ; preds = %0
%12 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %11, %7
%14 = bitcast i32* %1 to i8*
br label %15
15: ; preds = %15, %13
%16 = call i32 @sigemptyset(i32* %1)
%17 = call i32 @sigsuspend(i32* %1)
br label %15
}