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

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ free(char **);
char **parse(char *);
int /*<<< orphan*/ wait(int *);
int _system(char *command) {
  int pid, st;
  char **vect;
  vect = parse(command);
  if ((pid = fork()) == 0) {
    execvp(vect[0], vect);
    exit(-1);
  } else if (pid < 0) {
    free(vect);
    return -1;
  }
  free(vect);
  wait(&st);
  if (WIFEXITED(st))
    return WEXITSTATUS(st);
  else
    return -1;
}


x86 assembly (clang, -O0):
<_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <parse@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11c6 <_system+0x46>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <execvp@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jge    11e5 <_system+0x65>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1225 <_system+0xa5>
jmp    11ea <_system+0x6a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    -0x18(%rbp),%rdi
call   1090 <wait@plt>
mov    -0x18(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     121e <_system+0x9e>
mov    -0x18(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    1225 <_system+0xa5>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_system>:
push   %rbp
push   %rbx
push   %rax
call   1060 <parse@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11d5 <_system+0x55>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%ebx
test   %ebp,%ebp
js     11cc <_system+0x4c>
lea    0x4(%rsp),%rdi
call   1090 <wait@plt>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11cc <_system+0x4c>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
define i32 @_system(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8** @parse(i8* %7)
store i8** %8, i8*** %6
%9 = call i32 (...) @fork()
store i32 %9, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %6
%16 = call i32 @execvp(i8* %14, i8** %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %1
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8**, i8*** %6
%23 = call i32 @free(i8** %22)
store i32 -1, i32* %2
br label %36
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i8**, i8*** %6
%27 = call i32 @free(i8** %26)
%28 = call i32 @wait(i32* %5)
%29 = load i32, i32* %5
%30 = call i64 @WIFEXITED(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %5
%34 = call i32 @WEXITSTATUS(i32 %33)
store i32 %34, i32* %2
br label %36
35: ; preds = %25
store i32 -1, i32* %2
br label %36
36: ; preds = %35, %32, %21
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @_system(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i8** @parse(i8* %0)
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %4
%9 = tail call i32 @execvp(i8* %8, i8** %4)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %1
%12 = icmp slt i32 %5, 0
%13 = tail call i32 @free(i8** %4)
br i1 %12, label %22, label %14
14: ; preds = %11
%15 = call i32 @wait(i32* %2)
%16 = load i32, i32* %2
%17 = call i64 @WIFEXITED(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i32, i32* %2
%21 = call i32 @WEXITSTATUS(i32 %20)
br label %22
22: ; preds = %11, %14, %19
%23 = phi i32 [ %21, %19 ], [ -1, %14 ], [ -1, %11 ]
ret i32 %23
}