#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 */

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ pl_fatal(char *);
char **realloc(char **, size_t);
void pl_exec_add(char *cmd) {
  static char **array = NULL;
  static size_t size = 0;
  array = realloc(array, (size + 1) * sizeof(char *));
  if (array == NULL)
    pl_fatal("realloc");
  array[size++] = cmd;
  if (cmd == NULL) {
    execvp(array[0], array);
    pl_fatal("execvp");
  }
}


x86 assembly (clang, -O0):
<pl_exec_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2efd(%rip),%rdi
mov    0x2efe(%rip),%rsi
add    $0x1,%rsi
shl    $0x3,%rsi
call   1030 <realloc@plt>
mov    %rax,0x2ee2(%rip)
cmpq   $0x0,0x2eda(%rip)
jne    1178 <pl_exec_add+0x48>
lea    0xe8d(%rip),%rdi
call   1050 <pl_fatal@plt>
mov    -0x8(%rbp),%rdx
mov    0x2ebd(%rip),%rax
mov    0x2ebe(%rip),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,0x2eb0(%rip)
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x0,-0x8(%rbp)
jne    11c9 <pl_exec_add+0x99>
mov    0x2e92(%rip),%rax
mov    (%rax),%rdi
mov    0x2e88(%rip),%rsi
call   1040 <execvp@plt>
lea    0xe44(%rip),%rdi
call   1050 <pl_fatal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pl_exec_add>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2f02(%rip),%rdi
mov    0x2f03(%rip),%rbx
lea    0x8(,%rbx,8),%rsi
call   1030 <realloc@plt>
mov    %rax,0x2ee7(%rip)
test   %rax,%rax
jne    1178 <pl_exec_add+0x48>
lea    0xe9b(%rip),%rdi
call   1050 <pl_fatal@plt>
mov    0x2ecf(%rip),%rax
mov    0x2ed0(%rip),%rbx
lea    0x1(%rbx),%rcx
mov    %rcx,0x2ec5(%rip)
mov    %r14,(%rax,%rbx,8)
test   %r14,%r14
je     1194 <pl_exec_add+0x64>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rax),%rdi
mov    %rax,%rsi
call   1040 <execvp@plt>
lea    0xe62(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <pl_fatal@plt>

LLVM IR (-O0):
@pl_exec_add.array = internal global i8** null
@pl_exec_add.size = internal global i64 0
@.str = [8 x i8] c"realloc\00"
@.str.1 = [7 x i8] c"execvp\00"
define void @pl_exec_add(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8**, i8*** @pl_exec_add.array
%4 = load i64, i64* @pl_exec_add.size
%5 = add i64 %4, 1
%6 = mul i64 %5, 8
%7 = call i8** @realloc(i8** %3, i64 %6)
store i8** %7, i8*** @pl_exec_add.array
%8 = load i8**, i8*** @pl_exec_add.array
%9 = icmp eq i8** %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @pl_fatal(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i8*, i8** %2
%14 = load i8**, i8*** @pl_exec_add.array
%15 = load i64, i64* @pl_exec_add.size
%16 = add i64 %15, 1
store i64 %16, i64* @pl_exec_add.size
%17 = getelementptr inbounds i8*, i8** %14, i64 %15
store i8* %13, i8** %17
%18 = load i8*, i8** %2
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %27
20: ; preds = %12
%21 = load i8**, i8*** @pl_exec_add.array
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = load i8**, i8*** @pl_exec_add.array
%25 = call i32 @execvp(i8* %23, i8** %24)
%26 = call i32 @pl_fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %20, %12
ret void
}

LLVM IR (-O2):
@pl_exec_add.array = internal unnamed_addr global i8** null
@pl_exec_add.size = internal unnamed_addr global i64 0
@.str = [8 x i8] c"realloc\00"
@.str.1 = [7 x i8] c"execvp\00"
define void @pl_exec_add(i8* %0) {
%2 = load i8**, i8*** @pl_exec_add.array
%3 = load i64, i64* @pl_exec_add.size
%4 = shl i64 %3, 3
%5 = add i64 %4, 8
%6 = tail call i8** @realloc(i8** %2, i64 %5)
store i8** %6, i8*** @pl_exec_add.array
%7 = icmp eq i8** %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i32 @pl_fatal(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = load i8**, i8*** @pl_exec_add.array
%11 = load i64, i64* @pl_exec_add.size
br label %12
12: ; preds = %8, %1
%13 = phi i64 [ %11, %8 ], [ %3, %1 ]
%14 = phi i8** [ %10, %8 ], [ %6, %1 ]
%15 = add i64 %13, 1
store i64 %15, i64* @pl_exec_add.size
%16 = getelementptr inbounds i8*, i8** %14, i64 %13
store i8* %0, i8** %16
%17 = icmp eq i8* %0, null
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i8*, i8** %14
%20 = tail call i32 @execvp(i8* %19, i8** %14)
%21 = tail call i32 @pl_fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %18, %12
ret void
}