#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;
typedef scalar_t__ EX_OSERR;

/* Variables and functions */
scalar_t__ EX__BASE;
int WEXITSTATUS(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(scalar_t__);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int bee_execute_command(char *command[], int flags) {
  pid_t fpid, wpid;
  int wstatus;
  fpid = fork();
  if (fpid < 0) {
    perror("fork");
    return -1;
  } else if (fpid == 0) {
    execvp(command[0], command);
    perror("execvp");
    exit(((EX_OSERR)-EX__BASE + 96));
  } else {
    do {
      wpid = waitpid(fpid, &wstatus, 0);
    } while (wpid != fpid);
  }
  return WEXITSTATUS(wstatus);
}


x86 assembly (clang, -O0):
<bee_execute_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    119d <bee_execute_command+0x3d>
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <bee_execute_command+0xb6>
cmpq   $0x0,-0x20(%rbp)
jne    11db <bee_execute_command+0x7b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execvp@plt>
lea    0xe46(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    0x2e11(%rip),%rax
sub    (%rax),%rdi
add    $0x60,%rdi
call   1070 <exit@plt>
jmp    11e0 <bee_execute_command+0x80>
mov    -0x20(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11e0 <bee_execute_command+0x80>
jmp    1206 <bee_execute_command+0xa6>
jmp    120b <bee_execute_command+0xab>
mov    -0x2c(%rbp),%edi
call   1030 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bee_execute_command>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11a3 <bee_execute_command+0x43>
je     11b6 <bee_execute_command+0x56>
mov    %rax,%rbx
lea    0x4(%rsp),%r14
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    %rbx,%rax
jne    1180 <bee_execute_command+0x20>
mov    0x4(%rsp),%edi
call   1030 <WEXITSTATUS@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe56(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    119b <bee_execute_command+0x3b>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
lea    0xe3d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e0c(%rip),%rax
mov    $0x60,%edi
sub    (%rax),%rdi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [7 x i8] c"execvp\00"
@EX__BASE = global i64 0
define i32 @bee_execute_command(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
%9 = call i64 (...) @fork()
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %41
14: ; preds = %2
%15 = load i64, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %4
%22 = call i32 @execvp(i8* %20, i8** %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = load i64, i64* @EX__BASE
%25 = sub nsw i64 0, %24
%26 = add nsw i64 %25, 96
%27 = call i32 @exit(i64 %26)
unreachable
28: ; preds = %14
br label %29
29: ; preds = %32, %28
%30 = load i64, i64* %6
%31 = call i64 @waitpid(i64 %30, i32* %8, i32 0)
store i64 %31, i64* %7
br label %32
32: ; preds = %29
%33 = load i64, i64* %7
%34 = load i64, i64* %6
%35 = icmp ne i64 %33, %34
br i1 %35, label %29, label %36
36: ; preds = %32
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
%39 = load i32, i32* %8
%40 = call i32 @WEXITSTATUS(i32 %39)
store i32 %40, i32* %3
br label %41
41: ; preds = %38, %12
%42 = load i32, i32* %3
ret i32 %42
}

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