#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*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ xmalloc(int);
char *concat(char *s1, char *s2, char *s3) {
  int len1 = strlen(s1), len2 = strlen(s2), len3 = strlen(s3);
  char *result = ((char *)xmalloc((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
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <xmalloc@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),%edi
add    $0x1,%edi
mov    %ecx,%r14d
add    %eax,%r14d
call   1050 <xmalloc@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 = trunc i64 %24 to i32
%26 = call i64 @xmalloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %28, i8* %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 = call i32 @strcpy(i8* %34, i8* %35)
%37 = load i8*, i8** %10
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8*, i8** %6
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = load i8*, i8** %10
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = add nsw i32 %47, %48
%50 = load i32, i32* %9
%51 = add nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %46, i64 %52
store i8 0, i8* %53
%54 = load i8*, i8** %10
ret i8* %54
}

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 = tail call i64 @xmalloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @strcpy(i8* %11, i8* %0)
%13 = sext i32 %4 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = tail call i32 @strcpy(i8* %14, i8* %1)
%16 = sext i32 %5 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = tail call i32 @strcpy(i8* %17, i8* %2)
%19 = sext i32 %8 to i64
%20 = getelementptr inbounds i8, i8* %11, i64 %19
store i8 0, i8* %20
ret i8* %11
}