#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*/ assert(char *);
size_t bsGetLen(char *);
int /*<<< orphan*/ bsSetLen(char *, size_t);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void bsLCat(char **orig, char *s) {
  size_t lenO = bsGetLen(*orig);
  size_t lenS = strlen(s);
  size_t len = lenO + lenS;
  *orig = (char *)realloc(*orig - 4, sizeof(char) * (4 + len + 1));
  assert(*orig);
  *orig += 4;
  strcpy(*orig + lenO, s);
  bsSetLen(*orig, len);
}


x86 assembly (clang, -O0):
<bsLCat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <bsGetLen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    $0xfffffffffffffffc,%rdi
mov    -0x28(%rbp),%rax
add    $0x4,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x4,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <bsSetLen@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bsLCat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1050 <bsGetLen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r15,1),%r12
mov    (%rbx),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0x5(%r12),%esi
call   1080 <realloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
call   1060 <assert@plt>
mov    (%rbx),%rax
lea    0x4(%rax),%rcx
mov    %rcx,(%rbx)
lea    (%rax,%r15,1),%rdi
add    $0x4,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <bsSetLen@plt>

LLVM IR (-O0):
define void @bsLCat(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8** %0, i8*** %3
store i8* %1, i8** %4
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = call i64 @bsGetLen(i8* %9)
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = add i64 %13, %14
store i64 %15, i64* %7
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 -4
%19 = load i64, i64* %7
%20 = add i64 4, %19
%21 = add i64 %20, 1
%22 = mul i64 1, %21
%23 = trunc i64 %22 to i32
%24 = call i64 @realloc(i8* %18, i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = load i8**, i8*** %3
store i8* %25, i8** %26
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = call i32 @assert(i8* %28)
%30 = load i8**, i8*** %3
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 4
store i8* %32, i8** %30
%33 = load i8**, i8*** %3
%34 = load i8*, i8** %33
%35 = load i64, i64* %5
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8*, i8** %4
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = load i8**, i8*** %3
%40 = load i8*, i8** %39
%41 = load i64, i64* %7
%42 = call i32 @bsSetLen(i8* %40, i64 %41)
ret void
}

LLVM IR (-O2):
define void @bsLCat(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i64 @bsGetLen(i8* %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %5, %4
%7 = load i8*, i8** %0
%8 = getelementptr inbounds i8, i8* %7, i64 -4
%9 = trunc i64 %6 to i32
%10 = add i32 %9, 5
%11 = tail call i64 @realloc(i8* %8, i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %0
%13 = tail call i32 @assert(i8* %12)
%14 = load i8*, i8** %0
%15 = getelementptr inbounds i8, i8* %14, i64 4
store i8* %15, i8** %0
%16 = getelementptr inbounds i8, i8* %15, i64 %4
%17 = tail call i32 @strcpy(i8* %16, i8* %1)
%18 = load i8*, i8** %0
%19 = tail call i32 @bsSetLen(i8* %18, i64 %6)
ret void
}