char *concat(s1, s2, s3)
char *s1, *s2, *s3;
{
  int len = strlen(s1) + strlen(s2) + strlen(s3);
  char *new = (char *)xmalloc(len + 1);
  strcpy(new, s1);
  strcat(new, s2);
  strcat(new, s3);
  return new;
}


x86 assembly (clang, -O0):
<concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    $0x0,%al
call   1050 <xmalloc@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
add    %r13d,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
xor    %eax,%eax
call   1050 <xmalloc@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <strcat@plt>

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 i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
%13 = add i64 %10, %12
%14 = load i8*, i8** %6
%15 = call i64 @strlen(i8* %14)
%16 = add i64 %13, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
%20 = call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %19)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = load i8*, i8** %4
%25 = call i8* @strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %8
%27 = load i8*, i8** %5
%28 = call i8* @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %8
%30 = load i8*, i8** %6
%31 = call i8* @strcat(i8* %29, i8* %30)
%32 = load i8*, i8** %8
ret i8* %32
}

LLVM IR (-O2):
define i8* @concat(i8* nocapture %0, i8* nocapture %1, i8* nocapture %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %5, %4
%7 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%8 = add i64 %6, %7
%9 = trunc i64 %8 to i32
%10 = add nsw i32 %9, 1
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %10)
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = tail call i8* @strcpy(i8* dereferenceable(1) %13, i8* dereferenceable(1) %0)
%15 = tail call i8* @strcat(i8* dereferenceable(1) %13, i8* dereferenceable(1) %1)
%16 = tail call i8* @strcat(i8* dereferenceable(1) %13, i8* dereferenceable(1) %2)
ret i8* %13
}