static int rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block)

{

    RDMALocalBlocks *local = &rdma->local_ram_blocks;

    RDMALocalBlock *old = local->block;

    int x;



    if (rdma->blockmap) {

        g_hash_table_remove(rdma->blockmap, (void *)(uintptr_t)block->offset);

    }

    if (block->pmr) {

        int j;



        for (j = 0; j < block->nb_chunks; j++) {

            if (!block->pmr[j]) {

                continue;

            }

            ibv_dereg_mr(block->pmr[j]);

            rdma->total_registrations--;

        }

        g_free(block->pmr);

        block->pmr = NULL;

    }



    if (block->mr) {

        ibv_dereg_mr(block->mr);

        rdma->total_registrations--;

        block->mr = NULL;

    }



    g_free(block->transit_bitmap);

    block->transit_bitmap = NULL;



    g_free(block->unregister_bitmap);

    block->unregister_bitmap = NULL;



    g_free(block->remote_keys);

    block->remote_keys = NULL;



    g_free(block->block_name);

    block->block_name = NULL;



    if (rdma->blockmap) {

        for (x = 0; x < local->nb_blocks; x++) {

            g_hash_table_remove(rdma->blockmap,

                                (void *)(uintptr_t)old[x].offset);

        }

    }



    if (local->nb_blocks > 1) {



        local->block = g_malloc0(sizeof(RDMALocalBlock) *

                                    (local->nb_blocks - 1));



        if (block->index) {

            memcpy(local->block, old, sizeof(RDMALocalBlock) * block->index);

        }



        if (block->index < (local->nb_blocks - 1)) {

            memcpy(local->block + block->index, old + (block->index + 1),

                sizeof(RDMALocalBlock) *

                    (local->nb_blocks - (block->index + 1)));

        }

    } else {

        assert(block == local->block);

        local->block = NULL;

    }



    trace_rdma_delete_block(block, (uintptr_t)block->local_host_addr,

                           block->offset, block->length,

                            (uintptr_t)(block->local_host_addr + block->length),

                           BITS_TO_LONGS(block->nb_chunks) *

                               sizeof(unsigned long) * 8, block->nb_chunks);



    g_free(old);



    local->nb_blocks--;



    if (local->nb_blocks && rdma->blockmap) {

        for (x = 0; x < local->nb_blocks; x++) {

            g_hash_table_insert(rdma->blockmap,

                                (void *)(uintptr_t)local->block[x].offset,

                                &local->block[x]);

        }

    }



    return 0;

}

static int rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block)

{

    RDMALocalBlocks *local = &rdma->local_ram_blocks;

    RDMALocalBlock *old = local->block;

    int x;



    if (rdma->blockmap) {

        g_hash_table_remove(rdma->blockmap, (void *)(uintptr_t)block->offset);

    }

    if (block->pmr) {

        int j;



        for (j = 0; j < block->nb_chunks; j++) {

            if (!block->pmr[j]) {

                continue;

            }

            ibv_dereg_mr(block->pmr[j]);

            rdma->total_registrations--;

        }

        g_free(block->pmr);

        block->pmr = NULL;

    }



    if (block->mr) {

        ibv_dereg_mr(block->mr);

        rdma->total_registrations--;

        block->mr = NULL;

    }



    g_free(block->transit_bitmap);

    block->transit_bitmap = NULL;



    g_free(block->unregister_bitmap);

    block->unregister_bitmap = NULL;



    g_free(block->remote_keys);

    block->remote_keys = NULL;



    g_free(block->block_name);

    block->block_name = NULL;



    if (rdma->blockmap) {

        for (x = 0; x < local->nb_blocks; x++) {

            g_hash_table_remove(rdma->blockmap,

                                (void *)(uintptr_t)old[x].offset);

        }

    }



    if (local->nb_blocks > 1) {



        local->block = g_malloc0(sizeof(RDMALocalBlock) *

                                    (local->nb_blocks - 1));



        if (block->index) {

            memcpy(local->block, old, sizeof(RDMALocalBlock) * block->index);

        }



        if (block->index < (local->nb_blocks - 1)) {

            memcpy(local->block + block->index, old + (block->index + 1),

                sizeof(RDMALocalBlock) *

                    (local->nb_blocks - (block->index + 1)));

        }

    } else {

        assert(block == local->block);

        local->block = NULL;

    }



    trace_rdma_delete_block(block, (uintptr_t)block->local_host_addr,

                           block->offset, block->length,

                            (uintptr_t)(block->local_host_addr + block->length),

                           BITS_TO_LONGS(block->nb_chunks) *

                               sizeof(unsigned long) * 8, block->nb_chunks);



    g_free(old);



    local->nb_blocks--;



    if (local->nb_blocks && rdma->blockmap) {

        for (x = 0; x < local->nb_blocks; x++) {

            g_hash_table_insert(rdma->blockmap,

                                (void *)(uintptr_t)local->block[x].offset,

                                &local->block[x]);

        }

    }



    return 0;

}

        local->block = g_malloc0(sizeof(RDMALocalBlock) *                                     (local->nb_blocks - 1));
static int FUNC_0(RDMAContext *VAR_0, RDMALocalBlock *VAR_1)

