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

/* Variables and functions */
scalar_t__ EINTR;
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);
scalar_t__ errno;
int /*<<< orphan*/ execl(char *, char *, char *, char const *, char *);
scalar_t__ fork();
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*/ *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int l_system(const char *pszCmd) {
  pid_t pid;
  int status;
  struct sigaction ignore, saveintr, savequit;
  sigset_t chldmask, savemask;
  if (pszCmd == NULL)
    return -1;
  ignore.sa_handler = SIG_IGN;
  sigemptyset(&ignore.sa_mask);
  if (sigaction(SIGINT, &ignore, &saveintr) < 0)
    return -1;
  if (sigaction(SIGQUIT, &ignore, &savequit) < 0)
    return -1;
  sigemptyset(&chldmask);
  sigaddset(&chldmask, SIGCHLD);
  if (sigprocmask(SIG_BLOCK, &chldmask, &savemask) < 0)
    return -1;
  if ((pid = fork()) < 0) {
    status = -1;
  } else if (pid == 0) {
    sigaction(SIGINT, &saveintr, NULL);
    sigaction(SIGQUIT, &savequit, NULL);
    sigprocmask(SIG_SETMASK, &savemask, NULL);
    execl("/bin/sh", "sh", "-c", pszCmd, (char *)0);
    _exit(127);
  } else {
    while (waitpid(pid, &status, 0) < 0) {
      if (errno != EINTR) {
        status = -1;
        break;
      }
    }
  }
  if (sigaction(SIGINT, &saveintr, NULL) < 0)
    return -1;
  if (sigaction(SIGQUIT, &savequit, NULL) < 0)
    return -1;
  if (sigprocmask(SIG_SETMASK, &savemask, NULL) < 0)
    return -1;
  return status;
}


x86 assembly (clang, -O0):
<l_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <l_system+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <l_system+0x24f>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    11e4 <l_system+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <l_system+0x24f>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    1210 <l_system+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <l_system+0x24f>
lea    -0x3c(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdi
call   1090 <sigaddset@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    1257 <l_system+0xd7>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <l_system+0x24f>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1278 <l_system+0xf8>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1345 <l_system+0x1c5>
cmpq   $0x0,-0x18(%rbp)
jne    12f2 <l_system+0x172>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x10(%rbp),%rcx
lea    0xd30(%rip),%rdi
lea    0xd2e(%rip),%rsi
lea    0xd2a(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <execl@plt>
mov    $0x7f,%edi
call   1040 <_exit@plt>
jmp    12f7 <l_system+0x177>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
cmp    $0x0,%rax
jge    133b <l_system+0x1bb>
mov    0x2ca1(%rip),%rax
mov    (%rax),%rax
mov    0x2c87(%rip),%rcx
cmp    (%rcx),%rax
je     1336 <l_system+0x1b6>
movl   $0xffffffff,-0x1c(%rbp)
jmp    133b <l_system+0x1bb>
jmp    12f7 <l_system+0x177>
jmp    1340 <l_system+0x1c0>
jmp    1345 <l_system+0x1c5>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    1371 <l_system+0x1f1>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <l_system+0x24f>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <sigaction@plt>
cmp    $0x0,%rax
jge    139d <l_system+0x21d>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <l_system+0x24f>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    13c9 <l_system+0x249>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cf <l_system+0x24f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_system>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     12d4 <l_system+0x154>
mov    %rdi,%rbx
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e27(%rip),%r12
mov    (%r12),%edi
lea    0x10(%rsp),%rdx
mov    %rbp,%rsi
call   1050 <sigaction@plt>
test   %rax,%rax
js     12d4 <l_system+0x154>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12d4 <l_system+0x154>
lea    0x24(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <sigemptyset@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <sigaddset@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rdx
mov    %rbp,%rsi
call   1030 <sigprocmask@plt>
test   %rax,%rax
js     12d4 <l_system+0x154>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     127a <l_system+0xfa>
je     12e6 <l_system+0x166>
mov    %rax,%rbp
mov    %rsp,%r13
mov    0x2d60(%rip),%rbx
mov    0x2d49(%rip),%r15
nop
mov    %rbp,%rdi
mov    %r13,%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
test   %rax,%rax
jns    1281 <l_system+0x101>
mov    (%rbx),%rax
cmp    (%r15),%rax
je     1260 <l_system+0xe0>
movl   $0xffffffff,(%rsp)
mov    (%r12),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12d4 <l_system+0x154>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
test   %rax,%rax
js     12d4 <l_system+0x154>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     12d4 <l_system+0x154>
mov    (%rsp),%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <sigaction@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
lea    0xcd9(%rip),%rdi
lea    0xcd7(%rip),%rsi
lea    0xcd3(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1080 <execl@plt>
mov    $0x7f,%edi
call   1040 <_exit@plt>

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

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