#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*/ __sighandler_t;

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *);
int fork();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int wait4(int, int *, int /*<<< orphan*/, int /*<<< orphan*/);
int __libc_system(char *command) {
  int wait_val, pid;
  __sighandler_t save_quit, save_int, save_chld;
  if (command == 0)
    return 1;
  save_quit = signal(SIGQUIT, SIG_IGN);
  save_int = signal(SIGINT, SIG_IGN);
  save_chld = signal(SIGCHLD, SIG_DFL);
  if ((pid = fork()) < 0) {
    signal(SIGQUIT, save_quit);
    signal(SIGINT, save_int);
    signal(SIGCHLD, save_chld);
    return -1;
  }
  if (pid == 0) {
    signal(SIGQUIT, SIG_DFL);
    signal(SIGINT, SIG_DFL);
    signal(SIGCHLD, SIG_DFL);
    execl("/system/bin/sh", "sh", "-c", command, (char *)0);
    _exit(127);
  }
  signal(SIGQUIT, SIG_IGN);
  signal(SIGINT, SIG_IGN);
  if (wait4(pid, &wait_val, 0, 0) == -1)
    wait_val = -1;
  signal(SIGQUIT, save_quit);
  signal(SIGINT, save_int);
  signal(SIGCHLD, save_chld);
  return wait_val;
}


x86 assembly (clang, -O0):
<__libc_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <__libc_system+0x23>
movl   $0x1,-0x4(%rbp)
jmp    1316 <__libc_system+0x1c6>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1213 <__libc_system+0xc3>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   1040 <signal@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
call   1040 <signal@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%esi
call   1040 <signal@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1316 <__libc_system+0x1c6>
cmpl   $0x0,-0x18(%rbp)
jne    128f <__libc_system+0x13f>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    -0x10(%rbp),%rcx
lea    0xd93(%rip),%rdi
lea    0xd98(%rip),%rsi
lea    0xd94(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <wait4@plt>
cmp    $0xffffffff,%eax
jne    12dd <__libc_system+0x18d>
movl   $0xffffffff,-0x14(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   1040 <signal@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
call   1040 <signal@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%esi
call   1040 <signal@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__libc_system>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1233 <__libc_system+0xe3>
mov    %rdi,%rbx
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%r14
mov    (%r14),%esi
call   1040 <signal@plt>
mov    %eax,%r13d
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   1040 <signal@plt>
mov    %eax,%r15d
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
js     123a <__libc_system+0xea>
mov    %r13d,0x4(%rsp)
mov    0x2e19(%rip),%r13
mov    0x0(%r13),%edi
je     1281 <__libc_system+0x131>
mov    %eax,%ebp
mov    (%r14),%esi
call   1040 <signal@plt>
mov    0x2e06(%rip),%rbx
mov    (%rbx),%edi
mov    (%r14),%esi
call   1040 <signal@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <wait4@plt>
cmp    $0xffffffff,%eax
jne    1206 <__libc_system+0xb6>
movl   $0xffffffff,(%rsp)
mov    0x0(%r13),%edi
mov    0x4(%rsp),%esi
call   1040 <signal@plt>
mov    (%rbx),%edi
mov    %r15d,%esi
call   1040 <signal@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    %r12d,%esi
call   1040 <signal@plt>
mov    (%rsp),%eax
jmp    1272 <__libc_system+0x122>
mov    $0x1,%eax
jmp    1272 <__libc_system+0x122>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    %r13d,%esi
call   1040 <signal@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    %r15d,%esi
call   1040 <signal@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    %r12d,%esi
call   1040 <signal@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d38(%rip),%rbp
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
call   1040 <signal@plt>
lea    0xd47(%rip),%rdi
lea    0xd4c(%rip),%rsi
lea    0xd48(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>

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

LLVM IR (-O2):
@SIGQUIT = global i32 0
@SIG_IGN = global i32 0
@SIGINT = global i32 0
@SIGCHLD = global i32 0
@SIG_DFL = global i32 0
@.str = [15 x i8] c"/system/bin/sh\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [3 x i8] c"-c\00"
define i32 @__libc_system(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %55, label %5
5: ; preds = %1
%6 = load i32, i32* @SIGQUIT
%7 = load i32, i32* @SIG_IGN
%8 = tail call i32 @signal(i32 %6, i32 %7)
%9 = load i32, i32* @SIGINT
%10 = load i32, i32* @SIG_IGN
%11 = tail call i32 @signal(i32 %9, i32 %10)
%12 = load i32, i32* @SIGCHLD
%13 = load i32, i32* @SIG_DFL
%14 = tail call i32 @signal(i32 %12, i32 %13)
%15 = tail call i32 (...) @fork()
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %5
%18 = load i32, i32* @SIGQUIT
%19 = tail call i32 @signal(i32 %18, i32 %8)
%20 = load i32, i32* @SIGINT
%21 = tail call i32 @signal(i32 %20, i32 %11)
%22 = load i32, i32* @SIGCHLD
%23 = tail call i32 @signal(i32 %22, i32 %14)
br label %55
24: ; preds = %5
%25 = icmp eq i32 %15, 0
%26 = load i32, i32* @SIGQUIT
br i1 %25, label %27, label %38
27: ; preds = %24
%28 = load i32, i32* @SIG_DFL
%29 = tail call i32 @signal(i32 %26, i32 %28)
%30 = load i32, i32* @SIGINT
%31 = load i32, i32* @SIG_DFL
%32 = tail call i32 @signal(i32 %30, i32 %31)
%33 = load i32, i32* @SIGCHLD
%34 = load i32, i32* @SIG_DFL
%35 = tail call i32 @signal(i32 %33, i32 %34)
%36 = tail call i32 @execl(i8* getelementptr inbounds ([15 x i8], [15 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)
%37 = tail call i32 @_exit(i32 127)
unreachable
38: ; preds = %24
%39 = load i32, i32* @SIG_IGN
%40 = tail call i32 @signal(i32 %26, i32 %39)
%41 = load i32, i32* @SIGINT
%42 = load i32, i32* @SIG_IGN
%43 = tail call i32 @signal(i32 %41, i32 %42)
%44 = call i32 @wait4(i32 %15, i32* %2, i32 0, i32 0)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %47
46: ; preds = %38
store i32 -1, i32* %2
br label %47
47: ; preds = %46, %38
%48 = load i32, i32* @SIGQUIT
%49 = call i32 @signal(i32 %48, i32 %8)
%50 = load i32, i32* @SIGINT
%51 = call i32 @signal(i32 %50, i32 %11)
%52 = load i32, i32* @SIGCHLD
%53 = call i32 @signal(i32 %52, i32 %14)
%54 = load i32, i32* %2
br label %55
55: ; preds = %1, %47, %17
%56 = phi i32 [ -1, %17 ], [ %54, %47 ], [ 1, %1 ]
ret i32 %56
}