#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 argv_length(char **);
scalar_t__ xrealloc(char *, int);
char *xstrdup(char *);
char **argv_append(char **argv, char *s) {
  int argc = argv_length(argv) + 1;
  argv = (char **)xrealloc((char *)argv, sizeof(char *) * (argc + 1));
  argv[argc - 1] = xstrdup(s);
  argv[argc] = NULL;
  return argv;
}


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

x86 assembly (clang, -O2):
<argv_append>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <argv_length@plt>
mov    %eax,%r15d
lea    0x10(,%r15,8),%esi
mov    %rbx,%rdi
call   1030 <xrealloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <xstrdup@plt>
movslq %r15d,%rcx
mov    %rax,(%rbx,%rcx,8)
movq   $0x0,0x8(%rbx,%rcx,8)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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