#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 */
char *format_str(char *, char const *const, char const *);
int /*<<< orphan*/ free(char *);
void append_to_string(char **str, const char suffix[]) {
  const char *const non_null_str = (*str == NULL) ? "" : *str;
  char *const appended_str = format_str("%s%s", non_null_str, suffix);
  if (appended_str != NULL) {
    free(*str);
    *str = appended_str;
  }
}


x86 assembly (clang, -O0):
<append_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    114e <append_to_string+0x2e>
lea    0xebf(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1159 <append_to_string+0x39>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe90(%rip),%rdi
call   1040 <format_str@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119b <append_to_string+0x7b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_to_string>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rdx
mov    %rdi,%r14
mov    (%rdi),%rax
test   %rax,%rax
lea    0xecd(%rip),%rsi
cmovne %rax,%rsi
lea    0xebe(%rip),%rdi
call   1040 <format_str@plt>
test   %rax,%rax
je     115a <append_to_string+0x3a>
mov    %rax,%rbx
mov    (%r14),%rdi
call   1030 <free@plt>
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%s\00"
define void @append_to_string(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %14
11: ; preds = %2
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
br label %14
14: ; preds = %11, %10
%15 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %10 ], [ %13, %11 ]
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i8*, i8** %4
%18 = call i8* @format_str(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i8**, i8*** %3
%23 = load i8*, i8** %22
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %6
%26 = load i8**, i8*** %3
store i8* %25, i8** %26
br label %27
27: ; preds = %21, %14
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%s%s\00"
define void @append_to_string(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %3
%6 = tail call i8* @format_str(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %0
%10 = tail call i32 @free(i8* %9)
store i8* %6, i8** %0
br label %11
11: ; preds = %8, %2
ret void
}