#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 /*<<< orphan*/ execve(char *, char **const, int /*<<< orphan*/ *);
int fork();
int wait(int /*<<< orphan*/ *);
int system(const char *string) {
  char const *const argv[] = {"sh", "-c", (char const *const)string, NULL};
  if (string != NULL) {
    int pid = fork();
    if (pid == 0) {
      execve("/bin/sh", (char **const)argv, NULL);
    } else if (pid > 0) {
      while (wait(NULL) != pid)
        ;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xec5(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xeb2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11cf <system+0x9f>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    119a <system+0x6a>
lea    -0x30(%rbp),%rsi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <execve@plt>
jmp    11ca <system+0x9a>
cmpl   $0x0,-0x34(%rbp)
jle    11c5 <system+0x95>
jmp    11a9 <system+0x79>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <wait@plt>
cmp    -0x34(%rbp),%eax
je     11c0 <system+0x90>
jmp    11a9 <system+0x79>
jmp    11c5 <system+0x95>
jmp    11ca <system+0x9a>
jmp    11cf <system+0x9f>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<system>:
push   %rbx
sub    $0x20,%rsp
lea    0xecc(%rip),%rax
mov    %rax,(%rsp)
lea    0xeb9(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %rdi,0x10(%rsp)
movq   $0x0,0x18(%rsp)
test   %rdi,%rdi
je     118e <system+0x5e>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     117d <system+0x4d>
jle    118e <system+0x5e>
mov    %eax,%ebx
xchg   %ax,%ax
xor    %edi,%edi
call   1040 <wait@plt>
cmp    %ebx,%eax
jne    1170 <system+0x40>
jmp    118e <system+0x5e>
lea    0xe7f(%rip),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <execve@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [8 x i8] c"/bin/sh\00"
define i32 @system(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i8*]
%4 = alloca i32
store i8* %0, i8** %2
%5 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds i8*, i8** %5, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds i8*, i8** %6, i64 1
%8 = load i8*, i8** %2
store i8* %8, i8** %7
%9 = getelementptr inbounds i8*, i8** %7, i64 1
store i8* null, i8** %9
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %31
12: ; preds = %1
%13 = call i32 (...) @fork()
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%18 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %17, i32* null)
br label %30
19: ; preds = %12
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
br label %23
23: ; preds = %27, %22
%24 = call i32 @wait(i32* null)
%25 = load i32, i32* %4
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %23
28: ; preds = %23
br label %29
29: ; preds = %28, %19
br label %30
30: ; preds = %29, %16
br label %31
31: ; preds = %30, %1
ret i32 -1
}

LLVM IR (-O2):
@.str = [3 x i8] c"sh\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [8 x i8] c"/bin/sh\00"
define i32 @system(i8* %0) {
%2 = alloca [4 x i8*]
%3 = bitcast [4 x i8*]* %2 to i8*
%4 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 2
store i8* %0, i8** %6
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 3
store i8* null, i8** %7
%8 = icmp eq i8* %0, null
br i1 %8, label %19, label %9
9: ; preds = %1
%10 = tail call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %4, i32* null)
br label %19
14: ; preds = %9
%15 = icmp sgt i32 %10, 0
br i1 %15, label %16, label %19
16: ; preds = %14, %16
%17 = tail call i32 @wait(i32* null)
%18 = icmp eq i32 %17, %10
br i1 %18, label %19, label %16
19: ; preds = %16, %12, %14, %1
ret i32 -1
}