#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 /*<<< orphan*/ execv(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int execute(char *program, char *arguments[]) {
  pid_t parent_id;
  int status;
  parent_id = fork();
  if (parent_id < 0) {
    fprintf(stderr, "%s\n",
            "Couldn't create a child process for tool execution.");
    return -1;
  } else if (parent_id > 0) {
    waitpid(parent_id, &status, 0);
    return status;
  } else {
    execv(program, arguments);
  }
  return -1;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    118e <execute+0x4e>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
lea    0xe87(%rip),%rdx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <execute+0x8c>
cmpq   $0x0,-0x20(%rbp)
jle    11b3 <execute+0x73>
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cc <execute+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <execv@plt>
jmp    11c5 <execute+0x85>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     116d <execute+0x2d>
je     118b <execute+0x4b>
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x4(%rsp),%eax
jmp    119b <execute+0x5b>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
lea    0xe80(%rip),%rdx
call   1030 <fprintf@plt>
jmp    1196 <execute+0x56>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <execv@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [52 x i8] c"Couldn't create a child process for tool execution.\00"
define i32 @execute(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
14: ; preds = %2
%15 = load i64, i64* %6
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* %6
%19 = call i32 @waitpid(i64 %18, i32* %7, i32 0)
%20 = load i32, i32* %7
store i32 %20, i32* %3
br label %27
21: ; preds = %14
%22 = load i8*, i8** %4
%23 = load i8**, i8*** %5
%24 = call i32 @execv(i8* %22, i8** %23)
br label %25
25: ; preds = %21
br label %26
26: ; preds = %25
store i32 -1, i32* %3
br label %27
27: ; preds = %26, %17, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [52 x i8] c"Couldn't create a child process for tool execution.\00"
define i32 @execute(i8* %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %17
10: ; preds = %2
%11 = icmp eq i64 %5, 0
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = call i32 @waitpid(i64 %5, i32* %3, i32 0)
%14 = load i32, i32* %3
br label %17
15: ; preds = %10
%16 = tail call i32 @execv(i8* %0, i8** %1)
br label %17
17: ; preds = %15, %12, %7
%18 = phi i32 [ -1, %7 ], [ %14, %12 ], [ -1, %15 ]
ret i32 %18
}