#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 sigaction {
  scalar_t__ sa_flags;
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_handler;
};
typedef int /*<<< orphan*/ sigset_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ _exit(int);
int execvp(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ sigaction(int /*<<< orphan*/, struct sigaction *,
                     struct sigaction *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int system_noblock(char **argv) {
  pid_t pid;
  struct sigaction ignore, saveintr, savequit;
  sigset_t chldmask, savemask;
  if (argv == NULL)
    return -1;
  ignore.sa_handler = SIG_IGN;
  sigemptyset(&ignore.sa_mask);
  ignore.sa_flags = 0;
  if (sigaction(SIGINT, &ignore, &saveintr) < 0)
    return -1;
  if (sigaction(SIGQUIT, &ignore, &savequit) < 0)
    return -1;
  if (sigaction(SIGCHLD, &ignore, &savequit) < 0)
    return -1;
  sigemptyset(&chldmask);
  sigaddset(&chldmask, SIGCHLD);
  if (sigprocmask(SIG_BLOCK, &chldmask, &savemask) < 0)
    return -1;
  if ((pid = fork()) < 0) {
    perror("fork");
    return -1;
  } else if (pid == 0) {
    sigaction(SIGINT, &saveintr, NULL);
    sigaction(SIGQUIT, &savequit, NULL);
    sigaction(SIGCHLD, &savequit, NULL);
    sigprocmask(SIG_SETMASK, &savemask, NULL);
    if (-1 == execvp(argv[0], argv)) {
      perror("exec");
    }
    _exit(127);
  } else {
  }
  if (sigaction(SIGINT, &saveintr, NULL) < 0)
    return -1;
  if (sigaction(SIGQUIT, &savequit, NULL) < 0)
    return -1;
  if (sigaction(SIGCHLD, &ignore, &savequit) < 0)
    return -1;
  if (sigprocmask(SIG_SETMASK, &savemask, NULL) < 0)
    return -1;
  return pid;
}


x86 assembly (clang, -O0):
<system_noblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <system_noblock+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x8,%rdi
call   1060 <sigemptyset@plt>
movq   $0x0,-0x28(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    11f0 <system_noblock+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    121c <system_noblock+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    1248 <system_noblock+0xc8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
lea    -0x4c(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
lea    -0x4c(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    128f <system_noblock+0x10f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    12bc <system_noblock+0x13c>
lea    0xd55(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
cmpq   $0x0,-0x18(%rbp)
jne    1354 <system_noblock+0x1d4>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <execvp@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    134a <system_noblock+0x1ca>
lea    0xcc0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x7f,%edi
call   1040 <_exit@plt>
jmp    1359 <system_noblock+0x1d9>
jmp    135e <system_noblock+0x1de>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    138a <system_noblock+0x20a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    0x2c4f(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    13b6 <system_noblock+0x236>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    0x2c13(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    13e2 <system_noblock+0x262>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    140e <system_noblock+0x28e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1415 <system_noblock+0x295>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_noblock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     12e2 <system_noblock+0x162>
mov    %rdi,%rbx
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
lea    0x18(%rsp),%rdi
call   1060 <sigemptyset@plt>
movq   $0x0,0x10(%rsp)
mov    0x2e22(%rip),%r13
mov    0x0(%r13),%edi
lea    0x10(%rsp),%rsi
lea    0x38(%rsp),%rdx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12e2 <system_noblock+0x162>
mov    0x2df7(%rip),%r12
mov    (%r12),%edi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12e2 <system_noblock+0x162>
mov    0x2dc4(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12e2 <system_noblock+0x162>
lea    0x34(%rsp),%r14
mov    %r14,%rdi
call   1060 <sigemptyset@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <sigaddset@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rdx
mov    %r14,%rsi
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     12e2 <system_noblock+0x162>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     12d6 <system_noblock+0x156>
mov    %rax,%r14
mov    0x0(%r13),%edi
lea    0x38(%rsp),%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
test   %r14,%r14
je     12f3 <system_noblock+0x173>
test   %rax,%rax
js     12e2 <system_noblock+0x162>
mov    (%r12),%edi
lea    0x20(%rsp),%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12e2 <system_noblock+0x162>
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12e2 <system_noblock+0x162>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
mov    $0xffffffff,%ebp
cmovns %r14d,%ebp
jmp    12e2 <system_noblock+0x162>
lea    0xd23(%rip),%rdi
call   1070 <perror@plt>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%edi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
mov    (%r15),%edi
mov    %rbp,%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1080 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1344 <system_noblock+0x1c4>
lea    0xcc6(%rip),%rdi
call   1070 <perror@plt>
mov    $0x7f,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
%struct.sigaction = type { i64, i32, i32 }
@SIG_IGN = global i32 0
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@SIGCHLD = global i32 0
@SIG_BLOCK = global i32 0
@.str = [5 x i8] c"fork\00"
@SIG_SETMASK = global i32 0
@.str.1 = [5 x i8] c"exec\00"
define i32 @system_noblock(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i64
%5 = alloca %struct.sigaction
%6 = alloca %struct.sigaction
%7 = alloca %struct.sigaction
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %3
%10 = load i8**, i8*** %3
%11 = icmp eq i8** %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %93
13: ; preds = %1
%14 = load i32, i32* @SIG_IGN
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
%17 = call i32 @sigemptyset(i32* %16)
%18 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store i64 0, i64* %18
%19 = load i32, i32* @SIGINT
%20 = call i64 @sigaction(i32 %19, %struct.sigaction* %5, %struct.sigaction* %6)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 -1, i32* %2
br label %93
23: ; preds = %13
%24 = load i32, i32* @SIGQUIT
%25 = call i64 @sigaction(i32 %24, %struct.sigaction* %5, %struct.sigaction* %7)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %2
br label %93
28: ; preds = %23
%29 = load i32, i32* @SIGCHLD
%30 = call i64 @sigaction(i32 %29, %struct.sigaction* %5, %struct.sigaction* %7)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -1, i32* %2
br label %93
33: ; preds = %28
%34 = call i32 @sigemptyset(i32* %8)
%35 = load i32, i32* @SIGCHLD
%36 = call i32 @sigaddset(i32* %8, i32 %35)
%37 = load i32, i32* @SIG_BLOCK
%38 = call i64 @sigprocmask(i32 %37, i32* %8, i32* %9)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %33
store i32 -1, i32* %2
br label %93
41: ; preds = %33
%42 = call i64 (...) @fork()
store i64 %42, i64* %4
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %93
46: ; preds = %41
%47 = load i64, i64* %4
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %68
49: ; preds = %46
%50 = load i32, i32* @SIGINT
%51 = call i64 @sigaction(i32 %50, %struct.sigaction* %6, %struct.sigaction* null)
%52 = load i32, i32* @SIGQUIT
%53 = call i64 @sigaction(i32 %52, %struct.sigaction* %7, %struct.sigaction* null)
%54 = load i32, i32* @SIGCHLD
%55 = call i64 @sigaction(i32 %54, %struct.sigaction* %7, %struct.sigaction* null)
%56 = load i32, i32* @SIG_SETMASK
%57 = call i64 @sigprocmask(i32 %56, i32* %9, i32* null)
%58 = load i8**, i8*** %3
%59 = getelementptr inbounds i8*, i8** %58, i64 0
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %3
%62 = call i32 @execvp(i8* %60, i8** %61)
%63 = icmp eq i32 -1, %62
br i1 %63, label %64, label %66
64: ; preds = %49
%65 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %64, %49
%67 = call i32 @_exit(i32 127)
unreachable
68: ; preds = %46
br label %69
69: ; preds = %68
br label %70
70: ; preds = %69
%71 = load i32, i32* @SIGINT
%72 = call i64 @sigaction(i32 %71, %struct.sigaction* %6, %struct.sigaction* null)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %70
store i32 -1, i32* %2
br label %93
75: ; preds = %70
%76 = load i32, i32* @SIGQUIT
%77 = call i64 @sigaction(i32 %76, %struct.sigaction* %7, %struct.sigaction* null)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %75
store i32 -1, i32* %2
br label %93
80: ; preds = %75
%81 = load i32, i32* @SIGCHLD
%82 = call i64 @sigaction(i32 %81, %struct.sigaction* %5, %struct.sigaction* %7)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %80
store i32 -1, i32* %2
br label %93
85: ; preds = %80
%86 = load i32, i32* @SIG_SETMASK
%87 = call i64 @sigprocmask(i32 %86, i32* %9, i32* null)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %85
store i32 -1, i32* %2
br label %93
90: ; preds = %85
%91 = load i64, i64* %4
%92 = trunc i64 %91 to i32
store i32 %92, i32* %2
br label %93
93: ; preds = %90, %89, %84, %79, %74, %44, %40, %32, %27, %22, %12
%94 = load i32, i32* %2
ret i32 %94
}

LLVM IR (-O2):
%struct.sigaction = type { i64, i32, i32 }
@SIG_IGN = global i32 0
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@SIGCHLD = global i32 0
@SIG_BLOCK = global i32 0
@.str = [5 x i8] c"fork\00"
@SIG_SETMASK = global i32 0
@.str.1 = [5 x i8] c"exec\00"
define i32 @system_noblock(i8** %0) {
%2 = alloca %struct.sigaction
%3 = alloca %struct.sigaction
%4 = alloca %struct.sigaction
%5 = alloca i32
%6 = alloca i32
%7 = bitcast %struct.sigaction* %2 to i8*
%8 = bitcast %struct.sigaction* %3 to i8*
%9 = bitcast %struct.sigaction* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = icmp eq i8** %0, null
br i1 %12, label %76, label %13
13: ; preds = %1
%14 = load i32, i32* @SIG_IGN
%15 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 1
%17 = call i32 @sigemptyset(i32* %16)
%18 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
store i64 0, i64* %18
%19 = load i32, i32* @SIGINT
%20 = call i64 @sigaction(i32 %19, %struct.sigaction* %2, %struct.sigaction* %3)
%21 = icmp slt i64 %20, 0
br i1 %21, label %76, label %22
22: ; preds = %13
%23 = load i32, i32* @SIGQUIT
%24 = call i64 @sigaction(i32 %23, %struct.sigaction* %2, %struct.sigaction* %4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %76, label %26
26: ; preds = %22
%27 = load i32, i32* @SIGCHLD
%28 = call i64 @sigaction(i32 %27, %struct.sigaction* %2, %struct.sigaction* %4)
%29 = icmp slt i64 %28, 0
br i1 %29, label %76, label %30
30: ; preds = %26
%31 = call i32 @sigemptyset(i32* %5)
%32 = load i32, i32* @SIGCHLD
%33 = call i32 @sigaddset(i32* %5, i32 %32)
%34 = load i32, i32* @SIG_BLOCK
%35 = call i64 @sigprocmask(i32 %34, i32* %5, i32* %6)
%36 = icmp slt i64 %35, 0
br i1 %36, label %76, label %37
37: ; preds = %30
%38 = call i64 (...) @fork()
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %76
42: ; preds = %37
%43 = icmp eq i64 %38, 0
%44 = load i32, i32* @SIGINT
%45 = call i64 @sigaction(i32 %44, %struct.sigaction* %3, %struct.sigaction* null)
br i1 %43, label %46, label %60
46: ; preds = %42
%47 = load i32, i32* @SIGQUIT
%48 = call i64 @sigaction(i32 %47, %struct.sigaction* %4, %struct.sigaction* null)
%49 = load i32, i32* @SIGCHLD
%50 = call i64 @sigaction(i32 %49, %struct.sigaction* %4, %struct.sigaction* null)
%51 = load i32, i32* @SIG_SETMASK
%52 = call i64 @sigprocmask(i32 %51, i32* %6, i32* null)
%53 = load i8*, i8** %0
%54 = call i32 @execvp(i8* %53, i8** %0)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %46
%57 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %56, %46
%59 = call i32 @_exit(i32 127)
unreachable
60: ; preds = %42
%61 = icmp slt i64 %45, 0
br i1 %61, label %76, label %62
62: ; preds = %60
%63 = load i32, i32* @SIGQUIT
%64 = call i64 @sigaction(i32 %63, %struct.sigaction* %4, %struct.sigaction* null)
%65 = icmp slt i64 %64, 0
br i1 %65, label %76, label %66
66: ; preds = %62
%67 = load i32, i32* @SIGCHLD
%68 = call i64 @sigaction(i32 %67, %struct.sigaction* %2, %struct.sigaction* %4)
%69 = icmp slt i64 %68, 0
br i1 %69, label %76, label %70
70: ; preds = %66
%71 = load i32, i32* @SIG_SETMASK
%72 = call i64 @sigprocmask(i32 %71, i32* %6, i32* null)
%73 = icmp slt i64 %72, 0
%74 = trunc i64 %38 to i32
%75 = select i1 %73, i32 -1, i32 %74
br label %76
76: ; preds = %70, %66, %62, %60, %30, %26, %22, %13, %1, %40
%77 = phi i32 [ -1, %40 ], [ -1, %1 ], [ -1, %13 ], [ -1, %22 ], [ -1, %26 ], [ -1, %30 ], [ -1, %60 ], [ -1, %62 ], [ -1, %66 ], [ %75, %70 ]
ret i32 %77
}