#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int setsid();
int /*<<< orphan*/ umask(int);
int SWS_Daemon(void) {
  pid_t pid;
  pid = fork();
  switch (pid) {
  case -1:
    perror("SWS_Daemon failed to fork");
    return -1;
  case 0:
    break;
  default:
    exit(EXIT_SUCCESS);
  }
  if (-1 == setsid()) {
    perror("SWS_Daemon setsid failed");
    return -1;
  }
  umask(022);
  return 0;
}


x86 assembly (clang, -O0):
<SWS_Daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0xffffffff,%eax
je     1186 <SWS_Daemon+0x36>
jmp    1176 <SWS_Daemon+0x26>
mov    -0xc(%rbp),%eax
test   %eax,%eax
je     119e <SWS_Daemon+0x4e>
jmp    11a3 <SWS_Daemon+0x53>
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <SWS_Daemon+0xa0>
jmp    11b1 <SWS_Daemon+0x61>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1030 <setsid@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11df <SWS_Daemon+0x8f>
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <SWS_Daemon+0xa0>
mov    $0x12,%edi
call   1040 <umask@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SWS_Daemon>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    1178 <SWS_Daemon+0x28>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <setsid@plt>
cmp    $0xffffffff,%eax
je     1186 <SWS_Daemon+0x36>
mov    $0x12,%edi
call   1040 <umask@plt>
mov    %ebx,%eax
pop    %rbx
ret
cmp    $0xffffffff,%eax
jne    1199 <SWS_Daemon+0x49>
lea    0xe7c(%rip),%rdi
jmp    118d <SWS_Daemon+0x3d>
lea    0xe8d(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1174 <SWS_Daemon+0x24>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"SWS_Daemon failed to fork\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [25 x i8] c"SWS_Daemon setsid failed\00"
define i32 @SWS_Daemon() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
switch i32 %4, label %8 [
i32 -1, label %5
i32 0, label %7
]
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
7: ; preds = %0
br label %11
8: ; preds = %0
%9 = load i32, i32* @EXIT_SUCCESS
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %7
%12 = call i32 (...) @setsid()
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
16: ; preds = %11
%17 = call i32 @umask(i32 18)
store i32 0, i32* %1
br label %18
18: ; preds = %16, %14, %5
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [26 x i8] c"SWS_Daemon failed to fork\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [25 x i8] c"SWS_Daemon setsid failed\00"
define i32 @SWS_Daemon() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %4 [
i32 -1, label %2
i32 0, label %7
]
2: ; preds = %0
%3 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
4: ; preds = %0
%5 = load i32, i32* @EXIT_SUCCESS
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = tail call i32 (...) @setsid()
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %7
%13 = tail call i32 @umask(i32 18)
br label %14
14: ; preds = %12, %10, %2
%15 = phi i32 [ -1, %10 ], [ 0, %12 ], [ -1, %2 ]
ret i32 %15
}