#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 *mman_malloc(int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ rtime_getMPool();
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *mxstr_mstrcat(char *cop1, char *cop2) {
  char *cptr;
  if (cop1 == NULL)
    cop1 = "null";
  if (cop2 == NULL)
    cop2 = "null";
  cptr = mman_malloc(rtime_getMPool(), strlen(cop1) + strlen(cop2) + 1);
  strcpy(cptr, cop1);
  strcat(cptr, cop2);
  return cptr;
}


x86 assembly (clang, -O0):
<mxstr_mstrcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1176 <mxstr_mstrcat+0x26>
lea    0xe8e(%rip),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118c <mxstr_mstrcat+0x3c>
lea    0xe78(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <rtime_getMPool@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edi
add    %rax,%rsi
add    $0x1,%rsi
call   1030 <mman_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mxstr_mstrcat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xe9c(%rip),%rax
cmove  %rax,%rbx
mov    %rsi,%r14
test   %rsi,%rsi
cmove  %rax,%r14
xor    %eax,%eax
call   1060 <rtime_getMPool@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%rsi
add    $0x1,%rsi
mov    %r15d,%edi
call   1030 <mman_malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"null\00"
define i8* @mxstr_mstrcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
br label %9
9: ; preds = %8, %2
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
br label %13
13: ; preds = %12, %9
%14 = call i32 (...) @rtime_getMPool()
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = add nsw i64 %19, 1
%21 = call i8* @mman_malloc(i32 %14, i64 %20)
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %5
%26 = load i8*, i8** %4
%27 = call i32 @strcat(i8* %25, i8* %26)
%28 = load i8*, i8** %5
ret i8* %28
}

LLVM IR (-O2):
@.str = [5 x i8] c"null\00"
define i8* @mxstr_mstrcat(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0
%5 = icmp eq i8* %1, null
%6 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1
%7 = tail call i32 (...) @rtime_getMPool()
%8 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%10 = add i64 %8, 1
%11 = add i64 %10, %9
%12 = tail call i8* @mman_malloc(i32 %7, i64 %11)
%13 = tail call i32 @strcpy(i8* %12, i8* %4)
%14 = tail call i32 @strcat(i8* %12, i8* %6)
ret i8* %12
}