#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*/ _exit(int);
int /*<<< orphan*/ execl(char *, char *, char *, char const *,
                         int /*<<< orphan*/ *);
scalar_t__ fork();
int waitpid(scalar_t__, int *, int /*<<< orphan*/);
int system_(const char *cmdstring) {
  pid_t pid;
  int status;
  if (NULL == cmdstring)
    return 1;
  pid = fork();
  if (0 > pid) {
    status = -1;
  } else if (0 == pid) {
    execl("/bin/sh", "sh", "-c", cmdstring, NULL);
    _exit(127);
  }
  if (waitpid(pid, &status, 0) == -1)
    status = -1;
  return status;
}


x86 assembly (clang, -O0):
<system_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1164 <system_+0x24>
movl   $0x1,-0x4(%rbp)
jmp    11ea <system_+0xaa>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jle    1187 <system_+0x47>
movl   $0xffffffff,-0x1c(%rbp)
jmp    11c5 <system_+0x85>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11c0 <system_+0x80>
mov    -0x10(%rbp),%rcx
lea    0xe62(%rip),%rdi
lea    0xe60(%rip),%rsi
lea    0xe5c(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
jmp    11c5 <system_+0x85>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11e4 <system_+0xa4>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1185 <system_+0x45>
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     118c <system_+0x4c>
jne    1194 <system_+0x54>
lea    0xe9e(%rip),%rdi
lea    0xe9c(%rip),%rsi
lea    0xe98(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1050 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
mov    $0x1,%eax
jmp    11ac <system_+0x6c>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
je     11ac <system_+0x6c>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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