#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_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int /*<<< orphan*/ max;
  int /*<<< orphan*/ length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ BUF_MEM;

/* Variables and functions */
TYPE_1__ *BUF_MEM_create(int /*<<< orphan*/);
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
BUF_MEM *BUF_MEM_dup(const BUF_MEM *in) {
  BUF_MEM *out = NULL;
  if (!in)
    return NULL;
  out = BUF_MEM_create(in->length);
  {
    if (!(out)) {
      {
        fprintf(stderr,
                "[ERROR] (%s:%d ) "
                "Failed to allocate memory"
                "\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/"
                "master/src/misc.c",
                162);
        ERR_print_errors_fp(stderr);
      };
      goto err;
    }
  };
  memcpy(out->data, in->data, in->length);
  out->max = in->max;
err:
  return out;
}


x86 assembly (clang, -O0):
<BUF_MEM_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <BUF_MEM_dup+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11e9 <BUF_MEM_dup+0xa9>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <BUF_MEM_create@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bb <BUF_MEM_dup+0x7b>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
lea    0xe8e(%rip),%rdx
mov    $0xa2,%ecx
call   1040 <fprintf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <ERR_print_errors_fp@plt>
jmp    11e1 <BUF_MEM_dup+0xa1>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BUF_MEM_dup>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1199 <BUF_MEM_dup+0x59>
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1030 <BUF_MEM_create@plt>
test   %rax,%rax
je     1171 <BUF_MEM_dup+0x31>
mov    %rax,%r14
mov    0x8(%rax),%edi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%esi
call   1050 <memcpy@plt>
mov    (%rbx),%eax
mov    %eax,(%r14)
jmp    119c <BUF_MEM_dup+0x5c>
mov    0x2e68(%rip),%rbx
mov    (%rbx),%edi
lea    0xe7f(%rip),%rsi
lea    0xea4(%rip),%rdx
mov    $0xa2,%ecx
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1060 <ERR_print_errors_fp@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [44 x i8] c"[ERROR] (%s:%d ) Failed to allocate memory\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/master/src/misc.c\00"
define %struct.TYPE_5__* @BUF_MEM_dup(%struct.TYPE_5__* %0) {
%2 = alloca %struct.TYPE_5__*
%3 = alloca %struct.TYPE_5__*
%4 = alloca %struct.TYPE_5__*
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %3
store %struct.TYPE_5__* null, %struct.TYPE_5__** %4
%5 = load %struct.TYPE_5__*, %struct.TYPE_5__** %3
%6 = icmp ne %struct.TYPE_5__* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store %struct.TYPE_5__* null, %struct.TYPE_5__** %2
br label %38
8: ; preds = %1
%9 = load %struct.TYPE_5__*, %struct.TYPE_5__** %3
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call %struct.TYPE_5__* @BUF_MEM_create(i32 %11)
store %struct.TYPE_5__* %12, %struct.TYPE_5__** %4
%13 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%14 = icmp ne %struct.TYPE_5__* %13, null
br i1 %14, label %20, label %15
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 162)
%18 = load i32, i32* @stderr
%19 = call i32 @ERR_print_errors_fp(i32 %18)
br label %36
20: ; preds = %8
%21 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = load %struct.TYPE_5__*, %struct.TYPE_5__** %3
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %24, i32 0, i32 2
%26 = load i32, i32* %25
%27 = load %struct.TYPE_5__*, %struct.TYPE_5__** %3
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i32 @memcpy(i32 %23, i32 %26, i32 %29)
%31 = load %struct.TYPE_5__*, %struct.TYPE_5__** %3
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
%35 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %34, i32 0, i32 0
store i32 %33, i32* %35
br label %36
36: ; preds = %20, %15
%37 = load %struct.TYPE_5__*, %struct.TYPE_5__** %4
store %struct.TYPE_5__* %37, %struct.TYPE_5__** %2
br label %38
38: ; preds = %36, %7
%39 = load %struct.TYPE_5__*, %struct.TYPE_5__** %2
ret %struct.TYPE_5__* %39
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [44 x i8] c"[ERROR] (%s:%d ) Failed to allocate memory\0A\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/d0/openpace/refs/heads/master/src/misc.c\00"
define %struct.TYPE_5__* @BUF_MEM_dup(%struct.TYPE_5__* %0) {
%2 = icmp eq %struct.TYPE_5__* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = tail call %struct.TYPE_5__* @BUF_MEM_create(i32 %5)
%7 = icmp eq %struct.TYPE_5__* %6, null
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 162)
%11 = load i32, i32* @stderr
%12 = tail call i32 @ERR_print_errors_fp(i32 %11)
br label %23
13: ; preds = %3
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 2
%17 = load i32, i32* %16
%18 = load i32, i32* %4
%19 = tail call i32 @memcpy(i32 %15, i32 %17, i32 %18)
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 0
store i32 %21, i32* %22
br label %23
23: ; preds = %8, %13, %1
%24 = phi %struct.TYPE_5__* [ null, %1 ], [ %6, %13 ], [ null, %8 ]
ret %struct.TYPE_5__* %24
}