#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);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *bsCat(char *bs1, char *bs2) {
  size_t len1 = bsGetLen(bs1);
  size_t len2 = bsGetLen(bs2);
  size_t len = len1 + len2;
  char *bs = malloc(sizeof(char) * (4 + len + 1));
  assert(bs);
  bs += 4;
  strcpy(bs, bs1);
  strcpy(bs + len1, bs2);
  bsSetLen(bs, len);
  return bs;
}


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

x86 assembly (clang, -O2):
<bsCat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <bsGetLen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1040 <bsGetLen@plt>
lea    (%rax,%r13,1),%r12
lea    0x5(%r12),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
lea    0x4(%rbx),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    (%rbx,%r13,1),%rdi
add    $0x4,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1060 <bsSetLen@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @bsCat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @bsGetLen(i8* %9)
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i64 @bsGetLen(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 i64, i64* %7
%17 = add i64 4, %16
%18 = add i64 %17, 1
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = call i32 @assert(i8* %22)
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i64 4
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = load i8*, i8** %3
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %8
%30 = load i64, i64* %5
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8*, i8** %4
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i8*, i8** %8
%35 = load i64, i64* %7
%36 = call i32 @bsSetLen(i8* %34, i64 %35)
%37 = load i8*, i8** %8
ret i8* %37
}

LLVM IR (-O2):
define i8* @bsCat(i8* %0, i8* %1) {
%3 = tail call i64 @bsGetLen(i8* %0)
%4 = tail call i64 @bsGetLen(i8* %1)
%5 = add i64 %4, %3
%6 = trunc i64 %5 to i32
%7 = add i32 %6, 5
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @assert(i8* %8)
%10 = getelementptr inbounds i8, i8* %8, i64 4
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
%12 = getelementptr inbounds i8, i8* %10, i64 %3
%13 = tail call i32 @strcpy(i8* %12, i8* %1)
%14 = tail call i32 @bsSetLen(i8* %10, i64 %5)
ret i8* %10
}