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


x86 assembly (clang, -O0):
<system_clone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <system_clone+0x23>
movl   $0x1,-0x4(%rbp)
jmp    1224 <system_clone+0xe4>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1184 <system_clone+0x44>
movl   $0xffffffff,-0x1c(%rbp)
jmp    121e <system_clone+0xde>
cmpq   $0x0,-0x18(%rbp)
jne    11cb <system_clone+0x8b>
mov    -0x10(%rbp),%rcx
lea    0xe66(%rip),%rdi
lea    0xe64(%rip),%rsi
lea    0xe60(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <execl@plt>
cmp    $0x0,%rax
jge    11c6 <system_clone+0x86>
mov    $0x7f,%edi
call   1030 <_exit@plt>
jmp    1219 <system_clone+0xd9>
jmp    11d0 <system_clone+0x90>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    1214 <system_clone+0xd4>
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
je     120f <system_clone+0xcf>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1214 <system_clone+0xd4>
jmp    11d0 <system_clone+0x90>
jmp    1219 <system_clone+0xd9>
jmp    121e <system_clone+0xde>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system_clone>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     119e <system_clone+0x5e>
mov    %rdi,%rbp
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     11da <system_clone+0x9a>
je     11a6 <system_clone+0x66>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
mov    0x2e69(%rip),%r12
mov    0x2e5a(%rip),%rbp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %rax,%rax
jns    11d5 <system_clone+0x95>
mov    (%r12),%rax
cmp    0x0(%rbp),%rax
je     1180 <system_clone+0x40>
jmp    11da <system_clone+0x9a>
mov    $0x1,%r14d
jmp    11da <system_clone+0x9a>
lea    0xe53(%rip),%rdi
lea    0xe51(%rip),%rsi
lea    0xe4d(%rip),%rdx
mov    %rbp,%rcx
xor    %r8d,%r8d
call   1050 <execl@plt>
test   %rax,%rax
jns    11da <system_clone+0x9a>
mov    $0x7f,%edi
call   1030 <_exit@plt>
mov    0xc(%rsp),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
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"
@errno = global i64 0
@EINTR = global i64 0
define i32 @system_clone(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* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %38
9: ; preds = %1
%10 = call i64 (...) @fork()
store i64 %10, i64* %4
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 -1, i32* %5
br label %36
13: ; preds = %9
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = call i64 @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* %17, i8* null)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @_exit(i32 127)
unreachable
22: ; preds = %16
br label %35
23: ; preds = %13
br label %24
24: ; preds = %33, %23
%25 = load i64, i64* %4
%26 = call i64 @waitpid(i64 %25, i32* %5, i32 0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i64, i64* @errno
%30 = load i64, i64* @EINTR
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -1, i32* %5
br label %34
33: ; preds = %28
br label %24
34: ; preds = %32, %24
br label %35
35: ; preds = %34, %22
br label %36
36: ; preds = %35, %12
%37 = load i32, i32* %5
store i32 %37, i32* %2
br label %38
38: ; preds = %36, %8
%39 = load i32, i32* %2
ret i32 %39
}

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"
@errno = global i64 0
@EINTR = global i64 0
define i32 @system_clone(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = tail call i64 (...) @fork()
%7 = icmp slt i64 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = icmp eq i64 %6, 0
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = tail call i64 @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)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = tail call i32 @_exit(i32 127)
unreachable
15: ; preds = %8, %18
%16 = call i64 @waitpid(i64 %6, i32* %2, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br i1 %21, label %15, label %24
22: ; preds = %15
%23 = load i32, i32* %2
br label %24
24: ; preds = %18, %5, %10, %22, %1
%25 = phi i32 [ 1, %1 ], [ %23, %22 ], [ undef, %10 ], [ -1, %5 ], [ -1, %18 ]
ret i32 %25
}