int xics_alloc(XICSState *icp, int src, int irq_hint, bool lsi)

{

    ICSState *ics = &icp->ics[src];

    int irq;



    if (irq_hint) {

        assert(src == xics_find_source(icp, irq_hint));

        if (!ICS_IRQ_FREE(ics, irq_hint - ics->offset)) {

            trace_xics_alloc_failed_hint(src, irq_hint);

            return -1;

        }

        irq = irq_hint;

    } else {

        irq = ics_find_free_block(ics, 1, 1);

        if (irq < 0) {

            trace_xics_alloc_failed_no_left(src);

            return -1;

        }

        irq += ics->offset;

    }



    ics_set_irq_type(ics, irq - ics->offset, lsi);

    trace_xics_alloc(src, irq);



    return irq;

}

int xics_alloc(XICSState *icp, int src, int irq_hint, bool lsi)

{

    ICSState *ics = &icp->ics[src];

    int irq;



    if (irq_hint) {

        assert(src == xics_find_source(icp, irq_hint));

        if (!ICS_IRQ_FREE(ics, irq_hint - ics->offset)) {

            trace_xics_alloc_failed_hint(src, irq_hint);

            return -1;

        }

        irq = irq_hint;

    } else {

        irq = ics_find_free_block(ics, 1, 1);

        if (irq < 0) {

            trace_xics_alloc_failed_no_left(src);

            return -1;

        }

        irq += ics->offset;

    }



    ics_set_irq_type(ics, irq - ics->offset, lsi);

    trace_xics_alloc(src, irq);



    return irq;

}

int xics_alloc(XICSState *icp, int src, int irq_hint, bool lsi)             trace_xics_alloc_failed_hint(src, irq_hint);             trace_xics_alloc_failed_no_left(src);
int FUNC_0(XICSState *VAR_0, int VAR_1, int VAR_2, bool VAR_3)

{

    ICSState *ics = &VAR_0->ics[VAR_1];

    int VAR_4;



    if (VAR_2) {

        assert(VAR_1 == xics_find_source(VAR_0, VAR_2));

        if (!ICS_IRQ_FREE(ics, VAR_2 - ics->offset)) {

            trace_xics_alloc_failed_hint(VAR_1, VAR_2);

            return -1;

        }

        VAR_4 = VAR_2;

    } else {

        VAR_4 = ics_find_free_block(ics, 1, 1);

        if (VAR_4 < 0) {

            trace_xics_alloc_failed_no_left(VAR_1);

            return -1;

        }

        VAR_4 += ics->offset;

    }



    ics_set_irq_type(ics, VAR_4 - ics->offset, VAR_3);

    trace_xics_alloc(VAR_1, VAR_4);



    return VAR_4;

}

int FUNC_0(XICSState *VAR_0, int VAR_1, int VAR_2, bool VAR_3)
{ ICSState *ics = &VAR_0->ics[VAR_1]; int VAR_4; if (VAR_2) { assert(VAR_1 == xics_find_source(VAR_0, VAR_2)); if (!ICS_IRQ_FREE(ics, VAR_2 - ics->offset)) { trace_xics_alloc_failed_hint(VAR_1, VAR_2); return -1; } VAR_4 = VAR_2; } else { VAR_4 = ics_find_free_block(ics, 1, 1); if (VAR_4 < 0) { trace_xics_alloc_failed_no_left(VAR_1); return -1; } VAR_4 += ics->offset; } ics_set_irq_type(ics, VAR_4 - ics->offset, VAR_3); trace_xics_alloc(VAR_1, VAR_4); return VAR_4; }