#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 **, int);
void append_to_argv(int *argc, char ***argv, char *val) {
  char **_argv = xrealloc(*argv, (*argc + 2) * sizeof(*_argv));
  _argv[*argc] = val;
  _argv[*argc + 1] = (char *)'\0';
  (*argc)++;
  *argv = _argv;
}


x86 assembly (clang, -O0):
<append_to_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <xrealloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_to_argv>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    (%rsi),%rdi
mov    (%rbx),%eax
lea    0x10(,%rax,8),%esi
call   1030 <xrealloc@plt>
movslq (%rbx),%rcx
mov    %r14,(%rax,%rcx,8)
movq   $0x0,0x8(%rax,%rcx,8)
add    $0x1,%rcx
mov    %ecx,(%rbx)
mov    %rax,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @append_to_argv(i32* nocapture %0, i8*** nocapture %1, i8* %2) {
%4 = load i8**, i8*** %1
%5 = load i32, i32* %0
%6 = shl i32 %5, 3
%7 = add i32 %6, 16
%8 = tail call i8** @xrealloc(i8** %4, i32 %7)
%9 = load i32, i32* %0
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
store i8* %2, i8** %11
%12 = add nsw i32 %9, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %8, i64 %13
store i8* null, i8** %14
store i32 %12, i32* %0
store i8** %8, i8*** %1
ret void
}