#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ BUF_MEM;

/* Variables and functions */
TYPE_1__ *BUF_MEM_create(size_t);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void const *, size_t);
BUF_MEM *BUF_MEM_create_init(const void *buf, size_t len) {
  BUF_MEM *out;
  out = BUF_MEM_create(len);
  if (!out)
    return NULL;
  memcpy(out->data, buf, len);
  return out;
}


x86 assembly (clang, -O0):
<BUF_MEM_create_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <BUF_MEM_create@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1155 <BUF_MEM_create_init+0x35>
movq   $0x0,-0x8(%rbp)
jmp    1170 <BUF_MEM_create_init+0x50>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BUF_MEM_create_init>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <BUF_MEM_create@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1148 <BUF_MEM_create_init+0x28>
mov    (%rbx),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32 }
define %struct.TYPE_4__* @BUF_MEM_create_init(i8* %0, i64 %1) {
%3 = alloca %struct.TYPE_4__*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.TYPE_4__*
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = call %struct.TYPE_4__* @BUF_MEM_create(i64 %7)
store %struct.TYPE_4__* %8, %struct.TYPE_4__** %6
%9 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%10 = icmp ne %struct.TYPE_4__* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store %struct.TYPE_4__* null, %struct.TYPE_4__** %3
br label %20
12: ; preds = %2
%13 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i8*, i8** %4
%17 = load i64, i64* %5
%18 = call i32 @memcpy(i32 %15, i8* %16, i64 %17)
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
store %struct.TYPE_4__* %19, %struct.TYPE_4__** %3
br label %20
20: ; preds = %12, %11
%21 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
ret %struct.TYPE_4__* %21
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 }
define %struct.TYPE_4__* @BUF_MEM_create_init(i8* %0, i64 %1) {
%3 = tail call %struct.TYPE_4__* @BUF_MEM_create(i64 %1)
%4 = icmp eq %struct.TYPE_4__* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @memcpy(i32 %7, i8* %0, i64 %1)
br label %9
9: ; preds = %2, %5
ret %struct.TYPE_4__* %3
}