#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 */
struct cpl_allocator {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cpl_dl_free(struct cpl_allocator *, void *);
void *cpl_dl_malloc(struct cpl_allocator *, size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
void *cpl_dl_dummy_realloc(struct cpl_allocator *allocator, void *ptr,
                           size_t old_sz, size_t new_sz) {
  void *mem = cpl_dl_malloc(allocator, new_sz);
  if (mem) {
    memcpy(mem, ptr, old_sz);
  }
  cpl_dl_free(allocator, ptr);
  return mem;
}


x86 assembly (clang, -O0):
<cpl_dl_dummy_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <cpl_dl_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1175 <cpl_dl_dummy_realloc+0x45>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <cpl_dl_free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpl_dl_dummy_realloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rcx,%rsi
call   1050 <cpl_dl_malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115f <cpl_dl_dummy_realloc+0x2f>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <cpl_dl_free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.cpl_allocator = type { i32 }
define i8* @cpl_dl_dummy_realloc(%struct.cpl_allocator* %0, i8* %1, i64 %2, i64 %3) {
%5 = tail call i8* @cpl_dl_malloc(%struct.cpl_allocator* %0, i64 %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @memcpy(i8* %5, i8* %1, i64 %2)
br label %9
9: ; preds = %7, %4
%10 = tail call i32 @cpl_dl_free(%struct.cpl_allocator* %0, i8* %1)
ret i8* %5
}