#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*/ SIGCHLD;
int /*<<< orphan*/ SIG_DFL;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ _exit(int);
int daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int execvp(char *, char **);
char *getpid();
int /*<<< orphan*/ memcpy(char **, char **, int);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ unused(char *, ...);
__attribute__((noreturn)) void exec_daemon(int argc, char **argv) {
  char *args[argc + 2];
  args[0] = "fssh-daemon";
  memcpy(&args[1], argv, argc * sizeof(char *));
  args[argc + 1] = NULL;
  if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
    do {
      unused("signal(SIGCHLD, SIG_DFL) failed");
    } while (0);
    goto _fail;
  }
  if (daemon(0, 0) == -1) {
    do {
      unused("daemon() failed");
    } while (0);
    goto _fail;
  }
  do {
    unused("exec fssh-daemon, pid=%i", getpid());
  } while (0);
  if (execvp(args[0], args) == -1) {
    do {
      unused("execvp(%s) failed", args[0]);
    } while (0);
    goto _fail;
  }
_fail:
  _exit(1);
}


x86 assembly (clang, -O0):
<exec_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,(%rdi)
add    $0x8,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
jne    1223 <exec_daemon+0xb3>
jmp    120b <exec_daemon+0x9b>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
jmp    121e <exec_daemon+0xae>
jmp    12b2 <exec_daemon+0x142>
xor    %esi,%esi
mov    %esi,%edi
call   1080 <daemon@plt>
cmp    $0xffffffff,%eax
jne    1252 <exec_daemon+0xe2>
jmp    123a <exec_daemon+0xca>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
jmp    124d <exec_daemon+0xdd>
jmp    12b2 <exec_daemon+0x142>
jmp    1257 <exec_daemon+0xe7>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rsi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
jmp    1274 <exec_daemon+0x104>
mov    -0x28(%rbp),%rsi
mov    (%rsi),%rdi
call   1090 <execvp@plt>
cmp    $0xffffffff,%eax
jne    12ad <exec_daemon+0x13d>
jmp    128e <exec_daemon+0x11e>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1060 <unused@plt>
jmp    12a8 <exec_daemon+0x138>
jmp    12b2 <exec_daemon+0x142>
jmp    12b2 <exec_daemon+0x142>
mov    $0x1,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<exec_daemon>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0x2(%rbx),%eax
mov    %rsp,%rcx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
mov    %rcx,%r14
sub    %rax,%r14
mov    %r14,%rsp
neg    %rax
lea    0xe62(%rip),%rdx
mov    %rdx,(%rcx,%rax,1)
lea    0x8(%r14),%rdi
lea    0x0(,%rbx,8),%edx
call   1070 <memcpy@plt>
movslq %ebx,%rax
movq   $0x0,0x8(%r14,%rax,8)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
jne    11ea <exec_daemon+0x7a>
lea    0xe24(%rip),%rdi
jmp    11ff <exec_daemon+0x8f>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <daemon@plt>
cmp    $0xffffffff,%eax
jne    1210 <exec_daemon+0xa0>
lea    0xe2d(%rip),%rdi
xor    %eax,%eax
call   1060 <unused@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe1e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <unused@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1090 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1249 <exec_daemon+0xd9>
mov    (%r14),%rsi
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1060 <unused@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"fssh-daemon\00"
@SIGCHLD = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@.str.1 = [32 x i8] c"signal(SIGCHLD, SIG_DFL) failed\00"
@.str.2 = [16 x i8] c"daemon() failed\00"
@.str.3 = [25 x i8] c"exec fssh-daemon, pid=%i\00"
@.str.4 = [18 x i8] c"execvp(%s) failed\00"
define void @exec_daemon(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8*, i64 %9
store i64 %9, i64* %6
%12 = getelementptr inbounds i8*, i8** %11, i64 0
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds i8*, i8** %11, i64 1
%14 = load i8**, i8*** %4
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 8
%18 = trunc i64 %17 to i32
%19 = call i32 @memcpy(i8** %13, i8** %14, i32 %18)
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %11, i64 %22
store i8* null, i8** %23
%24 = load i32, i32* @SIGCHLD
%25 = load i32, i32* @SIG_DFL
%26 = call i64 @signal(i32 %24, i32 %25)
%27 = load i64, i64* @SIG_ERR
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %2
br label %30
30: ; preds = %29
%31 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30
br label %33
33: ; preds = %32
br label %60
34: ; preds = %2
%35 = call i32 @daemon(i32 0, i32 0)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %42
37: ; preds = %34
br label %38
38: ; preds = %37
%39 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38
br label %41
41: ; preds = %40
br label %60
42: ; preds = %34
br label %43
43: ; preds = %42
%44 = call i8* (...) @getpid()
%45 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43
br label %47
47: ; preds = %46
%48 = getelementptr inbounds i8*, i8** %11, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @execvp(i8* %49, i8** %11)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %59
52: ; preds = %47
br label %53
53: ; preds = %52
%54 = getelementptr inbounds i8*, i8** %11, i64 0
%55 = load i8*, i8** %54
%56 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %53
br label %58
58: ; preds = %57
br label %60
59: ; preds = %47
br label %60
60: ; preds = %59, %58, %41, %33
%61 = call i32 @_exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"fssh-daemon\00"
@SIGCHLD = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@.str.1 = [32 x i8] c"signal(SIGCHLD, SIG_DFL) failed\00"
@.str.2 = [16 x i8] c"daemon() failed\00"
@.str.3 = [25 x i8] c"exec fssh-daemon, pid=%i\00"
@.str.4 = [18 x i8] c"execvp(%s) failed\00"
define void @exec_daemon(i32 %0, i8** %1) {
%3 = add nsw i32 %0, 2
%4 = zext i32 %3 to i64
%5 = alloca i8*, i64 %4
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds i8*, i8** %5, i64 1
%7 = shl i32 %0, 3
%8 = call i32 @memcpy(i8** %6, i8** %1, i32 %7)
%9 = add nsw i32 %0, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %5, i64 %10
store i8* null, i8** %11
%12 = load i32, i32* @SIGCHLD
%13 = load i32, i32* @SIG_DFL
%14 = call i64 @signal(i32 %12, i32 %13)
%15 = load i64, i64* @SIG_ERR
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %33
19: ; preds = %2
%20 = call i32 @daemon(i32 0, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %33
24: ; preds = %19
%25 = call i8* (...) @getpid()
%26 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @execvp(i8* %27, i8** %5)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %24, %30, %22, %17
%34 = call i32 @_exit(i32 1)
unreachable
}