#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*/ exit(int);
int fork();
int /*<<< orphan*/ wait(int *);
int _system(const char *path) {
  int pid, st;
  if ((pid = fork()) == 0) {
    exit(-1);
  } else if (pid < 0)
    return -1;
  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    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1179 <_system+0x29>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jge    118f <_system+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <_system+0x76>
jmp    1194 <_system+0x44>
lea    -0x18(%rbp),%rdi
call   1060 <wait@plt>
mov    -0x18(%rbp),%edi
call   1040 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11bf <_system+0x6f>
mov    -0x18(%rbp),%edi
call   1030 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    11c6 <_system+0x76>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_system>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1192 <_system+0x42>
mov    $0xffffffff,%ebx
js     118a <_system+0x3a>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
mov    0xc(%rsp),%edi
call   1040 <WIFEXITED@plt>
test   %rax,%rax
je     118a <_system+0x3a>
mov    0xc(%rsp),%edi
call   1030 <WEXITSTATUS@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
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* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 -1, i32* %2
br label %24
14: ; preds = %10
br label %15
15: ; preds = %14
%16 = call i32 @wait(i32* %5)
%17 = load i32, i32* %5
%18 = call i64 @WIFEXITED(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %5
%22 = call i32 @WEXITSTATUS(i32 %21)
store i32 %22, i32* %2
br label %24
23: ; preds = %15
store i32 -1, i32* %2
br label %24
24: ; preds = %23, %20, %13
%25 = load i32, i32* %2
ret i32 %25
}

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