#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 *ace_str_alloc(size_t);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, size_t);
char *ace_str_join_3(const char *s1, const char *s2, const char *s3) {
  size_t length = strlen(s1) + strlen(s2) + strlen(s3) + 1;
  char *result = ace_str_alloc(length);
  strncat(result, s1, length);
  strncat(result, s2, length);
  strncat(result, s3, length);
  return result;
}


x86 assembly (clang, -O0):
<ace_str_join_3>:
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,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <ace_str_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <strncat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <strncat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <strncat@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ace_str_join_3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r12d,%ebp
add    %ebp,%eax
add    $0x1,%eax
movslq %eax,%rbp
mov    %rbp,%rdi
call   1030 <ace_str_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1050 <strncat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1050 <strncat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1050 <strncat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ace_str_join_3(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%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 i32 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = call i8* @ace_str_alloc(i64 %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = load i8*, i8** %4
%23 = load i64, i64* %7
%24 = call i32 @strncat(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %8
%26 = load i8*, i8** %5
%27 = load i64, i64* %7
%28 = call i32 @strncat(i8* %25, i8* %26, i64 %27)
%29 = load i8*, i8** %8
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = call i32 @strncat(i8* %29, i8* %30, i64 %31)
%33 = load i8*, i8** %8
ret i8* %33
}

LLVM IR (-O2):
define i8* @ace_str_join_3(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 i32 %4, 1
%8 = add i32 %7, %5
%9 = add i32 %8, %6
%10 = sext i32 %9 to i64
%11 = tail call i8* @ace_str_alloc(i64 %10)
%12 = tail call i32 @strncat(i8* %11, i8* %0, i64 %10)
%13 = tail call i32 @strncat(i8* %11, i8* %1, i64 %10)
%14 = tail call i32 @strncat(i8* %11, i8* %2, i64 %10)
ret i8* %11
}