#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 */
char **xrealloc(char **, size_t);
char *xstrdup(char const *);
char **argv_insert(char **argv, size_t *count, const char *str) {
  argv = xrealloc(argv, (*count + 2) * sizeof(char *));
  argv[*count] = str ? xstrdup(str) : xstrdup("");
  argv[*count + 1] = NULL;
  *count += 1;
  return argv;
}


x86 assembly (clang, -O0):
<argv_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
add    $0x2,%rsi
shl    $0x3,%rsi
call   1030 <xrealloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116d <argv_insert+0x4d>
mov    -0x18(%rbp),%rdi
call   1040 <xstrdup@plt>
mov    %rax,-0x20(%rbp)
jmp    117d <argv_insert+0x5d>
lea    0xe8c(%rip),%rdi
call   1040 <xstrdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
movq   $0x0,0x8(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argv_insert>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    (%rsi),%rax
lea    0x10(,%rax,8),%rsi
call   1030 <xrealloc@plt>
mov    %rax,%rbx
test   %r15,%r15
je     1148 <argv_insert+0x28>
mov    %r15,%rdi
jmp    114f <argv_insert+0x2f>
lea    0xeb1(%rip),%rdi
call   1040 <xstrdup@plt>
mov    (%r14),%rcx
mov    %rax,(%rbx,%rcx,8)
movq   $0x0,0x8(%rbx,%rcx,8)
add    $0x1,%rcx
mov    %rcx,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8** @argv_insert(i8** %0, i64* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i64*
%6 = alloca i8*
store i8** %0, i8*** %4
store i64* %1, i64** %5
store i8* %2, i8** %6
%7 = load i8**, i8*** %4
%8 = load i64*, i64** %5
%9 = load i64, i64* %8
%10 = add i64 %9, 2
%11 = mul i64 %10, 8
%12 = call i8** @xrealloc(i8** %7, i64 %11)
store i8** %12, i8*** %4
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = call i8* @xstrdup(i8* %16)
br label %20
18: ; preds = %3
%19 = call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = phi i8* [ %17, %15 ], [ %19, %18 ]
%22 = load i8**, i8*** %4
%23 = load i64*, i64** %5
%24 = load i64, i64* %23
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
store i8* %21, i8** %25
%26 = load i8**, i8*** %4
%27 = load i64*, i64** %5
%28 = load i64, i64* %27
%29 = add i64 %28, 1
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
store i8* null, i8** %30
%31 = load i64*, i64** %5
%32 = load i64, i64* %31
%33 = add i64 %32, 1
store i64 %33, i64* %31
%34 = load i8**, i8*** %4
ret i8** %34
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8** @argv_insert(i8** %0, i64* nocapture %1, i8* %2) {
%4 = load i64, i64* %1
%5 = shl i64 %4, 3
%6 = add i64 %5, 16
%7 = tail call i8** @xrealloc(i8** %0, i64 %6)
%8 = icmp eq i8* %2, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i8* @xstrdup(i8* %2)
br label %13
11: ; preds = %3
%12 = tail call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = phi i8* [ %10, %9 ], [ %12, %11 ]
%15 = load i64, i64* %1
%16 = getelementptr inbounds i8*, i8** %7, i64 %15
store i8* %14, i8** %16
%17 = add i64 %15, 1
%18 = getelementptr inbounds i8*, i8** %7, i64 %17
store i8* null, i8** %18
store i64 %17, i64* %1
ret i8** %7
}