#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, int,
                           char *);
int getpid();
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
char **realloc(char **, size_t);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *strerror(int /*<<< orphan*/);
int append_arg(char *data, char ***arg, size_t *index, size_t *capacity) {
  if (*index >= *capacity) {
    *capacity <<= 1;
    *arg = realloc(*arg, *capacity * sizeof(char *));
    if (*arg == NULL) {
      fprintf(stderr,
              "kickstart[%d]: %s[%d]: "
              "realloc: %s\n",
              getpid(),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/"
              "src/tools/pegasus-kickstart/invoke.c",
              37, strerror(errno));
      return -1;
    }
    memset(*arg + *index, 0, sizeof(char *) * (*capacity - *index));
  }
  if (data == NULL) {
    (*arg)[(*index)++] = NULL;
  } else {
    char *temp = strdup(data);
    if (temp == NULL) {
      fprintf(stderr,
              "kickstart[%d]: %s[%d]: "
              "strdup: %s\n",
              getpid(),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/"
              "src/tools/pegasus-kickstart/invoke.c",
              49, strerror(errno));
      return -1;
    }
    (*arg)[(*index)++] = temp;
  }
  return 0;
}


x86 assembly (clang, -O0):
<append_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
jb     124b <append_arg+0xeb>
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
shl    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
shl    $0x3,%rsi
call   1060 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    121b <append_arg+0xbb>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x34(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%r9
lea    0xe03(%rip),%rsi
lea    0xe20(%rip),%rcx
mov    $0x25,%r8d
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <append_arg+0x1ac>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
sub    (%rcx),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    127b <append_arg+0x11b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rdx
mov    (%rdx),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
movq   $0x0,(%rax,%rcx,8)
jmp    1305 <append_arg+0x1a5>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12e5 <append_arg+0x185>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%r9
lea    0xe02(%rip),%rsi
lea    0xd56(%rip),%rcx
mov    $0x31,%r8d
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <append_arg+0x1ac>
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rsi
mov    (%rsi),%rcx
mov    %rcx,%rdi
add    $0x1,%rdi
mov    %rdi,(%rsi)
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_arg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rcx),%rsi
cmp    %rsi,(%rdx)
jb     11ad <append_arg+0x4d>
mov    %rcx,%rbx
lea    (%rsi,%rsi,1),%rax
mov    %rax,(%rcx)
mov    (%r14),%rdi
shl    $0x4,%rsi
call   1060 <realloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11f4 <append_arg+0x94>
mov    (%r12),%rcx
lea    (%rax,%rcx,8),%rdi
mov    (%rbx),%edx
sub    %ecx,%edx
shl    $0x3,%edx
xor    %esi,%esi
call   1040 <memset@plt>
test   %r15,%r15
je     11d9 <append_arg+0x79>
mov    %r15,%rdi
call   1070 <strdup@plt>
test   %rax,%rax
je     122e <append_arg+0xce>
mov    (%r14),%rcx
mov    (%r12),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%r12)
mov    %rax,(%rcx,%rdx,8)
xor    %eax,%eax
jmp    1273 <append_arg+0x113>
mov    (%r14),%rax
mov    (%r12),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%r12)
movq   $0x0,(%rax,%rcx,8)
xor    %eax,%eax
jmp    1273 <append_arg+0x113>
mov    0x2de5(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde5(%rip),%rsi
lea    0xe02(%rip),%rcx
mov    %ebx,%edi
mov    %ebp,%edx
mov    $0x25,%r8d
jmp    1266 <append_arg+0x106>
mov    0x2dab(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe74(%rip),%rsi
lea    0xdc8(%rip),%rcx
mov    %ebx,%edi
mov    %ebp,%edx
mov    $0x31,%r8d
mov    %rax,%r9
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"kickstart[%d]: %s[%d]: realloc: %s\0A\00"
@.str.1 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/src/tools/pegasus-kickstart/invoke.c\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"kickstart[%d]: %s[%d]: strdup: %s\0A\00"
define i32 @append_arg(i8* %0, i8*** %1, i64* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8***
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i8*
store i8* %0, i8** %6
store i8*** %1, i8**** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
%11 = load i64*, i64** %8
%12 = load i64, i64* %11
%13 = load i64*, i64** %9
%14 = load i64, i64* %13
%15 = icmp uge i64 %12, %14
br i1 %15, label %16, label %50
16: ; preds = %4
%17 = load i64*, i64** %9
%18 = load i64, i64* %17
%19 = shl i64 %18, 1
store i64 %19, i64* %17
%20 = load i8***, i8**** %7
%21 = load i8**, i8*** %20
%22 = load i64*, i64** %9
%23 = load i64, i64* %22
%24 = mul i64 %23, 8
%25 = call i8** @realloc(i8** %21, i64 %24)
%26 = load i8***, i8**** %7
store i8** %25, i8*** %26
%27 = load i8***, i8**** %7
%28 = load i8**, i8*** %27
%29 = icmp eq i8** %28, null
br i1 %29, label %30, label %36
30: ; preds = %16
%31 = load i32, i32* @stderr
%32 = call i32 (...) @getpid()
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %32, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* %34)
store i32 -1, i32* %5
br label %80
36: ; preds = %16
%37 = load i8***, i8**** %7
%38 = load i8**, i8*** %37
%39 = load i64*, i64** %8
%40 = load i64, i64* %39
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i64*, i64** %9
%43 = load i64, i64* %42
%44 = load i64*, i64** %8
%45 = load i64, i64* %44
%46 = sub i64 %43, %45
%47 = mul i64 8, %46
%48 = trunc i64 %47 to i32
%49 = call i32 @memset(i8** %41, i32 0, i32 %48)
br label %50
50: ; preds = %36, %4
%51 = load i8*, i8** %6
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %60
53: ; preds = %50
%54 = load i8***, i8**** %7
%55 = load i8**, i8*** %54
%56 = load i64*, i64** %8
%57 = load i64, i64* %56
%58 = add i64 %57, 1
store i64 %58, i64* %56
%59 = getelementptr inbounds i8*, i8** %55, i64 %57
store i8* null, i8** %59
br label %79
60: ; preds = %50
%61 = load i8*, i8** %6
%62 = call i8* @strdup(i8* %61)
store i8* %62, i8** %10
%63 = load i8*, i8** %10
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %71
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = call i32 (...) @getpid()
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %67, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 49, i8* %69)
store i32 -1, i32* %5
br label %80
71: ; preds = %60
%72 = load i8*, i8** %10
%73 = load i8***, i8**** %7
%74 = load i8**, i8*** %73
%75 = load i64*, i64** %8
%76 = load i64, i64* %75
%77 = add i64 %76, 1
store i64 %77, i64* %75
%78 = getelementptr inbounds i8*, i8** %74, i64 %76
store i8* %72, i8** %78
br label %79
79: ; preds = %71, %53
store i32 0, i32* %5
br label %80
80: ; preds = %79, %65, %30
%81 = load i32, i32* %5
ret i32 %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"kickstart[%d]: %s[%d]: realloc: %s\0A\00"
@.str.1 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/src/tools/pegasus-kickstart/invoke.c\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"kickstart[%d]: %s[%d]: strdup: %s\0A\00"
define i32 @append_arg(i8* %0, i8*** nocapture %1, i64* nocapture %2, i64* nocapture %3) {
%5 = load i64, i64* %2
%6 = load i64, i64* %3
%7 = icmp ult i64 %5, %6
br i1 %7, label %28, label %8
8: ; preds = %4
%9 = shl i64 %6, 1
store i64 %9, i64* %3
%10 = load i8**, i8*** %1
%11 = shl i64 %6, 4
%12 = tail call i8** @realloc(i8** %10, i64 %11)
store i8** %12, i8*** %1
%13 = icmp eq i8** %12, null
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = tail call i32 (...) @getpid()
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %16, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 37, i8* %18)
br label %49
20: ; preds = %8
%21 = load i64, i64* %2
%22 = getelementptr inbounds i8*, i8** %12, i64 %21
%23 = load i64, i64* %3
%24 = sub i64 %23, %21
%25 = trunc i64 %24 to i32
%26 = shl i32 %25, 3
%27 = tail call i32 @memset(i8** %22, i32 0, i32 %26)
br label %28
28: ; preds = %20, %4
%29 = icmp eq i8* %0, null
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = load i8**, i8*** %1
%32 = load i64, i64* %2
%33 = add i64 %32, 1
store i64 %33, i64* %2
%34 = getelementptr inbounds i8*, i8** %31, i64 %32
store i8* null, i8** %34
br label %49
35: ; preds = %28
%36 = tail call i8* @strdup(i8* %0)
%37 = icmp eq i8* %36, null
br i1 %37, label %43, label %38
38: ; preds = %35
%39 = load i8**, i8*** %1
%40 = load i64, i64* %2
%41 = add i64 %40, 1
store i64 %41, i64* %2
%42 = getelementptr inbounds i8*, i8** %39, i64 %40
store i8* %36, i8** %42
br label %49
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = tail call i32 (...) @getpid()
%46 = load i32, i32* @errno
%47 = tail call i8* @strerror(i32 %46)
%48 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %45, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 49, i8* %47)
br label %49
49: ; preds = %30, %38, %43, %14
%50 = phi i32 [ -1, %14 ], [ -1, %43 ], [ 0, %38 ], [ 0, %30 ]
ret i32 %50
}