{

    RDMALocalBlocks *local = &VAR_0->local_ram_blocks;

    RDMALocalBlock *old = local->VAR_1;

    int VAR_2;



    if (VAR_0->blockmap) {

        g_hash_table_remove(VAR_0->blockmap, (void *)(uintptr_t)VAR_1->offset);

    }

    if (VAR_1->pmr) {

        int VAR_3;



        for (VAR_3 = 0; VAR_3 < VAR_1->nb_chunks; VAR_3++) {

            if (!VAR_1->pmr[VAR_3]) {

                continue;

            }

            ibv_dereg_mr(VAR_1->pmr[VAR_3]);

            VAR_0->total_registrations--;

        }

        g_free(VAR_1->pmr);

        VAR_1->pmr = NULL;

    }



    if (VAR_1->mr) {

        ibv_dereg_mr(VAR_1->mr);

        VAR_0->total_registrations--;

        VAR_1->mr = NULL;

    }



    g_free(VAR_1->transit_bitmap);

    VAR_1->transit_bitmap = NULL;



    g_free(VAR_1->unregister_bitmap);

    VAR_1->unregister_bitmap = NULL;



    g_free(VAR_1->remote_keys);

    VAR_1->remote_keys = NULL;



    g_free(VAR_1->block_name);

    VAR_1->block_name = NULL;



    if (VAR_0->blockmap) {

        for (VAR_2 = 0; VAR_2 < local->nb_blocks; VAR_2++) {

            g_hash_table_remove(VAR_0->blockmap,

                                (void *)(uintptr_t)old[VAR_2].offset);

        }

    }



    if (local->nb_blocks > 1) {



        local->VAR_1 = g_malloc0(sizeof(RDMALocalBlock) *

                                    (local->nb_blocks - 1));



        if (VAR_1->index) {

            memcpy(local->VAR_1, old, sizeof(RDMALocalBlock) * VAR_1->index);

        }



        if (VAR_1->index < (local->nb_blocks - 1)) {

            memcpy(local->VAR_1 + VAR_1->index, old + (VAR_1->index + 1),

                sizeof(RDMALocalBlock) *

                    (local->nb_blocks - (VAR_1->index + 1)));

        }

    } else {

        assert(VAR_1 == local->VAR_1);

        local->VAR_1 = NULL;

    }



    trace_rdma_delete_block(VAR_1, (uintptr_t)VAR_1->local_host_addr,

                           VAR_1->offset, VAR_1->length,

                            (uintptr_t)(VAR_1->local_host_addr + VAR_1->length),

                           BITS_TO_LONGS(VAR_1->nb_chunks) *

                               sizeof(unsigned long) * 8, VAR_1->nb_chunks);



    g_free(old);



    local->nb_blocks--;



    if (local->nb_blocks && VAR_0->blockmap) {

        for (VAR_2 = 0; VAR_2 < local->nb_blocks; VAR_2++) {

            g_hash_table_insert(VAR_0->blockmap,

                                (void *)(uintptr_t)local->VAR_1[VAR_2].offset,

                                &local->VAR_1[VAR_2]);

        }

    }



    return 0;

}

static int FUNC_0(RDMAContext *VAR_0, RDMALocalBlock *VAR_1)
{ RDMALocalBlocks *local = &VAR_0->local_ram_blocks; RDMALocalBlock *old = local->VAR_1; int VAR_2; if (VAR_0->blockmap) { g_hash_table_remove(VAR_0->blockmap, (void *)(uintptr_t)VAR_1->offset); } if (VAR_1->pmr) { int VAR_3; for (VAR_3 = 0; VAR_3 < VAR_1->nb_chunks; VAR_3++) { if (!VAR_1->pmr[VAR_3]) { continue; } ibv_dereg_mr(VAR_1->pmr[VAR_3]); VAR_0->total_registrations--; } g_free(VAR_1->pmr); VAR_1->pmr = NULL; } if (VAR_1->mr) { ibv_dereg_mr(VAR_1->mr); VAR_0->total_registrations--; VAR_1->mr = NULL; } g_free(VAR_1->transit_bitmap); VAR_1->transit_bitmap = NULL; g_free(VAR_1->unregister_bitmap); VAR_1->unregister_bitmap = NULL; g_free(VAR_1->remote_keys); VAR_1->remote_keys = NULL; g_free(VAR_1->block_name); VAR_1->block_name = NULL; if (VAR_0->blockmap) { for (VAR_2 = 0; VAR_2 < local->nb_blocks; VAR_2++) { g_hash_table_remove(VAR_0->blockmap,
(void *)(uintptr_t)old[VAR_2].offset); } } if (local->nb_blocks > 1) { local->VAR_1 = g_malloc0(sizeof(RDMALocalBlock) *
(local->nb_blocks - 1)); if (VAR_1->index) { memcpy(local->VAR_1, old, sizeof(RDMALocalBlock) * VAR_1->index); } if (VAR_1->index < (local->nb_blocks - 1)) { memcpy(local->VAR_1 + VAR_1->index, old + (VAR_1->index + 1),
sizeof(RDMALocalBlock) *
(local->nb_blocks - (VAR_1->index + 1))); } } else { assert(VAR_1 == local->VAR_1); local->VAR_1 = NULL; } trace_rdma_delete_block(VAR_1, (uintptr_t)VAR_1->local_host_addr,
VAR_1->offset, VAR_1->length,
(uintptr_t)(VAR_1->local_host_addr + VAR_1->length),
BITS_TO_LONGS(VAR_1->nb_chunks) *
sizeof(unsigned long) * 8, VAR_1->nb_chunks); g_free(old); local->nb_blocks--; if (local->nb_blocks && VAR_0->blockmap) { for (VAR_2 = 0; VAR_2 < local->nb_blocks; VAR_2++) { g_hash_table_insert(VAR_0->blockmap,
(void *)(uintptr_t)local->VAR_1[VAR_2].offset,
&local->VAR_1[VAR_2]); } } return 0; }