#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 *myrealloc(char *, int);
char *realloc_strcpy(char **, char *);
char *strcat(char *, char *);
int strlen(char *);
char *realloc_strcat(char **dest, char *src) {
  if (dest == NULL || *dest == NULL)
    return realloc_strcpy(dest, src);
  else {
    *dest = myrealloc(*dest, (strlen(*dest) + strlen(src) + 1) * sizeof(char));
    return strcat(*dest, src);
  }
}


x86 assembly (clang, -O0):
<realloc_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1169 <realloc_strcat+0x29>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    117f <realloc_strcat+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc_strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    11db <realloc_strcat+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1040 <myrealloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_strcat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1196 <realloc_strcat+0x56>
mov    (%rbx),%r15
test   %r15,%r15
je     1196 <realloc_strcat+0x56>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%esi
add    $0x1,%esi
mov    %r15,%rdi
call   1040 <myrealloc@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <realloc_strcpy@plt>

LLVM IR (-O0):
define i8* @realloc_strcat(i8** %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%6 = load i8**, i8*** %4
%7 = icmp eq i8** %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8, %2
%13 = load i8**, i8*** %4
%14 = load i8*, i8** %5
%15 = call i8* @realloc_strcpy(i8** %13, i8* %14)
store i8* %15, i8** %3
br label %35
16: ; preds = %8
%17 = load i8**, i8*** %4
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %21, %23
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i8* @myrealloc(i8* %18, i32 %28)
%30 = load i8**, i8*** %4
store i8* %29, i8** %30
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = load i8*, i8** %5
%34 = call i8* @strcat(i8* %32, i8* %33)
store i8* %34, i8** %3
br label %35
35: ; preds = %16, %12
%36 = load i8*, i8** %3
ret i8* %36
}

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