#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 size_t uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *const, size_t);
int /*<<< orphan*/ size_buffer(char **, size_t *, size_t);
size_t strlen(char const *const);
scalar_t__ uint32Pack(size_t *, char **, size_t *, size_t *);
size_t astringPack(const char *const *data, char **buffer, size_t *size,
                   size_t *pos) {
  size_t byte_count = 0;
  uint32_t str_len = strlen(*data);
  byte_count += uint32Pack(&str_len, buffer, size, pos);
  size_buffer(buffer, size, *pos + str_len);
  memcpy(*buffer + *pos, *data, str_len);
  *pos += str_len;
  return sizeof(uint32_t) + str_len;
}


x86 assembly (clang, -O0):
<astringPack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdi
call   1040 <uint32Pack@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
add    -0x30(%rbp),%rdx
call   1060 <size_buffer@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
add    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astringPack>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    (%rdi),%rdi
call   1030 <strlen@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <uint32Pack@plt>
mov    (%rsp),%rdx
add    (%r15),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <size_buffer@plt>
mov    (%rbx),%rdi
add    (%r15),%rdi
mov    (%r12),%rsi
mov    (%rsp),%rdx
call   1050 <memcpy@plt>
mov    (%rsp),%rax
add    %rax,(%r15)
add    $0x8,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @astringPack(i8** %0, i8** %1, i64* %2, i64* %3) {
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i64
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
store i64 0, i64* %9
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %10
%14 = load i8**, i8*** %6
%15 = load i64*, i64** %7
%16 = load i64*, i64** %8
%17 = call i64 @uint32Pack(i64* %10, i8** %14, i64* %15, i64* %16)
%18 = load i64, i64* %9
%19 = add i64 %18, %17
store i64 %19, i64* %9
%20 = load i8**, i8*** %6
%21 = load i64*, i64** %7
%22 = load i64*, i64** %8
%23 = load i64, i64* %22
%24 = load i64, i64* %10
%25 = add i64 %23, %24
%26 = call i32 @size_buffer(i8** %20, i64* %21, i64 %25)
%27 = load i8**, i8*** %6
%28 = load i8*, i8** %27
%29 = load i64*, i64** %8
%30 = load i64, i64* %29
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = load i64, i64* %10
%35 = call i32 @memcpy(i8* %31, i8* %33, i64 %34)
%36 = load i64, i64* %10
%37 = load i64*, i64** %8
%38 = load i64, i64* %37
%39 = add i64 %38, %36
store i64 %39, i64* %37
%40 = load i64, i64* %10
%41 = add i64 8, %40
ret i64 %41
}

LLVM IR (-O2):
define i64 @astringPack(i8** nocapture %0, i8** %1, i64* %2, i64* %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = load i8*, i8** %0
%8 = tail call i64 @strlen(i8* dereferenceable(1) %7)
store i64 %8, i64* %5
%9 = call i64 @uint32Pack(i64* %5, i8** %1, i64* %2, i64* %3)
%10 = load i64, i64* %3
%11 = load i64, i64* %5
%12 = add i64 %11, %10
%13 = call i32 @size_buffer(i8** %1, i64* %2, i64 %12)
%14 = load i8*, i8** %1
%15 = load i64, i64* %3
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8*, i8** %0
%18 = load i64, i64* %5
%19 = call i32 @memcpy(i8* %16, i8* %17, i64 %18)
%20 = load i64, i64* %5
%21 = load i64, i64* %3
%22 = add i64 %21, %20
store i64 %22, i64* %3
%23 = add i64 %20, 8
ret i64 %23
}