#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__ calloc(int, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *str3cat(char *s1, char *s2, char *s3) {
  char *ret =
      (char *)calloc(strlen(s1) + strlen(s2) + strlen(s3) + 1, sizeof(char));
  strcpy(ret, s1);
  strcat(ret, s2);
  strcat(ret, s3);
  ret[strlen(s1) + strlen(s2) + strlen(s3)] = 0;
  return ret;
}


x86 assembly (clang, -O0):
<str3cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%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    -0x30(%rbp),%rcx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
add    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str3cat>:
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
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
add    %r12,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %rbx,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @str3cat(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add i64 %9, %11
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = add i64 %12, %14
%16 = add i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i64 @calloc(i32 %17, i32 1)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %7
%27 = load i8*, i8** %6
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %7
%30 = load i8*, i8** %4
%31 = call i64 @strlen(i8* %30)
%32 = load i8*, i8** %5
%33 = call i64 @strlen(i8* %32)
%34 = add i64 %31, %33
%35 = load i8*, i8** %6
%36 = call i64 @strlen(i8* %35)
%37 = add i64 %34, %36
%38 = getelementptr inbounds i8, i8* %29, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %7
ret i8* %39
}

LLVM IR (-O2):
define i8* @str3cat(i8* %0, i8* %1, i8* %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 i32 %9, 1
%11 = tail call i64 @calloc(i32 %10, i32 1)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @strcpy(i8* %12, i8* %0)
%14 = tail call i32 @strcat(i8* %12, i8* %1)
%15 = tail call i32 @strcat(i8* %12, i8* %2)
%16 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%17 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%18 = add i64 %17, %16
%19 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%20 = add i64 %18, %19
%21 = getelementptr inbounds i8, i8* %12, i64 %20
store i8 0, i8* %21
ret i8* %12
}