int execute(argv)
char **argv;
{
  int pid, r, status;
  if ((pid = fork()) < 0) {
    perr("fork()");
    return 0;
  }
  if (pid == 0) {
    execvp(argv[0], argv);
    perrx(argv[0]);
  }
  while ((r = wait(&status)) != pid) {
    if (r < 0) {
      perr(argv[0]);
      return 0;
    }
  }
  return status == 0;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1189 <execute+0x39>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <perr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1207 <execute+0xb7>
cmpl   $0x0,-0x14(%rbp)
jne    11b3 <execute+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <execvp@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x0,%al
call   1030 <perrx@plt>
jmp    11b8 <execute+0x68>
lea    -0x1c(%rbp),%rdi
mov    $0x0,%al
call   1060 <wait@plt>
mov    %eax,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
je     11f8 <execute+0xa8>
cmpl   $0x0,-0x18(%rbp)
jge    11f3 <execute+0xa3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x0,%al
call   1040 <perr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1207 <execute+0xb7>
jmp    11b8 <execute+0x68>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
js     11a9 <execute+0x59>
mov    %eax,%ebp
jne    1183 <execute+0x33>
mov    (%r14),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <execvp@plt>
mov    (%r14),%rdi
xor    %eax,%eax
call   1030 <perrx@plt>
lea    0xc(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <wait@plt>
cmp    %ebp,%eax
je     11b9 <execute+0x69>
test   %eax,%eax
jns    1190 <execute+0x40>
mov    (%r14),%rdi
xor    %ebx,%ebx
jmp    11b0 <execute+0x60>
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1040 <perr@plt>
jmp    11c3 <execute+0x73>
xor    %ebx,%ebx
cmpl   $0x0,0xc(%rsp)
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"fork()\00"
define i32 @execute(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
%7 = call i32 (...) @fork()
store i32 %7, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @perr to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %42
11: ; preds = %1
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %3
%19 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execvp to i32 (i8*, i8**, ...)*)(i8* %17, i8** %18)
%20 = load i8**, i8*** %3
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) bitcast (i32 (...)* @perrx to i32 (i8*, ...)*)(i8* %22)
br label %24
24: ; preds = %14, %11
br label %25
25: ; preds = %37, %24
%26 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %6)
store i32 %26, i32* %5
%27 = load i32, i32* %4
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8**, i8*** %3
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) bitcast (i32 (...)* @perr to i32 (i8*, ...)*)(i8* %35)
store i32 0, i32* %2
br label %42
37: ; preds = %29
br label %25
38: ; preds = %25
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, 0
%41 = zext i1 %40 to i32
store i32 %41, i32* %2
br label %42
42: ; preds = %38, %32, %9
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@.str = [7 x i8] c"fork()\00"
define i32 @execute(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, ...) bitcast (i32 (...)* @perr to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %28
8: ; preds = %1
%9 = icmp eq i32 %4, 0
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = load i8*, i8** %0
%12 = tail call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execvp to i32 (i8*, i8**, ...)*)(i8* %11, i8** %0)
%13 = load i8*, i8** %0
%14 = tail call i32 (i8*, ...) bitcast (i32 (...)* @perrx to i32 (i8*, ...)*)(i8* %13)
br label %15
15: ; preds = %10, %8
br label %16
16: ; preds = %15, %19
%17 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %2)
%18 = icmp eq i32 %17, %4
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = icmp slt i32 %17, 0
br i1 %20, label %21, label %16
21: ; preds = %19
%22 = load i8*, i8** %0
%23 = call i32 (i8*, ...) bitcast (i32 (...)* @perr to i32 (i8*, ...)*)(i8* %22)
br label %28
24: ; preds = %16
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %24, %21, %6
%29 = phi i32 [ 0, %6 ], [ 0, %21 ], [ %27, %24 ]
ret i32 %29
}