#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*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int execute(char **args) {
  int status;
  int pid;
  if ((pid = fork()) < 0) {
    perror("fork");
    exit(1);
  }
  if (pid == 0) {
    execvp(*args, args);
    perror(*args);
    return (pid);
  }
  return 0;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1175 <execute+0x35>
lea    0xe9a(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11a6 <execute+0x66>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <execvp@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <execute+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
js     116a <execute+0x2a>
je     1155 <execute+0x15>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1040 <execvp@plt>
mov    (%rbx),%rdi
call   1030 <perror@plt>
jmp    1151 <execute+0x11>
lea    0xe8f(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
define i32 @execute(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* %5
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i8**, i8*** %3
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %3
%18 = call i32 @execvp(i8* %16, i8** %17)
%19 = load i8**, i8*** %3
%20 = load i8*, i8** %19
%21 = call i32 @perror(i8* %20)
%22 = load i32, i32* %5
store i32 %22, i32* %2
br label %24
23: ; preds = %11
store i32 0, i32* %2
br label %24
24: ; preds = %23, %14
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
define i32 @execute(i8** %0) {
%2 = tail call i32 (...) @fork()
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = icmp eq i32 %2, 0
br i1 %8, label %9, label %14
9: ; preds = %7
%10 = load i8*, i8** %0
%11 = tail call i32 @execvp(i8* %10, i8** %0)
%12 = load i8*, i8** %0
%13 = tail call i32 @perror(i8* %12)
br label %14
14: ; preds = %7, %9
ret i32 0
}