#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 WEXITSTATUS(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int execute(char **argv) {
  pid_t p;
  int status;
  p = fork();
  switch (p) {
  case -1:
    return -1;
  case 0:
    execvp(argv[0], argv);
    exit(1);
    break;
  default:
    waitpid(p, &status, 0);
    break;
  }
  return WEXITSTATUS(status);
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     118a <execute+0x3a>
jmp    117a <execute+0x2a>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     1196 <execute+0x46>
jmp    11b0 <execute+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <execute+0x79>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execvp@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    -0x18(%rbp),%edi
call   1030 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
cmp    $0xffffffff,%eax
je     117f <execute+0x2f>
test   %eax,%eax
je     1185 <execute+0x35>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1030 <WEXITSTATUS@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execvp@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
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* %4
%7 = load i32, i32* %4
switch i32 %7, label %16 [
i32 -1, label %8
i32 0, label %9
]
8: ; preds = %1
store i32 -1, i32* %2
br label %22
9: ; preds = %1
%10 = load i8**, i8*** %3
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = load i8**, i8*** %3
%14 = call i32 @execvp(i8* %12, i8** %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i32, i32* %4
%18 = call i32 @waitpid(i32 %17, i32* %5, i32 0)
br label %19
19: ; preds = %16
%20 = load i32, i32* %5
%21 = call i32 @WEXITSTATUS(i32 %20)
store i32 %21, i32* %2
br label %22
22: ; preds = %19, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @execute(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
switch i32 %4, label %9 [
i32 -1, label %13
i32 0, label %5
]
5: ; preds = %1
%6 = load i8*, i8** %0
%7 = tail call i32 @execvp(i8* %6, i8** %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = call i32 @waitpid(i32 %4, i32* %2, i32 0)
%11 = load i32, i32* %2
%12 = call i32 @WEXITSTATUS(i32 %11)
br label %13
13: ; preds = %1, %9
%14 = phi i32 [ %12, %9 ], [ %4, %1 ]
ret i32 %14
}