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


x86 assembly (clang, -O0):
<system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116a <system+0x2a>
movl   $0x1,-0x4(%rbp)
jmp    121c <system+0xdc>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    118b <system+0x4b>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1216 <system+0xd6>
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <system+0x83>
mov    -0x10(%rbp),%rcx
lea    0xe5f(%rip),%rdi
lea    0xe60(%rip),%rsi
lea    0xe6b(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <execl@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
jmp    11c8 <system+0x88>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    120c <system+0xcc>
mov    0x2df8(%rip),%rax
mov    (%rax),%rax
mov    0x2de6(%rip),%rcx
cmp    (%rcx),%rax
je     1207 <system+0xc7>
movl   $0xffffffff,-0x1c(%rbp)
jmp    120c <system+0xcc>
jmp    11c8 <system+0x88>
jmp    1211 <system+0xd1>
jmp    1216 <system+0xd6>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
test   %rdi,%rdi
je     11ae <system+0x6e>
mov    %rdi,%rbp
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     11bb <system+0x7b>
je     11cb <system+0x8b>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
mov    0x2e61(%rip),%r12
mov    0x2e52(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %rax,%rax
jns    11b6 <system+0x76>
mov    (%r12),%rax
cmp    0x0(%rbp),%rax
je     1190 <system+0x50>
jmp    11bb <system+0x7b>
mov    $0x1,%r14d
jmp    11bb <system+0x7b>
mov    0xc(%rsp),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2e(%rip),%rdi
lea    0xe2f(%rip),%rsi
lea    0xe3a(%rip),%rdx
mov    %rbp,%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 = [18 x i8] c"xxxxxxxxxxxx11111\00"
@.str.2 = [3 x i8] c"-c\00"
@errno = global i64 0
@EINTR = global i64 0
define i32 @system(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%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 %35
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 %33
13: ; preds = %9
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 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 = call i32 @_exit(i32 127)
unreachable
20: ; preds = %13
br label %21
21: ; preds = %30, %20
%22 = load i64, i64* %4
%23 = call i64 @waitpid(i64 %22, i32* %5, i32 0)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINTR
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %5
br label %31
30: ; preds = %25
br label %21
31: ; preds = %29, %21
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32, %12
%34 = load i32, i32* %5
store i32 %34, i32* %2
br label %35
35: ; preds = %33, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [18 x i8] c"xxxxxxxxxxxx11111\00"
@.str.2 = [3 x i8] c"-c\00"
@errno = global i64 0
@EINTR = global i64 0
define i32 @system(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = tail call i64 (...) @fork()
%7 = icmp slt i64 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = icmp eq i64 %6, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 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 = tail call i32 @_exit(i32 127)
unreachable
13: ; preds = %8, %16
%14 = call i64 @waitpid(i64 %6, i32* %2, i32 0)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br i1 %19, label %13, label %22
20: ; preds = %13
%21 = load i32, i32* %2
br label %22
22: ; preds = %16, %5, %20, %1
%23 = phi i32 [ 1, %1 ], [ %21, %20 ], [ -1, %5 ], [ -1, %16 ]
ret i32 %23
}