static void phys_page_set_level(PhysPageEntry *lp, target_phys_addr_t *index,

                                target_phys_addr_t *nb, uint16_t leaf,

                                int level)

{

    PhysPageEntry *p;

    int i;

    target_phys_addr_t step = (target_phys_addr_t)1 << (level * L2_BITS);



    if (!lp->is_leaf && lp->ptr == PHYS_MAP_NODE_NIL) {

        lp->ptr = phys_map_node_alloc();

        p = phys_map_nodes[lp->ptr];

        if (level == 0) {

            for (i = 0; i < L2_SIZE; i++) {

                p[i].is_leaf = 1;

                p[i].ptr = phys_section_unassigned;

            }

        }

    } else {

        p = phys_map_nodes[lp->ptr];

    }

    lp = &p[(*index >> (level * L2_BITS)) & (L2_SIZE - 1)];



    while (*nb && lp < &p[L2_SIZE]) {

        if ((*index & (step - 1)) == 0 && *nb >= step) {

            lp->is_leaf = true;

            lp->ptr = leaf;

            *index += step;

            *nb -= step;

        } else {

            phys_page_set_level(lp, index, nb, leaf, level - 1);

        }

        ++lp;

    }

}

static void phys_page_set_level(PhysPageEntry *lp, target_phys_addr_t *index,

                                target_phys_addr_t *nb, uint16_t leaf,

                                int level)

{

    PhysPageEntry *p;

    int i;

    target_phys_addr_t step = (target_phys_addr_t)1 << (level * L2_BITS);



    if (!lp->is_leaf && lp->ptr == PHYS_MAP_NODE_NIL) {

        lp->ptr = phys_map_node_alloc();

        p = phys_map_nodes[lp->ptr];

        if (level == 0) {

            for (i = 0; i < L2_SIZE; i++) {

                p[i].is_leaf = 1;

                p[i].ptr = phys_section_unassigned;

            }

        }

    } else {

        p = phys_map_nodes[lp->ptr];

    }

    lp = &p[(*index >> (level * L2_BITS)) & (L2_SIZE - 1)];



    while (*nb && lp < &p[L2_SIZE]) {

        if ((*index & (step - 1)) == 0 && *nb >= step) {

            lp->is_leaf = true;

            lp->ptr = leaf;

            *index += step;

            *nb -= step;

        } else {

            phys_page_set_level(lp, index, nb, leaf, level - 1);

        }

        ++lp;

    }

}

static void FUNC_0(PhysPageEntry *VAR_0, target_phys_addr_t *VAR_1,

                                target_phys_addr_t *VAR_2, uint16_t VAR_3,

                                int VAR_4)

{

    PhysPageEntry *p;

    int VAR_5;

    target_phys_addr_t step = (target_phys_addr_t)1 << (VAR_4 * L2_BITS);



    if (!VAR_0->is_leaf && VAR_0->ptr == PHYS_MAP_NODE_NIL) {

        VAR_0->ptr = phys_map_node_alloc();

        p = phys_map_nodes[VAR_0->ptr];

        if (VAR_4 == 0) {

            for (VAR_5 = 0; VAR_5 < L2_SIZE; VAR_5++) {

                p[VAR_5].is_leaf = 1;

                p[VAR_5].ptr = phys_section_unassigned;

            }

        }

    } else {

        p = phys_map_nodes[VAR_0->ptr];

    }

    VAR_0 = &p[(*VAR_1 >> (VAR_4 * L2_BITS)) & (L2_SIZE - 1)];



    while (*VAR_2 && VAR_0 < &p[L2_SIZE]) {

        if ((*VAR_1 & (step - 1)) == 0 && *VAR_2 >= step) {

            VAR_0->is_leaf = true;

            VAR_0->ptr = VAR_3;

            *VAR_1 += step;

            *VAR_2 -= step;

        } else {

            FUNC_0(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4 - 1);

        }

        ++VAR_0;

    }

}

static void FUNC_0(PhysPageEntry *VAR_0, target_phys_addr_t *VAR_1,
target_phys_addr_t *VAR_2, uint16_t VAR_3,
int VAR_4)
{ PhysPageEntry *p; int VAR_5; target_phys_addr_t step = (target_phys_addr_t)1 << (VAR_4 * L2_BITS); if (!VAR_0->is_leaf && VAR_0->ptr == PHYS_MAP_NODE_NIL) { VAR_0->ptr = phys_map_node_alloc(); p = phys_map_nodes[VAR_0->ptr]; if (VAR_4 == 0) { for (VAR_5 = 0; VAR_5 < L2_SIZE; VAR_5++) { p[VAR_5].is_leaf = 1; p[VAR_5].ptr = phys_section_unassigned; } } } else { p = phys_map_nodes[VAR_0->ptr]; } VAR_0 = &p[(*VAR_1 >> (VAR_4 * L2_BITS)) & (L2_SIZE - 1)]; while (*VAR_2 && VAR_0 < &p[L2_SIZE]) { if ((*VAR_1 & (step - 1)) == 0 && *VAR_2 >= step) { VAR_0->is_leaf = true; VAR_0->ptr = VAR_3; *VAR_1 += step; *VAR_2 -= step; } else { FUNC_0(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4 - 1); } ++VAR_0; } }