int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)

{

    void *fdt, *fdt_skel;

    sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };



    size -= sizeof(hdr);



    /* Create sceleton */

    fdt_skel = g_malloc0(size);

    _FDT((fdt_create(fdt_skel, size)));

    _FDT((fdt_begin_node(fdt_skel, "")));

    _FDT((fdt_end_node(fdt_skel)));

    _FDT((fdt_finish(fdt_skel)));

    fdt = g_malloc0(size);

    _FDT((fdt_open_into(fdt_skel, fdt, size)));

    g_free(fdt_skel);



    /* Place to make changes to the tree */



    /* Pack resulting tree */

    _FDT((fdt_pack(fdt)));



    if (fdt_totalsize(fdt) + sizeof(hdr) > size) {

        trace_spapr_cas_failed(size);

        return -1;

    }



    cpu_physical_memory_write(addr, &hdr, sizeof(hdr));

    cpu_physical_memory_write(addr + sizeof(hdr), fdt, fdt_totalsize(fdt));

    trace_spapr_cas_continue(fdt_totalsize(fdt) + sizeof(hdr));

    g_free(fdt);



    return 0;

}

int spapr_h_cas_compose_response(target_ulong addr, target_ulong size)

{

    void *fdt, *fdt_skel;

    sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };



    size -= sizeof(hdr);



    

    fdt_skel = g_malloc0(size);

    _FDT((fdt_create(fdt_skel, size)));

    _FDT((fdt_begin_node(fdt_skel, "")));

    _FDT((fdt_end_node(fdt_skel)));

    _FDT((fdt_finish(fdt_skel)));

    fdt = g_malloc0(size);

    _FDT((fdt_open_into(fdt_skel, fdt, size)));

    g_free(fdt_skel);



    



    

    _FDT((fdt_pack(fdt)));



    if (fdt_totalsize(fdt) + sizeof(hdr) > size) {

        trace_spapr_cas_failed(size);

        return -1;

    }



    cpu_physical_memory_write(addr, &hdr, sizeof(hdr));

    cpu_physical_memory_write(addr + sizeof(hdr), fdt, fdt_totalsize(fdt));

    trace_spapr_cas_continue(fdt_totalsize(fdt) + sizeof(hdr));

    g_free(fdt);



    return 0;

}

int FUNC_0(target_ulong VAR_0, target_ulong VAR_1)

{

    void *VAR_2, *VAR_3;

    sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };



    VAR_1 -= sizeof(hdr);



    

    VAR_3 = g_malloc0(VAR_1);

    _FDT((fdt_create(VAR_3, VAR_1)));

    _FDT((fdt_begin_node(VAR_3, "")));

    _FDT((fdt_end_node(VAR_3)));

    _FDT((fdt_finish(VAR_3)));

    VAR_2 = g_malloc0(VAR_1);

    _FDT((fdt_open_into(VAR_3, VAR_2, VAR_1)));

    g_free(VAR_3);



    



    

    _FDT((fdt_pack(VAR_2)));



    if (fdt_totalsize(VAR_2) + sizeof(hdr) > VAR_1) {

        trace_spapr_cas_failed(VAR_1);

        return -1;

    }



    cpu_physical_memory_write(VAR_0, &hdr, sizeof(hdr));

    cpu_physical_memory_write(VAR_0 + sizeof(hdr), VAR_2, fdt_totalsize(VAR_2));

    trace_spapr_cas_continue(fdt_totalsize(VAR_2) + sizeof(hdr));

    g_free(VAR_2);



    return 0;

}

int FUNC_0(target_ulong VAR_0, target_ulong VAR_1)
{ void *VAR_2, *VAR_3; sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 }; VAR_1 -= sizeof(hdr); VAR_3 = g_malloc0(VAR_1); _FDT((fdt_create(VAR_3, VAR_1))); _FDT((fdt_begin_node(VAR_3, ""))); _FDT((fdt_end_node(VAR_3))); _FDT((fdt_finish(VAR_3))); VAR_2 = g_malloc0(VAR_1); _FDT((fdt_open_into(VAR_3, VAR_2, VAR_1))); g_free(VAR_3); _FDT((fdt_pack(VAR_2))); if (fdt_totalsize(VAR_2) + sizeof(hdr) > VAR_1) { trace_spapr_cas_failed(VAR_1); return -1; } cpu_physical_memory_write(VAR_0, &hdr, sizeof(hdr)); cpu_physical_memory_write(VAR_0 + sizeof(hdr), VAR_2, fdt_totalsize(VAR_2)); trace_spapr_cas_continue(fdt_totalsize(VAR_2) + sizeof(hdr)); g_free(VAR_2); return 0; }