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


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

x86 assembly (clang, -O2):
<crStrjoin3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,(%rsp)
call   1050 <crStrlen@plt>
mov    %eax,%r14d
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <crStrlen@plt>
mov    %eax,%ebx
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
call   1050 <crStrlen@plt>
mov    %eax,%r12d
lea    (%rbx,%r14,1),%r13d
lea    (%r12,%r13,1),%edi
add    $0x1,%edi
call   1030 <crAlloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11cc <crStrjoin3+0x9c>
add    %r12d,%r13d
mov    %r15,%rdi
mov    (%rsp),%rsi
mov    %r14d,%edx
call   1040 <crMemcpy@plt>
movslq %r14d,%rax
mov    %r15,%rbp
add    %rax,%rbp
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    %ebx,%edx
call   1040 <crMemcpy@plt>
movslq %ebx,%rdi
add    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %r12d,%edx
call   1040 <crMemcpy@plt>
movslq %r13d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @crStrjoin3(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
%12 = call i32 @crStrlen(i8* %11)
store i32 %12, i32* %7
%13 = load i8*, i8** %5
%14 = call i32 @crStrlen(i8* %13)
store i32 %14, i32* %8
%15 = load i8*, i8** %6
%16 = call i32 @crStrlen(i8* %15)
store i32 %16, i32* %9
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = add nsw i32 %17, %18
%20 = load i32, i32* %9
%21 = add nsw i32 %19, %20
%22 = add nsw i32 %21, 1
%23 = call i8* @crAlloc(i32 %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %56
26: ; preds = %3
%27 = load i8*, i8** %10
%28 = load i8*, i8** %4
%29 = load i32, i32* %7
%30 = call i32 @crMemcpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %10
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8*, i8** %5
%36 = load i32, i32* %8
%37 = call i32 @crMemcpy(i8* %34, i8* %35, i32 %36)
%38 = load i8*, i8** %10
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8*, i8** %6
%46 = load i32, i32* %9
%47 = call i32 @crMemcpy(i8* %44, i8* %45, i32 %46)
%48 = load i8*, i8** %10
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = add nsw i32 %49, %50
%52 = load i32, i32* %9
%53 = add nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %48, i64 %54
store i8 0, i8* %55
br label %56
56: ; preds = %26, %3
%57 = load i8*, i8** %10
ret i8* %57
}

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