#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 scalar_t__ pid_t;

/* Variables and functions */
int EXIT_FAILURE;
int WEXITSTATUS(int);
int execve(char *, char **, char **);
scalar_t__ fork();
int /*<<< orphan*/ wait(int *);
int execute(char *bin_path, char **argv, char **env) {
  pid_t child;
  int child_status;
  if ((child = fork()) == 0) {
    if (execve(bin_path, argv, env) == -1)
      return (EXIT_FAILURE);
  } else if (child > 0) {
    wait(&child_status);
    return (WEXITSTATUS(child_status));
  }
  return (EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1199 <execute+0x59>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <execve@plt>
cmp    $0xffffffff,%eax
jne    1194 <execute+0x54>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ce <execute+0x8e>
jmp    11c2 <execute+0x82>
cmpq   $0x0,-0x28(%rbp)
jle    11bd <execute+0x7d>
lea    -0x2c(%rbp),%rdi
call   1050 <wait@plt>
mov    -0x2c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    11ce <execute+0x8e>
jmp    11c2 <execute+0x82>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1175 <execute+0x35>
jle    1186 <execute+0x46>
lea    0xc(%rsp),%rdi
call   1050 <wait@plt>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
jmp    118f <execute+0x4f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <execve@plt>
cmp    $0xffffffff,%eax
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i32 @execute(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = call i64 (...) @fork()
store i64 %10, i64* %8
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8**, i8*** %6
%15 = load i8**, i8*** %7
%16 = call i32 @execve(i8* %13, i8** %14, i8** %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %4
br label %31
20: ; preds = %12
br label %29
21: ; preds = %3
%22 = load i64, i64* %8
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = call i32 @wait(i32* %9)
%26 = load i32, i32* %9
%27 = call i32 @WEXITSTATUS(i32 %26)
store i32 %27, i32* %4
br label %31
28: ; preds = %21
br label %29
29: ; preds = %28, %20
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %4
br label %31
31: ; preds = %29, %24, %18
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i32 @execute(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = tail call i32 @execve(i8* %0, i8** %1, i8** %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32, i32* @EXIT_FAILURE
br label %21
13: ; preds = %3
%14 = icmp sgt i64 %6, 0
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = call i32 @wait(i32* %4)
%17 = load i32, i32* %4
%18 = call i32 @WEXITSTATUS(i32 %17)
br label %21
19: ; preds = %13, %8
%20 = load i32, i32* @EXIT_FAILURE
br label %21
21: ; preds = %19, %15, %11
%22 = phi i32 [ %12, %11 ], [ %20, %19 ], [ %18, %15 ]
ret i32 %22
}