#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*/ strcat(char *, char const *);
size_t strlen(char const *);
int /*<<< orphan*/ sttstr_copy(char *, char const *, size_t);
void sttstr_append_string(char *this, const char *new_str, size_t buffer_size) {
  size_t new_size;
  if (NULL == this)
    return;
  if (!(*this)) {
    sttstr_copy(this, new_str, buffer_size);
    return;
  }
  if (!new_str || !(*new_str))
    return;
  new_size = strlen(this) + strlen(new_str);
  if (buffer_size < new_size)
    return;
  strcat(this, new_str);
}


x86 assembly (clang, -O0):
<sttstr_append_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    1155 <sttstr_append_string+0x25>
jmp    11d9 <sttstr_append_string+0xa9>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1178 <sttstr_append_string+0x48>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <sttstr_copy@plt>
jmp    11d9 <sttstr_append_string+0xa9>
cmpq   $0x0,-0x10(%rbp)
je     1190 <sttstr_append_string+0x60>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1195 <sttstr_append_string+0x65>
jmp    11d9 <sttstr_append_string+0xa9>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11cc <sttstr_append_string+0x9c>
jmp    11d9 <sttstr_append_string+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sttstr_append_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1171 <sttstr_append_string+0x41>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     117d <sttstr_append_string+0x4d>
test   %r14,%r14
je     1171 <sttstr_append_string+0x41>
cmpb   $0x0,(%r14)
je     1171 <sttstr_append_string+0x41>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %r12,%rax
cmp    %r15,%rax
jbe    1196 <sttstr_append_string+0x66>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <sttstr_copy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <strcat@plt>

LLVM IR (-O0):
define void @sttstr_append_string(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %4
%9 = icmp eq i8* null, %8
br i1 %9, label %10, label %11
10: ; preds = %3
br label %42
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i32 @sttstr_copy(i8* %16, i8* %17, i64 %18)
br label %42
20: ; preds = %11
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23, %20
br label %42
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = call i64 @strlen(i8* %29)
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
%33 = add i64 %30, %32
store i64 %33, i64* %7
%34 = load i64, i64* %6
%35 = load i64, i64* %7
%36 = icmp ult i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %28
br label %42
38: ; preds = %28
%39 = load i8*, i8** %4
%40 = load i8*, i8** %5
%41 = call i32 @strcat(i8* %39, i8* %40)
br label %42
42: ; preds = %38, %37, %27, %15, %10
ret void
}

LLVM IR (-O2):
define void @sttstr_append_string(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @sttstr_copy(i8* %0, i8* %1, i64 %2)
br label %22
10: ; preds = %5
%11 = icmp eq i8* %1, null
br i1 %11, label %22, label %12
12: ; preds = %10
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = tail call i64 @strlen(i8* %0)
%17 = tail call i64 @strlen(i8* %1)
%18 = add i64 %17, %16
%19 = icmp ugt i64 %18, %2
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = tail call i32 @strcat(i8* %0, i8* %1)
br label %22
22: ; preds = %15, %10, %12, %3, %20, %8
ret void
}