#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*/ execvp(char *, char **);
scalar_t__ fork();
scalar_t__ getpid();
int execute_command(char *bin, char **args) {
  pid_t pid = fork();
  if (pid == 0) {
    execvp(args[0], args);
  } else if (pid < 0) {
    return -1;
  } else {
    pid = getpid();
  }
  return 0;
}


x86 assembly (clang, -O0):
<execute_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <execute_command+0x3b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <execvp@plt>
jmp    1192 <execute_command+0x62>
cmpq   $0x0,-0x20(%rbp)
jge    1182 <execute_command+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <execute_command+0x69>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x20(%rbp)
jmp    1192 <execute_command+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_command>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1152 <execute_command+0x22>
js     115f <execute_command+0x2f>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
jmp    1164 <execute_command+0x34>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1040 <execvp@plt>
jmp    1164 <execute_command+0x34>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @execute_command(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %5
%15 = call i32 @execvp(i8* %13, i8** %14)
br label %23
16: ; preds = %2
%17 = load i64, i64* %6
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %3
br label %24
20: ; preds = %16
%21 = call i64 (...) @getpid()
store i64 %21, i64* %6
br label %22
22: ; preds = %20
br label %23
23: ; preds = %22, %10
store i32 0, i32* %3
br label %24
24: ; preds = %23, %19
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @execute_command(i8* nocapture readnone %0, i8** %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @execvp(i8* %6, i8** %1)
br label %12
8: ; preds = %2
%9 = icmp slt i64 %3, 0
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = tail call i64 (...) @getpid()
br label %12
12: ; preds = %5, %10, %8
%13 = phi i32 [ -1, %8 ], [ 0, %10 ], [ 0, %5 ]
ret i32 %13
}