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

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *);
int /*<<< orphan*/ fork();
int waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int system(char *command) {
  int status;
  pid_t childPid;
  switch (childPid = fork()) {
  case -1:
    return -1;
  case 0:
    execl("/bin/sh", "sh", "-c", command, (char *)NULL);
    _exit(127);
  default:
    if (waitpid(childPid, &status, 0) == -1)
      return -1;
    else
      return status;
  }
}


x86 assembly (clang, -O0):
<system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,-0x18(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     1179 <system+0x39>
jmp    1169 <system+0x29>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     1185 <system+0x45>
jmp    11b2 <system+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <system+0x9b>
mov    -0x10(%rbp),%rcx
lea    0xe70(%rip),%rdi
lea    0xe6e(%rip),%rsi
lea    0xe6a(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11d5 <system+0x95>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <system+0x9b>
mov    -0x14(%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
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     116f <system+0x2f>
test   %eax,%eax
je     1175 <system+0x35>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
je     116f <system+0x2f>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe84(%rip),%rdi
lea    0xe82(%rip),%rsi
lea    0xe7e(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1050 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>

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 i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 (...) @fork()
store i32 %6, i32* %5
switch i32 %6, label %12 [
i32 -1, label %7
i32 0, label %8
]
7: ; preds = %1
store i32 -1, i32* %2
br label %19
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = 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* %9, i8* null)
%11 = call i32 @_exit(i32 127)
unreachable
12: ; preds = %1
%13 = load i32, i32* %5
%14 = call i32 @waitpid(i32 %13, i32* %4, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %2
br label %19
17: ; preds = %12
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %19
19: ; preds = %17, %16, %7
%20 = load i32, i32* %2
ret i32 %20
}

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 = tail call i32 (...) @fork()
switch i32 %4, label %8 [
i32 -1, label %13
i32 0, label %5
]
5: ; preds = %1
%6 = 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, i8* null)
%7 = tail call i32 @_exit(i32 127)
unreachable
8: ; preds = %1
%9 = call i32 @waitpid(i32 %4, i32* %2, i32 0)
%10 = icmp eq i32 %9, -1
%11 = load i32, i32* %2
%12 = select i1 %10, i32 -1, i32 %11
br label %13
13: ; preds = %8, %1
%14 = phi i32 [ %4, %1 ], [ %12, %8 ]
ret i32 %14
}