void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment)

{

    size_t align = QEMU_VMALLOC_ALIGN;

    size_t total = size + align - getpagesize();

    void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

    size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;

    void *ptr1;



    if (ptr == MAP_FAILED) {

        return NULL;

    }



    if (alignment) {

        *alignment = align;

    }



    ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,

                MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

    if (ptr1 == MAP_FAILED) {

        munmap(ptr, total);

        return NULL;

    }



    ptr += offset;

    total -= offset;



    if (offset > 0) {

        munmap(ptr - offset, offset);

    }

    if (total > size) {

        munmap(ptr + size, total - size);

    }



    trace_qemu_anon_ram_alloc(size, ptr);

    return ptr;

}

void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment)

{

    size_t align = QEMU_VMALLOC_ALIGN;

    size_t total = size + align - getpagesize();

    void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

    size_t offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;

    void *ptr1;



    if (ptr == MAP_FAILED) {

        return NULL;

    }



    if (alignment) {

        *alignment = align;

    }



    ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,

                MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

    if (ptr1 == MAP_FAILED) {

        munmap(ptr, total);

        return NULL;

    }



    ptr += offset;

    total -= offset;



    if (offset > 0) {

        munmap(ptr - offset, offset);

    }

    if (total > size) {

        munmap(ptr + size, total - size);

    }



    trace_qemu_anon_ram_alloc(size, ptr);

    return ptr;

}

    size_t total = size + align - getpagesize();     if (total > size) {         munmap(ptr + size, total - size);
void *FUNC_0(size_t VAR_0, uint64_t *VAR_1)

{

    size_t align = QEMU_VMALLOC_ALIGN;

    size_t total = VAR_0 + align - getpagesize();

    void *VAR_2 = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

    size_t offset = QEMU_ALIGN_UP((uintptr_t)VAR_2, align) - (uintptr_t)VAR_2;

    void *VAR_3;



    if (VAR_2 == MAP_FAILED) {

        return NULL;

    }



    if (VAR_1) {

        *VAR_1 = align;

    }



    VAR_3 = mmap(VAR_2 + offset, VAR_0, PROT_READ | PROT_WRITE,

                MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

    if (VAR_3 == MAP_FAILED) {

        munmap(VAR_2, total);

        return NULL;

    }



    VAR_2 += offset;

    total -= offset;



    if (offset > 0) {

        munmap(VAR_2 - offset, offset);

    }

    if (total > VAR_0) {

        munmap(VAR_2 + VAR_0, total - VAR_0);

    }



    trace_qemu_anon_ram_alloc(VAR_0, VAR_2);

    return VAR_2;

}

void *FUNC_0(size_t VAR_0, uint64_t *VAR_1)
{ size_t align = QEMU_VMALLOC_ALIGN; size_t total = VAR_0 + align - getpagesize(); void *VAR_2 = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); size_t offset = QEMU_ALIGN_UP((uintptr_t)VAR_2, align) - (uintptr_t)VAR_2; void *VAR_3; if (VAR_2 == MAP_FAILED) { return NULL; } if (VAR_1) { *VAR_1 = align; } VAR_3 = mmap(VAR_2 + offset, VAR_0, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (VAR_3 == MAP_FAILED) { munmap(VAR_2, total); return NULL; } VAR_2 += offset; total -= offset; if (offset > 0) { munmap(VAR_2 - offset, offset); } if (total > VAR_0) { munmap(VAR_2 + VAR_0, total - VAR_0); } trace_qemu_anon_ram_alloc(VAR_0, VAR_2); return VAR_2; }