#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_space(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) + 2);
    strcat(*target, " ");
    strcat(*target, source);
  }
}


x86 assembly (clang, -O0):
<mp_strcat_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1160 <mp_strcat_space+0x20>
jmp    11f0 <mp_strcat_space+0xb0>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1186 <mp_strcat_space+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <mp_strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11eb <mp_strcat_space+0xab>
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    $0x2,%rsi
call   1050 <mp_realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe2a(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
jmp    11f0 <mp_strcat_space+0xb0>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp_strcat_space>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11b1 <mp_strcat_space+0x71>
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rbx
test   %rbx,%rbx
je     11a6 <mp_strcat_space+0x66>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x2,%rsi
mov    %rbx,%rdi
call   1050 <mp_realloc@plt>
mov    %rax,(%r14)
lea    0xe78(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcat@plt>
mov    (%r14),%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <strcat@plt>
mov    %r15,%rdi
call   1030 <mp_strdup@plt>
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @mp_strcat_space(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 %36
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 %35
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, 2
%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 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%31 = load i8**, i8*** %3
%32 = load i8*, i8** %31
%33 = load i8*, i8** %4
%34 = call i32 @strcat(i8* %32, i8* %33)
br label %35
35: ; preds = %16, %12
br label %36
36: ; preds = %7, %35
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @mp_strcat_space(i8** nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %18, 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 %18
9: ; preds = %4
%10 = tail call i64 @strlen(i8* %5)
%11 = tail call i64 @strlen(i8* %1)
%12 = add i64 %10, 2
%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* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %0
%17 = tail call i32 @strcat(i8* %16, i8* %1)
br label %18
18: ; preds = %7, %9, %2
ret void
}