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


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

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

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

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