#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*/ error(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *concat(char *s1, char *separator, char *s2) {
  char *result =
      (char *)malloc(strlen(s1) + strlen(separator) + strlen(s2) + 1);
  if (!result) {
    error("Failed to allocate space");
  }
  strcpy(result, s1);
  strcat(result, separator);
  strcat(result, s2);
  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    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bc <concat+0x6c>
lea    0xe49(%rip),%rdi
call   1060 <error@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%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
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r13,%rbx
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a1 <concat+0x51>
lea    0xe64(%rip),%rdi
call   1060 <error@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Failed to allocate space\00"
define i8* @concat(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 nsw i64 %9, %11
%13 = load i8*, i8** %6
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %12, %14
%16 = add nsw i64 %15, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %3
%22 = call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %3
%24 = load i8*, i8** %7
%25 = load i8*, i8** %4
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i8*, i8** %7
%28 = load i8*, i8** %5
%29 = call i32 @strcat(i8* %27, i8* %28)
%30 = load i8*, i8** %7
%31 = load i8*, i8** %6
%32 = call i32 @strcat(i8* %30, i8* %31)
%33 = load i8*, i8** %7
ret i8* %33
}

LLVM IR (-O2):
@.str = [25 x i8] c"Failed to allocate space\00"
define i8* @concat(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 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = add i64 %4, 1
%8 = add i64 %7, %5
%9 = add i64 %8, %6
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = tail call i32 @strcpy(i8* %11, i8* %0)
%17 = tail call i32 @strcat(i8* %11, i8* %1)
%18 = tail call i32 @strcat(i8* %11, i8* %2)
ret i8* %11
}