#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*/ fatal(char const *, char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *astrcat(const char *src1, const char *src2) {
  static const char fnName[] __attribute__((unused)) = "astrcat()";
  char *catString = NULL;
  size_t catLength = strlen(src1) + strlen(src2) + 1;
  if ((catString = (char *)malloc(catLength * sizeof(char))) == NULL) {
    fatal(fnName, "Out of memory!");
  } else {
    strcpy(catString, src1);
    strcat(catString, src2);
  }
  return catString;
}


x86 assembly (clang, -O0):
<astrcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c0 <astrcat+0x70>
lea    0xe51(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1070 <fatal@plt>
jmp    11da <astrcat+0x8a>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrcat>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
movslq %eax,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1197 <astrcat+0x47>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    11aa <astrcat+0x5a>
lea    0xe62(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fatal@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@astrcat.fnName = internal constant [10 x i8] c"astrcat()\00"
@.str = [15 x i8] c"Out of memory!\00"
define i8* @astrcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = mul i64 %14, 1
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @astrcat.fnName, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %28
21: ; preds = %2
%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)
br label %28
28: ; preds = %21, %19
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@astrcat.fnName = internal constant [10 x i8] c"astrcat()\00"
@.str = [15 x i8] c"Out of memory!\00"
define i8* @astrcat(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %3, 1
%6 = add i32 %5, %4
%7 = sext i32 %6 to i64
%8 = tail call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @astrcat.fnName, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %16
13: ; preds = %2
%14 = tail call i32 @strcpy(i8* %9, i8* %0)
%15 = tail call i32 @strcat(i8* %9, i8* %1)
br label %16
16: ; preds = %13, %11
ret i8* %9
}