#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*/ sprintf(char *, char *, char);
size_t strlen(char *);
void sttstr_append_char(char *this, char new_char, size_t buffer_size) {
  size_t cur_size;
  size_t new_size;
  if (NULL == this)
    return;
  if (!(*this)) {
    sprintf(this, "%c", new_char);
    return;
  }
  cur_size = strlen(this);
  new_size = cur_size + 1;
  if (buffer_size < new_size)
    return;
  this[cur_size] = new_char;
  this[new_size] = '\0';
}


x86 assembly (clang, -O0):
<sttstr_append_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    1147 <sttstr_append_char+0x27>
jmp    11b3 <sttstr_append_char+0x93>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    116d <sttstr_append_char+0x4d>
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
movsbl -0x9(%rbp),%edx
call   1040 <sprintf@plt>
jmp    11b3 <sttstr_append_char+0x93>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1199 <sttstr_append_char+0x79>
jmp    11b3 <sttstr_append_char+0x93>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sttstr_append_char>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     114c <sttstr_append_char+0x3c>
mov    %esi,%r14d
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     113d <sttstr_append_char+0x2d>
mov    %rdx,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rcx
cmp    %rbp,%rcx
ja     114c <sttstr_append_char+0x3c>
add    %rbx,%rax
jmp    1145 <sttstr_append_char+0x35>
mov    $0x1,%ecx
mov    %rbx,%rax
mov    %r14b,(%rax)
movb   $0x0,(%rbx,%rcx,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @sttstr_append_char(i8* %0, i8 signext %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i8 %1, i8* %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = icmp eq i8* null, %9
br i1 %10, label %11, label %12
11: ; preds = %3
br label %37
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8, i8* %5
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %18)
br label %37
20: ; preds = %12
%21 = load i8*, i8** %4
%22 = call i64 @strlen(i8* %21)
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = add i64 %23, 1
store i64 %24, i64* %8
%25 = load i64, i64* %6
%26 = load i64, i64* %8
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %20
br label %37
29: ; preds = %20
%30 = load i8, i8* %5
%31 = load i8*, i8** %4
%32 = load i64, i64* %7
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 %30, i8* %33
%34 = load i8*, i8** %4
%35 = load i64, i64* %8
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %29, %28, %16, %11
ret void
}

LLVM IR (-O2):
define void @sttstr_append_char(i8* %0, i8 signext %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i64 @strlen(i8* %0)
%10 = add i64 %9, 1
%11 = icmp ugt i64 %10, %2
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 %9
br label %14
14: ; preds = %5, %12
%15 = phi i8* [ %13, %12 ], [ %0, %5 ]
%16 = phi i64 [ %10, %12 ], [ 1, %5 ]
store i8 %1, i8* %15
%17 = getelementptr i8, i8* %0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %14, %8, %3
ret void
}