#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
char mysystem(char *value) {
  pid_t ret;
  ret = fork();
  switch (ret) {
  case -1:
    perror("fork failed\n");
    return -1;
    break;
  case 0:
    execl("/bin/sh", "sh", "-c", value, NULL);
    exit(0);
    break;
  default:
    wait(NULL);
    printf("parent process\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<mysystem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xffffffff,%eax
je     119a <mysystem+0x3a>
jmp    118a <mysystem+0x2a>
mov    -0x18(%rbp),%eax
test   %eax,%eax
je     11af <mysystem+0x4f>
jmp    11d9 <mysystem+0x79>
lea    0xe5f(%rip),%rdi
call   1040 <perror@plt>
movb   $0xff,-0x1(%rbp)
jmp    11f2 <mysystem+0x92>
mov    -0x10(%rbp),%rcx
lea    0xe53(%rip),%rdi
lea    0xe51(%rip),%rsi
lea    0xe4d(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <execl@plt>
xor    %edi,%edi
call   1050 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysystem>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     118d <mysystem+0x2d>
test   %eax,%eax
je     119d <mysystem+0x3d>
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe6c(%rip),%rdi
call   1040 <perror@plt>
mov    $0xff,%bl
jmp    1189 <mysystem+0x29>
lea    0xe69(%rip),%rdi
lea    0xe67(%rip),%rsi
lea    0xe63(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"fork failed\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"sh\00"
@.str.3 = [3 x i8] c"-c\00"
@.str.4 = [16 x i8] c"parent process\0A\00"
define signext i8 @mysystem(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 (...) @fork()
store i32 %5, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %13 [
i32 -1, label %7
i32 0, label %9
]
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8 -1, i8* %2
br label %17
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32* null)
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %1
%14 = call i32 @wait(i32* null)
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %13
store i8 0, i8* %2
br label %17
17: ; preds = %16, %7
%18 = load i8, i8* %2
ret i8 %18
}

LLVM IR (-O2):
@.str = [13 x i8] c"fork failed\0A\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"sh\00"
@.str.3 = [3 x i8] c"-c\00"
@str = [15 x i8] c"parent process\00"
define signext i8 @mysystem(i8* %0) {
%2 = tail call i32 (...) @fork()
switch i32 %2, label %8 [
i32 -1, label %3
i32 0, label %5
]
3: ; preds = %1
%4 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %11
5: ; preds = %1
%6 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32* null)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %1
%9 = tail call i32 @wait(i32* null)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %8, %3
%12 = phi i8 [ 0, %8 ], [ -1, %3 ]
ret i8 %12
}