#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 /*<<< orphan*/ cbuf_capacity(char **, size_t *, size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
void cbuf_append_str(char **buf, size_t *lenptr, size_t *sizeptr,
                     const char *str, size_t len) {
  cbuf_capacity(buf, sizeptr, *lenptr + len);
  memcpy(*buf + *lenptr, str, len);
  *lenptr += len;
  (*buf)[*lenptr] = '\0';
}


x86 assembly (clang, -O0):
<cbuf_append_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
add    -0x28(%rbp),%rdx
call   1030 <cbuf_capacity@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
add    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbuf_append_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    (%rsi),%rax
add    %r8,%rax
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <cbuf_capacity@plt>
mov    (%r12),%rdi
add    (%r15),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
add    (%r15),%rbx
mov    %rbx,(%r15)
mov    (%r12),%rax
movb   $0x0,(%rax,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @cbuf_append_str(i8** %0, i64* nocapture %1, i64* %2, i8* %3, i64 %4) {
%6 = load i64, i64* %1
%7 = add i64 %6, %4
%8 = tail call i32 @cbuf_capacity(i8** %0, i64* %2, i64 %7)
%9 = load i8*, i8** %0
%10 = load i64, i64* %1
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = tail call i32 @memcpy(i8* %11, i8* %3, i64 %4)
%13 = load i64, i64* %1
%14 = add i64 %13, %4
store i64 %14, i64* %1
%15 = load i8*, i8** %0
%16 = getelementptr inbounds i8, i8* %15, i64 %14
store i8 0, i8* %16
ret void
}