#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 */
typedef int /*<<< orphan*/ error_t;

/* Variables and functions */
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *realloc(char *, size_t);
error_t __argz_append(char **argz, size_t *argz_len, const char *buf,
                      size_t buf_len) {
  size_t new_argz_len = *argz_len + buf_len;
  char *new_argz = realloc(*argz, new_argz_len);
  if (new_argz) {
    memcpy(new_argz + *argz_len, buf, buf_len);
    *argz = new_argz;
    *argz_len = new_argz_len;
    return 0;
  } else
    return ENOMEM;
}


x86 assembly (clang, -O0):
<__argz_append>:
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    -0x18(%rbp),%rax
mov    (%rax),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11a0 <__argz_append+0x80>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
add    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11ac <__argz_append+0x8c>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__argz_append>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rsi),%rbx
add    %rcx,%rbx
mov    (%rdi),%rdi
mov    %rbx,%rsi
call   1040 <realloc@plt>
test   %rax,%rax
je     116b <__argz_append+0x4b>
mov    %rax,%rbp
mov    (%r14),%rdi
add    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1030 <memcpy@plt>
mov    %rbp,(%r15)
mov    %rbx,(%r14)
xor    %eax,%eax
jmp    1174 <__argz_append+0x54>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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