#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, char *, char const *,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int system(const char *command) {
  int status;
  pid_t pid;
  pid = fork();
  if (pid == 0) {
    execl("/system/bin/sh", "/system/bin/sh", "-c", command, NULL);
    exit(127);
  } else if (pid > 0) {
    pid = waitpid(pid, &status, 0);
    if (pid < 0) {
      return -1;
    }
    return status;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <system+0x4b>
mov    -0x10(%rbp),%rcx
lea    0xe93(%rip),%rsi
lea    0xe9b(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1050 <execl@plt>
mov    $0x7f,%edi
call   1040 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jle    11cb <system+0x8b>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1030 <waitpid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11c0 <system+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <system+0x92>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <system+0x92>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1183 <system+0x43>
jle    1178 <system+0x38>
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1030 <waitpid@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     117d <system+0x3d>
mov    0xc(%rsp),%eax
jmp    117d <system+0x3d>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe76(%rip),%rdi
lea    0xe7e(%rip),%rdx
mov    %rdi,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1050 <execl@plt>
mov    $0x7f,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/system/bin/sh\00"
@.str.1 = [3 x i8] c"-c\00"
define i32 @system(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
%6 = call i64 (...) @fork()
store i64 %6, i64* %5
%7 = load i64, i64* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @execl(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), 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* %10, i32* null)
%12 = call i32 @exit(i32 127)
unreachable
13: ; preds = %1
%14 = load i64, i64* %5
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i64, i64* %5
%18 = call i64 @waitpid(i64 %17, i32* %4, i32 0)
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %2
br label %25
22: ; preds = %16
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %25
24: ; preds = %13
store i32 -1, i32* %2
br label %25
25: ; preds = %24, %22, %21
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [15 x i8] c"/system/bin/sh\00"
@.str.1 = [3 x i8] c"-c\00"
define i32 @system(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @execl(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), 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* %0, i32* null)
%8 = tail call i32 @exit(i32 127)
unreachable
9: ; preds = %1
%10 = icmp sgt i64 %4, 0
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = call i64 @waitpid(i64 %4, i32* %2, i32 0)
%13 = icmp slt i64 %12, 0
%14 = load i32, i32* %2
%15 = select i1 %13, i32 -1, i32 %14
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ -1, %9 ], [ %15, %11 ]
ret i32 %17
}