#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 /*<<< orphan*/ execl(char *, char *, char *, char const *,
                         int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int my_system(const char *command) {
  int pid, status;
  if ((pid = fork()) == 0) {
    execl("sh", "sh", "-c", command, NULL);
    _exit(100);
  }
  waitpid(pid, &status, 0);
  if (!WIFEXITED(status))
    fprintf(stderr,
            "CS2MONITOT: Error while executing '%s': "
            "Anormal exit.\n",
            command);
  else if (WEXITSTATUS(status) && WEXITSTATUS(status) != 1)
    fprintf(stderr,
            "CS2MONITOT: Error while executing '%s': "
            "Returncode is %d.\n",
            command, WEXITSTATUS(status));
  return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
}


x86 assembly (clang, -O0):
<my_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    11b8 <my_system+0x48>
mov    -0x8(%rbp),%rcx
lea    0xe66(%rip),%rsi
lea    0xe62(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1080 <execl@plt>
mov    $0x64,%edi
call   1030 <_exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x10(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
jne    11f8 <my_system+0x88>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1252 <my_system+0xe2>
mov    -0x10(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     124d <my_system+0xdd>
mov    -0x10(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x1,%eax
je     124d <my_system+0xdd>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %eax,%ecx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1252 <my_system+0xe2>
mov    -0x10(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1274 <my_system+0x104>
mov    -0x10(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,-0x20(%rbp)
jmp    1281 <my_system+0x111>
mov    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1281 <my_system+0x111>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_system>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1224 <my_system+0xb4>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11e5 <my_system+0x75>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
test   %eax,%eax
je     11ff <my_system+0x8f>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x1,%eax
je     11ff <my_system+0x8f>
mov    0x2e1d(%rip),%rax
mov    (%rax),%ebp
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xe68(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ff <my_system+0x8f>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     1218 <my_system+0xa8>
mov    0x4(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
jmp    121d <my_system+0xad>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdd5(%rip),%rdi
lea    0xdd1(%rip),%rdx
mov    %rdi,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1080 <execl@plt>
mov    $0x64,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@stderr = global i32 0
@.str.2 = [55 x i8] c"CS2MONITOT: Error while executing '%s': Anormal exit.\0A\00"
@.str.3 = [59 x i8] c"CS2MONITOT: Error while executing '%s': Returncode is %d.\0A\00"
define i32 @my_system(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @execl(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32* null)
%10 = call i32 @_exit(i32 100)
unreachable
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 @waitpid(i32 %12, i32* %4, i32 0)
%14 = load i32, i32* %4
%15 = call i64 @WIFEXITED(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %36
21: ; preds = %11
%22 = load i32, i32* %4
%23 = call i32 @WEXITSTATUS(i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32, i32* %4
%27 = call i32 @WEXITSTATUS(i32 %26)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %2
%32 = load i32, i32* %4
%33 = call i32 @WEXITSTATUS(i32 %32)
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 %33)
br label %35
35: ; preds = %29, %25, %21
br label %36
36: ; preds = %35, %17
%37 = load i32, i32* %4
%38 = call i64 @WIFEXITED(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %4
%42 = call i32 @WEXITSTATUS(i32 %41)
br label %44
43: ; preds = %36
br label %44
44: ; preds = %43, %40
%45 = phi i32 [ %42, %40 ], [ -1, %43 ]
ret i32 %45
}

LLVM IR (-O2):
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@stderr = global i32 0
@.str.2 = [55 x i8] c"CS2MONITOT: Error while executing '%s': Anormal exit.\0A\00"
@.str.3 = [59 x i8] c"CS2MONITOT: Error while executing '%s': Returncode is %d.\0A\00"
define i32 @my_system(i8* %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 %9
6: ; preds = %1
%7 = tail call i32 @execl(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
%8 = tail call i32 @_exit(i32 100)
unreachable
9: ; preds = %1
%10 = call i32 @waitpid(i32 %4, i32* %2, i32 0)
%11 = load i32, i32* %2
%12 = call i64 @WIFEXITED(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %30
17: ; preds = %9
%18 = load i32, i32* %2
%19 = call i32 @WEXITSTATUS(i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %17
%22 = load i32, i32* %2
%23 = call i32 @WEXITSTATUS(i32 %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i32, i32* %2
%28 = call i32 @WEXITSTATUS(i32 %27)
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %28)
br label %30
30: ; preds = %17, %21, %25, %14
%31 = load i32, i32* %2
%32 = call i64 @WIFEXITED(i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i32, i32* %2
%36 = call i32 @WEXITSTATUS(i32 %35)
br label %37
37: ; preds = %30, %34
%38 = phi i32 [ %36, %34 ], [ -1, %30 ]
ret i32 %38
}