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

/* Variables and functions */
int /*<<< orphan*/ SIG_UNBLOCK;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ exec_ssh(char const *, char const *const *);
int fork();
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ unused(char *, ...);
pid_t fork_ssh(sigset_t *sigchld, const char *unix_socket,
               const char *const *argv) {
  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_ssh(unix_socket, argv);
  }
  do {
    unused("forked ssh, pid=%i", pid);
  } while (0);
  return pid;
}


x86 assembly (clang, -O0):
<fork_ssh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1197 <fork_ssh+0x47>
jmp    117d <fork_ssh+0x2d>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <fork_ssh+0xb6>
cmpl   $0x0,-0x24(%rbp)
jne    11ea <fork_ssh+0x9a>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
jne    11dd <fork_ssh+0x8d>
jmp    11c5 <fork_ssh+0x75>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <exec_ssh@plt>
jmp    11ef <fork_ssh+0x9f>
mov    -0x24(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_ssh>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1183 <fork_ssh+0x33>
cmp    $0xffffffff,%ebx
jne    11a6 <fork_ssh+0x56>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <unused@plt>
jmp    11b6 <fork_ssh+0x66>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     11c4 <fork_ssh+0x74>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <exec_ssh@plt>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <unused@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1050 <unused@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

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

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