#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*/ copy_memory(char *, char const *, size_t);
size_t mu_strlen(char const *);
scalar_t__ safe_malloc(size_t, int /*<<< orphan*/);
char *astrcat(const char *str1, const char *str2) {
  register size_t len1 = mu_strlen(str1);
  register size_t len2 = mu_strlen(str2);
  char *dest = (char *)safe_malloc(len1 + len2, 0);
  if (str1)
    copy_memory(dest, str1, len1);
  if (str2)
    copy_memory(dest + len1, str2, len2);
  return dest;
}


x86 assembly (clang, -O0):
<astrcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <mu_strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <mu_strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1030 <safe_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1189 <astrcat+0x59>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <copy_memory@plt>
cmpq   $0x0,-0x10(%rbp)
je     11a9 <astrcat+0x79>
mov    -0x28(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <copy_memory@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrcat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <mu_strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1050 <mu_strlen@plt>
mov    %rax,%r15
lea    (%rax,%r12,1),%rdi
xor    %esi,%esi
call   1030 <safe_malloc@plt>
mov    %rax,%r13
test   %rbx,%rbx
je     1173 <astrcat+0x43>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <copy_memory@plt>
test   %r14,%r14
je     1189 <astrcat+0x59>
mov    %r13,%rdi
add    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <copy_memory@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @astrcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i64 @mu_strlen(i8* %8)
store i64 %9, i64* %5
%10 = load i8*, i8** %4
%11 = call i64 @mu_strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %5
%13 = load i64, i64* %6
%14 = add i64 %12, %13
%15 = call i64 @safe_malloc(i64 %14, i32 0)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8*, i8** %7
%21 = load i8*, i8** %3
%22 = load i64, i64* %5
%23 = call i32 @copy_memory(i8* %20, i8* %21, i64 %22)
br label %24
24: ; preds = %19, %2
%25 = load i8*, i8** %4
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = load i64, i64* %5
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8*, i8** %4
%32 = load i64, i64* %6
%33 = call i32 @copy_memory(i8* %30, i8* %31, i64 %32)
br label %34
34: ; preds = %27, %24
%35 = load i8*, i8** %7
ret i8* %35
}

LLVM IR (-O2):
define i8* @astrcat(i8* %0, i8* %1) {
%3 = tail call i64 @mu_strlen(i8* %0)
%4 = tail call i64 @mu_strlen(i8* %1)
%5 = add i64 %4, %3
%6 = tail call i64 @safe_malloc(i64 %5, i32 0)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i8* %0, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @copy_memory(i8* %7, i8* %0, i64 %3)
br label %11
11: ; preds = %9, %2
%12 = icmp eq i8* %1, null
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = getelementptr inbounds i8, i8* %7, i64 %3
%15 = tail call i32 @copy_memory(i8* %14, i8* %1, i64 %4)
br label %16
16: ; preds = %13, %11
ret i8* %7
}