#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 */
scalar_t__ realloc(char **, int);
int popen_noshell_add_ptr_to_argv(char ***argv, int *count, char *start) {
  *count += 1;
  *argv = (char **)realloc(*argv, *count * sizeof(char **));
  if (*argv == NULL) {
    return -1;
  }
  *(*argv + *count - 1) = start;
  return 0;
}


x86 assembly (clang, -O0):
<popen_noshell_add_ptr_to_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    116c <popen_noshell_add_ptr_to_argv+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <popen_noshell_add_ptr_to_argv+0x7a>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,-0x8(%rax,%rcx,8)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<popen_noshell_add_ptr_to_argv>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rsi)
mov    (%rdi),%rdi
lea    0x8(,%rax,8),%esi
call   1030 <realloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1148 <popen_noshell_add_ptr_to_argv+0x38>
movslq (%rbx),%rcx
mov    %r14,-0x8(%rax,%rcx,8)
xor    %eax,%eax
jmp    114d <popen_noshell_add_ptr_to_argv+0x3d>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @popen_noshell_add_ptr_to_argv(i8*** %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8***
%6 = alloca i32*
%7 = alloca i8*
store i8*** %0, i8**** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%8 = load i32*, i32** %6
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
store i32 %10, i32* %8
%11 = load i8***, i8**** %5
%12 = load i8**, i8*** %11
%13 = load i32*, i32** %6
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call i64 @realloc(i8** %12, i32 %17)
%19 = inttoptr i64 %18 to i8**
%20 = load i8***, i8**** %5
store i8** %19, i8*** %20
%21 = load i8***, i8**** %5
%22 = load i8**, i8*** %21
%23 = icmp eq i8** %22, null
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 -1, i32* %4
br label %34
25: ; preds = %3
%26 = load i8*, i8** %7
%27 = load i8***, i8**** %5
%28 = load i8**, i8*** %27
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
%33 = getelementptr inbounds i8*, i8** %32, i64 -1
store i8* %26, i8** %33
store i32 0, i32* %4
br label %34
34: ; preds = %25, %24
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @popen_noshell_add_ptr_to_argv(i8*** nocapture %0, i32* nocapture %1, i8* %2) {
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 1
store i32 %5, i32* %1
%6 = load i8**, i8*** %0
%7 = shl i32 %5, 3
%8 = tail call i64 @realloc(i8** %6, i32 %7)
%9 = inttoptr i64 %8 to i8**
store i8** %9, i8*** %0
%10 = icmp eq i64 %8, 0
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %9, i64 %13
%15 = getelementptr inbounds i8*, i8** %14, i64 -1
store i8* %2, i8** %15
br label %16
16: ; preds = %3, %11
%17 = phi i32 [ 0, %11 ], [ -1, %3 ]
ret i32 %17
}