int System(c)
char *c;
{
  int pid, status;
  switch (pid = fork()) {
  case -1:
    return -1;
  case 0:
    execl("/bin/sh", "sh", "-c", c, (char *)0);
    execl("/usr/bin/sh", "sh", "-c", c, (char *)0);
    exit(-1);
  default:
    while (wait(&status) != pid)
      ;
  }
  return status;
}


x86 assembly (clang, -O0):
<System>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     1179 <System+0x39>
jmp    1169 <System+0x29>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     1185 <System+0x45>
jmp    11d9 <System+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    1202 <System+0xc2>
mov    -0x10(%rbp),%rcx
lea    0xe77(%rip),%rdi
lea    0xe75(%rip),%rsi
lea    0xe62(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1040 <execl@plt>
mov    -0x10(%rbp),%rcx
lea    0xe4e(%rip),%rdi
lea    0xe50(%rip),%rsi
lea    0xe3d(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1040 <execl@plt>
mov    $0xffffffff,%edi
call   1030 <exit@plt>
jmp    11de <System+0x9e>
lea    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <wait@plt>
cmp    -0x14(%rbp),%eax
je     11f7 <System+0xb7>
jmp    11de <System+0x9e>
jmp    11fc <System+0xbc>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<System>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1182 <System+0x42>
test   %ebp,%ebp
je     118d <System+0x4d>
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <wait@plt>
cmp    %ebp,%eax
jne    1170 <System+0x30>
mov    0xc(%rsp),%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe73(%rip),%rdi
lea    0xe71(%rip),%rbp
lea    0xe5e(%rip),%r14
mov    %rbp,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1040 <execl@plt>
lea    0xe47(%rip),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1040 <execl@plt>
mov    $0xffffffff,%edi
call   1030 <exit@plt>

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"
@.str.3 = [12 x i8] c"/usr/bin/sh\00"
define i32 @System(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 (...) @fork()
store i32 %6, i32* %4
switch i32 %6, label %13 [
i32 -1, label %7
i32 0, label %8
]
7: ; preds = %1
store i32 -1, i32* %2
br label %22
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @execl to i32 (i8*, i8*, i8*, i8*, i8*, ...)*)(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* %9, i8* null)
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @execl to i32 (i8*, i8*, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, 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* %11, i8* null)
unreachable
13: ; preds = %1
br label %14
14: ; preds = %18, %13
%15 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %5)
%16 = load i32, i32* %4
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
br label %14
19: ; preds = %14
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %7
%23 = load i32, i32* %2
ret i32 %23
}

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"
@.str.3 = [12 x i8] c"/usr/bin/sh\00"
define i32 @System(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
switch i32 %4, label %8 [
i32 -1, label %13
i32 0, label %5
]
5: ; preds = %1
%6 = tail call i32 (i8*, i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @execl to i32 (i8*, i8*, i8*, i8*, i8*, ...)*)(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)
%7 = tail call i32 (i8*, i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @execl to i32 (i8*, i8*, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, 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)
tail call void @exit(i32 -1)
unreachable
8: ; preds = %1, %8
%9 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %2)
%10 = icmp eq i32 %9, %4
br i1 %10, label %11, label %8
11: ; preds = %8
%12 = load i32, i32* %2
br label %13
13: ; preds = %1, %11
%14 = phi i32 [ %12, %11 ], [ %4, %1 ]
ret i32 %14
}