#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__ malloc(unsigned int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, unsigned int);
unsigned char *mem_combine(const unsigned char *src1, unsigned int src1_len,
                           const unsigned char *src2, unsigned int src2_len) {
  unsigned char *p = (unsigned char *)malloc(src1_len + src2_len);
  if (!p)
    return NULL;
  memcpy(p, src1, src1_len);
  memcpy(p + src1_len, src2, src2_len);
  return p;
}


x86 assembly (clang, -O0):
<mem_combine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%edi
add    -0x24(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    115d <mem_combine+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    118b <mem_combine+0x6b>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_combine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r13
lea    (%r14,%r12,1),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1167 <mem_combine+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <memcpy@plt>
mov    %r12d,%edi
add    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
jmp    1169 <mem_combine+0x49>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mem_combine(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %7
%12 = load i32, i32* %9
%13 = add i32 %11, %12
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %4
store i8* null, i8** %5
br label %32
19: ; preds = %4
%20 = load i8*, i8** %10
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %10
%25 = load i32, i32* %7
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = call i32 @memcpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %10
store i8* %31, i8** %5
br label %32
32: ; preds = %19, %18
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
define i8* @mem_combine(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = add i32 %3, %1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i32 @memcpy(i8* %7, i8* %0, i32 %1)
%11 = zext i32 %1 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = tail call i32 @memcpy(i8* %12, i8* %2, i32 %3)
br label %14
14: ; preds = %4, %9
%15 = phi i8* [ %7, %9 ], [ null, %4 ]
ret i8* %15
}