#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*/ nomem();
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
void append(char **s, const char *new) {
  if ((*s = realloc(*s, strlen(*s) + strlen(new) + 1)) == NULL)
    nomem();
  strcat(*s, new);
}


x86 assembly (clang, -O0):
<append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1050 <realloc@plt>
mov    -0x8(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11a0 <append+0x60>
mov    $0x0,%al
call   1040 <nomem@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
call   1050 <realloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
jne    1186 <append+0x46>
xor    %eax,%eax
call   1040 <nomem@plt>
mov    (%r15),%rax
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <strcat@plt>

LLVM IR (-O0):
define void @append(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%5 = load i8**, i8*** %3
%6 = load i8*, i8** %5
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = add nsw i64 %12, 1
%14 = call i8* @realloc(i8* %6, i64 %13)
%15 = load i8**, i8*** %3
store i8* %14, i8** %15
%16 = icmp eq i8* %14, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (...) @nomem()
br label %19
19: ; preds = %17, %2
%20 = load i8**, i8*** %3
%21 = load i8*, i8** %20
%22 = load i8*, i8** %4
%23 = call i32 @strcat(i8* %21, i8* %22)
ret void
}

LLVM IR (-O2):
define void @append(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %4, 1
%7 = add i64 %6, %5
%8 = tail call i8* @realloc(i8* %3, i64 %7)
store i8* %8, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 (...) @nomem()
%12 = load i8*, i8** %0
br label %13
13: ; preds = %10, %2
%14 = phi i8* [ %12, %10 ], [ %8, %2 ]
%15 = tail call i32 @strcat(i8* %14, i8* %1)
ret void
}