#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ _exit(int);
scalar_t__ errno;
int /*<<< orphan*/ execvp(char const *, char *const *);
scalar_t__ fork();
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int xsystem(const char *file, char *const argv[]) {
  pid_t pid;
  int status;
  if ((pid = fork()) < 0)
    return (-1);
  if (pid == 0) {
    execvp(file, argv);
    _exit(127);
  }
  while (waitpid(pid, &status, 0) < 0) {
    if (errno != EINTR)
      return (-1);
  }
  return (status);
}


x86 assembly (clang, -O0):
<xsystem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1171 <xsystem+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <xsystem+0xa2>
cmpq   $0x0,-0x20(%rbp)
jne    1193 <xsystem+0x53>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <execvp@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
jmp    1198 <xsystem+0x58>
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    11dc <xsystem+0x9c>
mov    0x2e28(%rip),%rax
mov    (%rax),%rax
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%rax
je     11d7 <xsystem+0x97>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <xsystem+0xa2>
jmp    1198 <xsystem+0x58>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xsystem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     11a3 <xsystem+0x63>
je     11b3 <xsystem+0x73>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
mov    0x2e6b(%rip),%r12
mov    0x2e5c(%rip),%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %rax,%rax
jns    119e <xsystem+0x5e>
mov    (%r12),%rax
cmp    0x0(%rbp),%rax
je     1180 <xsystem+0x40>
jmp    11a3 <xsystem+0x63>
mov    0xc(%rsp),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <execvp@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @xsystem(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %32
11: ; preds = %2
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i8**, i8*** %5
%17 = call i32 @execvp(i8* %15, i8** %16)
%18 = call i32 @_exit(i32 127)
unreachable
19: ; preds = %11
br label %20
20: ; preds = %29, %19
%21 = load i64, i64* %6
%22 = call i64 @waitpid(i64 %21, i32* %7, i32 0)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -1, i32* %3
br label %32
29: ; preds = %24
br label %20
30: ; preds = %20
%31 = load i32, i32* %7
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %28, %10
%33 = load i32, i32* %3
ret i32 %33
}

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