#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 *crAlloc(int const);
int /*<<< orphan*/ crMemcpy(char *, char const *, int const);
int crStrlen(char const *);
char *crStrjoin(const char *str1, const char *str2) {
  const int len1 = crStrlen(str1), len2 = crStrlen(str2);
  char *s = crAlloc(len1 + len2 + 1);
  if (s) {
    crMemcpy(s, str1, len1);
    crMemcpy(s + len1, str2, len2);
    s[len1 + len2] = '\0';
  }
  return s;
}


x86 assembly (clang, -O0):
<crStrjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <crStrlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <crStrlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    -0x18(%rbp),%edi
add    $0x1,%edi
call   1030 <crAlloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ad <crStrjoin+0x7d>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <crMemcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <crMemcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crStrjoin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <crStrlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1050 <crStrlen@plt>
mov    %eax,%r12d
lea    (%r12,%r13,1),%edi
add    $0x1,%edi
call   1030 <crAlloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1197 <crStrjoin+0x67>
mov    %r12d,%ebp
add    %r13d,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <crMemcpy@plt>
movslq %r13d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <crMemcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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