#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*/ die(char *);
scalar_t__ realloc(char *, unsigned int);
int /*<<< orphan*/ strcpy(char *, char const *);
unsigned int strlen(char const *);
void local_strcat(char **dest, const char *source) {
  unsigned ndest, nsource;
  ;
  ;
  ndest = *dest ? strlen(*dest) : 0;
  nsource = strlen(source);
  if (nsource == 0)
    return;
  *dest = (char *)realloc(*dest, ndest + nsource + 1);
  if (0 == *dest)
    die("out of memory growing string");
  strcpy((*dest) + ndest, source);
}


x86 assembly (clang, -O0):
<local_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1172 <local_strcat+0x32>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
jmp    117c <local_strcat+0x3c>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    117c <local_strcat+0x3c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    119d <local_strcat+0x5d>
jmp    11ed <local_strcat+0xad>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
add    -0x18(%rbp),%esi
add    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    11d7 <local_strcat+0x97>
lea    0xe2e(%rip),%rdi
call   1060 <die@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_strcat>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     115d <local_strcat+0x1d>
call   1040 <strlen@plt>
mov    %eax,%r15d
jmp    1160 <local_strcat+0x20>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11a5 <local_strcat+0x65>
mov    (%rbx),%rdi
lea    (%r15,%rax,1),%esi
add    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    1192 <local_strcat+0x52>
lea    0xe76(%rip),%rdi
call   1060 <die@plt>
mov    (%rbx),%rax
mov    %r15d,%edi
add    %rax,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"out of memory growing string\00"
define void @local_strcat(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %3
%12 = load i8*, i8** %11
%13 = call i32 @strlen(i8* %12)
br label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %10
%16 = phi i32 [ %13, %10 ], [ 0, %14 ]
store i32 %16, i32* %5
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
br label %45
22: ; preds = %15
%23 = load i8**, i8*** %3
%24 = load i8*, i8** %23
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = add i32 %25, %26
%28 = add i32 %27, 1
%29 = call i64 @realloc(i8* %24, i32 %28)
%30 = inttoptr i64 %29 to i8*
%31 = load i8**, i8*** %3
store i8* %30, i8** %31
%32 = load i8**, i8*** %3
%33 = load i8*, i8** %32
%34 = icmp eq i8* null, %33
br i1 %34, label %35, label %37
35: ; preds = %22
%36 = call i32 @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %22
%38 = load i8**, i8*** %3
%39 = load i8*, i8** %38
%40 = load i32, i32* %5
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8*, i8** %4
%44 = call i32 @strcpy(i8* %42, i8* %43)
br label %45
45: ; preds = %37, %21
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"out of memory growing string\00"
define void @local_strcat(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
br label %7
7: ; preds = %2, %5
%8 = phi i32 [ %6, %5 ], [ 0, %2 ]
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %7
%12 = load i8*, i8** %0
%13 = add i32 %8, 1
%14 = add i32 %13, %9
%15 = tail call i64 @realloc(i8* %12, i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %0
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = tail call i32 @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %0
br label %21
21: ; preds = %18, %11
%22 = phi i8* [ %20, %18 ], [ %16, %11 ]
%23 = zext i32 %8 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = tail call i32 @strcpy(i8* %24, i8* %1)
br label %26
26: ; preds = %7, %21
ret void
}