#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 */
scalar_t__ eMalloc(size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *concat(const char *s1, const char *s2, const char *s3) {
  int len1 = strlen(s1), len2 = strlen(s2), len3 = strlen(s3);
  char *result =
      (char *)eMalloc((size_t)(len1 + len2 + len3 + 1) * sizeof(char));
  strcpy(result, s1);
  strcpy(result + len1, s2);
  strcpy(result + len1 + len2, s3);
  result[len1 + len2 + len3] = '\0';
  return result;
}


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

LLVM IR (-O0):
define i8* @concat(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 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = call i64 @eMalloc(i64 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = load i8*, i8** %4
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %10
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8*, i8** %5
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %10
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8*, i8** %6
%44 = call i32 @strcpy(i8* %42, i8* %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* @concat(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 = sext i32 %9 to i64
%11 = tail call i64 @eMalloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @strcpy(i8* %12, i8* %0)
%14 = sext i32 %4 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = tail call i32 @strcpy(i8* %15, i8* %1)
%17 = sext i32 %5 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = tail call i32 @strcpy(i8* %18, i8* %2)
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds i8, i8* %12, i64 %20
store i8 0, i8* %21
ret i8* %12
}