#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 *mp_realloc(char *, scalar_t__);
char *mp_strdup(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
void mp_strcat(char **target, char *source) {
  if (source == NULL) {
    return;
  } else if (*target == NULL) {
    *target = mp_strdup(source);
  } else {
    *target = mp_realloc(*target, strlen(*target) + strlen(source) + 1);
    strcat(*target, source);
  }
}


x86 assembly (clang, -O0):
<mp_strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1160 <mp_strcat+0x20>
jmp    11dd <mp_strcat+0x9d>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1186 <mp_strcat+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <mp_strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11d8 <mp_strcat+0x98>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1050 <mp_realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
jmp    11dd <mp_strcat+0x9d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_strcat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11a2 <mp_strcat+0x62>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rdi),%r15
test   %r15,%r15
je     1197 <mp_strcat+0x57>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1050 <mp_realloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <strcat@plt>
mov    %rbx,%rdi
call   1030 <mp_strdup@plt>
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @mp_strcat(i8** nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %16, 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
%8 = tail call i8* @mp_strdup(i8* %1)
store i8* %8, i8** %0
br label %16
9: ; preds = %4
%10 = tail call i64 @strlen(i8* %5)
%11 = tail call i64 @strlen(i8* %1)
%12 = add i64 %10, 1
%13 = add i64 %12, %11
%14 = tail call i8* @mp_realloc(i8* %5, i64 %13)
store i8* %14, i8** %0
%15 = tail call i32 @strcat(i8* %14, i8* %1)
br label %16
16: ; preds = %7, %9, %2
ret void
}