#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*/ assert(int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *XXH_strcatDup(const char *s1, const char *s2) {
  assert(s1 != NULL);
  assert(s2 != NULL);
  {
    size_t len1 = strlen(s1);
    size_t len2 = strlen(s2);
    char *buf = (char *)malloc(len1 + len2 + 1);
    if (buf != NULL) {
      memcpy(buf, s1, len1);
      memcpy(buf + len1, s2, len2 + 1);
    }
    return buf;
  }
}


x86 assembly (clang, -O0):
<XXH_strcatDup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d8 <XXH_strcatDup+0x98>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XXH_strcatDup>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
lea    (%rax,%r12,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b9 <XXH_strcatDup+0x79>
add    $0x1,%r13
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
add    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1050 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @XXH_strcatDup(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 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %3
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %5
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %6
%20 = load i64, i64* %5
%21 = load i64, i64* %6
%22 = add i64 %20, %21
%23 = add i64 %22, 1
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %40
28: ; preds = %2
%29 = load i8*, i8** %7
%30 = load i8*, i8** %3
%31 = load i64, i64* %5
%32 = call i32 @memcpy(i8* %29, i8* %30, i64 %31)
%33 = load i8*, i8** %7
%34 = load i64, i64* %5
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8*, i8** %4
%37 = load i64, i64* %6
%38 = add i64 %37, 1
%39 = call i32 @memcpy(i8* %35, i8* %36, i64 %38)
br label %40
40: ; preds = %28, %2
%41 = load i8*, i8** %7
ret i8* %41
}

LLVM IR (-O2):
define i8* @XXH_strcatDup(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = add i64 %10, 1
%12 = add i64 %11, %9
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = tail call i32 @memcpy(i8* %14, i8* %0, i64 %9)
%18 = getelementptr inbounds i8, i8* %14, i64 %9
%19 = tail call i32 @memcpy(i8* %18, i8* %1, i64 %11)
br label %20
20: ; preds = %16, %2
ret i8* %14
}