#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 */
void *_insert(void *, long, char *, long);
int /*<<< orphan*/ _ripremove(void *);
void *malloc(long);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, long);
void *realloc(void *, long);
extern void *_VDBG_malloc(void *ptr, long bytes, char *file, long line) {
  bytes += 64;
  if (ptr) {
    ptr = (void *)(((char *)ptr) - 64);
    _ripremove(ptr);
    ptr = realloc(ptr, bytes);
  } else {
    ptr = malloc(bytes);
    memset(ptr, 0, bytes);
  }
  return _insert(ptr, bytes, file, line);
}


x86 assembly (clang, -O0):
<_VDBG_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11aa <_VDBG_malloc+0x5a>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffc0,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <_ripremove@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11c6 <_VDBG_malloc+0x76>
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <_insert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_VDBG_malloc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
add    $0x40,%r13
test   %rdi,%rdi
je     118a <_VDBG_malloc+0x3a>
mov    %rdi,%rbx
add    $0xffffffffffffffc0,%rbx
mov    %rbx,%rdi
call   1070 <_ripremove@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <realloc@plt>
mov    %rax,%r12
jmp    11a2 <_VDBG_malloc+0x52>
mov    %r13,%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13,%rdx
call   1030 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <_insert@plt>

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

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