#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
char *concat3(const char *t1, const char *t2, const char *t3) {
  int l1 = strlen(t1);
  int l2 = strlen(t2);
  int l3 = strlen(t3);
  char *text = malloc(l1 + l2 + l3 + 1);
  memcpy(text, t1, l1);
  memcpy(text + l1, t2, l2);
  memcpy(text + l1 + l2, t3, l3);
  text[l1 + l2 + l3] = 0;
  return text;
}


x86 assembly (clang, -O0):
<concat3>:
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   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
add    -0x20(%rbp),%edi
add    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@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 <memcpy@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):
<concat3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rdx,0x10(%rsp)
mov    %rsi,%rbp
mov    %rsi,0x8(%rsp)
mov    %rdi,(%rsp)
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    (%r12,%r13,1),%eax
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
mov    %eax,%r15d
add    %ebx,%r15d
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    (%rsp),%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
movslq %r12d,%rbp
add    %r14,%rbp
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
movslq %r13d,%rdi
add    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @concat3(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 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %8
%15 = load i8*, i8** %6
%16 = call i32 @strlen(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* @malloc(i32 %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i8*, i8** %10
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8*, i8** %5
%33 = load i32, i32* %8
%34 = call i32 @memcpy(i8* %31, i8* %32, i32 %33)
%35 = load i8*, i8** %10
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8*, i8** %6
%43 = load i32, i32* %9
%44 = call i32 @memcpy(i8* %41, i8* %42, i32 %43)
%45 = load i8*, i8** %10
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = add nsw i32 %46, %47
%49 = load i32, i32* %9
%50 = add nsw i32 %48, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %45, i64 %51
store i8 0, i8* %52
%53 = load i8*, i8** %10
ret i8* %53
}

LLVM IR (-O2):
define i8* @concat3(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* %2)
%7 = add nsw i32 %5, %4
%8 = add nsw i32 %7, %6
%9 = add nsw i32 %8, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @memcpy(i8* %10, i8* %0, i32 %4)
%12 = sext i32 %4 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = tail call i32 @memcpy(i8* %13, i8* %1, i32 %5)
%15 = sext i32 %5 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = tail call i32 @memcpy(i8* %16, i8* %2, i32 %6)
%18 = sext i32 %8 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
store i8 0, i8* %19
ret i8* %10
}