#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*/ abort();
int /*<<< orphan*/ free(char *);
void *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *, char *);
scalar_t__ strlen(char const *);
char *merge3(char *a, const char *op, char *b) {
  char *buf;
  buf = ({
    void *alloc_size_tmp = malloc(strlen(op) + strlen(a) + strlen(b) + 1);
    if (!alloc_size_tmp)
      abort();
    alloc_size_tmp;
  });
  sprintf(buf, "%s%s%s", a, op, b);
  free(a);
  free(b);
  return buf;
}


x86 assembly (clang, -O0):
<merge3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b7 <merge3+0x67>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe22(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge3>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %r13,%rbx
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11cd <merge3+0x7d>
mov    %rax,%rbx
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <sprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%s%s%s\00"
define i8* @merge3(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %11, %13
%15 = load i8*, i8** %6
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %14, %16
%18 = add nsw i64 %17, 1
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %3
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %3
%25 = load i8*, i8** %8
store i8* %25, i8** %9
%26 = load i8*, i8** %9
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i8*, i8** %6
%31 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29, i8* %30)
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %7
ret i8* %36
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
define noalias i8* @merge3(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%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 i8* @malloc(i64 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %3
%15 = tail call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%16 = tail call i32 @free(i8* %0)
%17 = tail call i32 @free(i8* %2)
ret i8* %10
}