#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 */
struct names {
  int dummy;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ exec_client(struct names *);
int fork();
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ unused(char *, ...);
pid_t fork_client(sigset_t *sigchld, struct names *names) {
  pid_t pid = fork();
  if (pid == -1) {
    do {
      unused("fork() failed");
    } while (0);
    return -1;
  }
  if (pid == 0) {
    if (sigprocmask(SIG_UNBLOCK, sigchld, NULL) == -1) {
      do {
        unused("sigprocmask() failed");
      } while (0);
      _exit(1);
    }
    exec_client(names);
  }
  do {
    unused("forked fssh-client, pid=%i", pid);
  } while (0);
  return pid;
}


x86 assembly (clang, -O0):
<fork_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1193 <fork_client+0x43>
jmp    1179 <fork_client+0x29>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <fork_client+0xae>
cmpl   $0x0,-0x1c(%rbp)
jne    11e2 <fork_client+0x92>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    11d9 <fork_client+0x89>
jmp    11c1 <fork_client+0x71>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    -0x18(%rbp),%rdi
call   1060 <exec_client@plt>
jmp    11e7 <fork_client+0x97>
mov    -0x1c(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_client>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     117d <fork_client+0x2d>
cmp    $0xffffffff,%ebx
jne    119d <fork_client+0x4d>
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1050 <unused@plt>
jmp    11ad <fork_client+0x5d>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11b5 <fork_client+0x65>
mov    %r14,%rdi
call   1060 <exec_client@plt>
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <unused@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1050 <unused@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
%struct.names = type { i32 }
@.str = [14 x i8] c"fork() failed\00"
@SIG_UNBLOCK = global i32 0
@.str.1 = [21 x i8] c"sigprocmask() failed\00"
@.str.2 = [27 x i8] c"forked fssh-client, pid=%i\00"
define i32 @fork_client(i32* %0, %struct.names* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.names*
%6 = alloca i32
store i32* %0, i32** %4
store %struct.names* %1, %struct.names** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
br label %11
11: ; preds = %10
%12 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11
store i32 -1, i32* %3
br label %36
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i32, i32* @SIG_UNBLOCK
%19 = load i32*, i32** %4
%20 = call i32 @sigprocmask(i32 %18, i32* %19, i32* null)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %17
br label %23
23: ; preds = %22
%24 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23
%26 = call i32 @_exit(i32 1)
unreachable
27: ; preds = %17
%28 = load %struct.names*, %struct.names** %5
%29 = call i32 @exec_client(%struct.names* %28)
br label %30
30: ; preds = %27, %14
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.names = type { i32 }
@.str = [14 x i8] c"fork() failed\00"
@SIG_UNBLOCK = global i32 0
@.str.1 = [21 x i8] c"sigprocmask() failed\00"
@.str.2 = [27 x i8] c"forked fssh-client, pid=%i\00"
define i32 @fork_client(i32* %0, %struct.names* %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %15 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %17
6: ; preds = %2
%7 = load i32, i32* @SIG_UNBLOCK
%8 = tail call i32 @sigprocmask(i32 %7, i32* %0, i32* null)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @_exit(i32 1)
unreachable
13: ; preds = %6
%14 = tail call i32 @exec_client(%struct.names* %1)
br label %15
15: ; preds = %2, %13
%16 = tail call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %3)
br label %17
17: ; preds = %15, %4
ret i32 %3
}