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

/* Variables and functions */
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ _PATH_BSHELL;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execl(int /*<<< orphan*/, char *, char *, char *,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int vfork();
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int susystem(char *s) {
  sig_t istat, qstat;
  int status;
  pid_t pid;
  pid = vfork();
  switch (pid) {
  case -1:
    return (127);
  case 0:
    (void)execl(_PATH_BSHELL, "sh", "-c", s, NULL);
    _exit(127);
  }
  istat = signal(SIGINT, SIG_IGN);
  qstat = signal(SIGQUIT, SIG_IGN);
  if (waitpid(pid, &status, 0) < 0)
    status = -1;
  (void)signal(SIGINT, istat);
  (void)signal(SIGQUIT, qstat);
  return (status);
}


x86 assembly (clang, -O0):
<susystem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
call   1060 <vfork@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xffffffff,%eax
je     1188 <susystem+0x38>
jmp    1178 <susystem+0x28>
mov    -0x24(%rbp),%eax
test   %eax,%eax
je     1194 <susystem+0x44>
jmp    11c3 <susystem+0x73>
movl   $0x7f,-0x4(%rbp)
jmp    123e <susystem+0xee>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe58(%rip),%rsi
lea    0xe54(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    1216 <susystem+0xc6>
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1040 <signal@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
call   1040 <signal@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<susystem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x7f,%ebp
call   1060 <vfork@plt>
mov    %ebp,%ecx
cmp    $0xffffffff,%eax
je     11dc <susystem+0x8c>
test   %eax,%eax
je     11eb <susystem+0x9b>
mov    %eax,%ebx
mov    0x2e6b(%rip),%r15
mov    (%r15),%edi
mov    0x2e49(%rip),%rbp
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    %eax,%r14d
mov    0x2e47(%rip),%r12
mov    (%r12),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
xor    %edx,%edx
mov    %ebx,%edi
call   1050 <waitpid@plt>
test   %rax,%rax
jns    11c2 <susystem+0x72>
movl   $0xffffffff,0xc(%rsp)
ff
mov    (%r15),%edi
mov    %r14d,%esi
call   1040 <signal@plt>
mov    (%r12),%edi
mov    %ebp,%esi
call   1040 <signal@plt>
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
lea    0xe01(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rbx,%rcx
call   1070 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@_PATH_BSHELL = global i32 0
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGQUIT = global i32 0
define i32 @susystem(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i32 @vfork()
store i32 %8, i32* %7
%9 = load i32, i32* %7
switch i32 %9, label %16 [
i32 -1, label %10
i32 0, label %11
]
10: ; preds = %1
store i32 127, i32* %2
br label %35
11: ; preds = %1
%12 = load i32, i32* @_PATH_BSHELL
%13 = load i8*, i8** %3
%14 = call i32 @execl(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32* null)
%15 = call i32 @_exit(i32 127)
unreachable
16: ; preds = %1
%17 = load i32, i32* @SIGINT
%18 = load i32, i32* @SIG_IGN
%19 = call i32 @signal(i32 %17, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* @SIGQUIT
%21 = load i32, i32* @SIG_IGN
%22 = call i32 @signal(i32 %20, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %7
%24 = call i64 @waitpid(i32 %23, i32* %6, i32 0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %16
store i32 -1, i32* %6
br label %27
27: ; preds = %26, %16
%28 = load i32, i32* @SIGINT
%29 = load i32, i32* %4
%30 = call i32 @signal(i32 %28, i32 %29)
%31 = load i32, i32* @SIGQUIT
%32 = load i32, i32* %5
%33 = call i32 @signal(i32 %31, i32 %32)
%34 = load i32, i32* %6
store i32 %34, i32* %2
br label %35
35: ; preds = %27, %10
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@_PATH_BSHELL = global i32 0
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGQUIT = global i32 0
define i32 @susystem(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @vfork()
switch i32 %4, label %9 [
i32 -1, label %25
i32 0, label %5
]
5: ; preds = %1
%6 = load i32, i32* @_PATH_BSHELL
%7 = call i32 @execl(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
%8 = call i32 @_exit(i32 127)
unreachable
9: ; preds = %1
%10 = load i32, i32* @SIGINT
%11 = load i32, i32* @SIG_IGN
%12 = call i32 @signal(i32 %10, i32 %11)
%13 = load i32, i32* @SIGQUIT
%14 = load i32, i32* @SIG_IGN
%15 = call i32 @signal(i32 %13, i32 %14)
%16 = call i64 @waitpid(i32 %4, i32* %2, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %9
store i32 -1, i32* %2
br label %19
19: ; preds = %18, %9
%20 = load i32, i32* @SIGINT
%21 = call i32 @signal(i32 %20, i32 %12)
%22 = load i32, i32* @SIGQUIT
%23 = call i32 @signal(i32 %22, i32 %15)
%24 = load i32, i32* %2
br label %25
25: ; preds = %1, %19
%26 = phi i32 [ %24, %19 ], [ 127, %1 ]
ret i32 %26
}