static void sdp_service_record_build(struct sdp_service_record_s *record,

                struct sdp_def_service_s *def, int handle)

{

    int len = 0;

    uint8_t *data;

    int *uuid;



    record->uuids = 0;

    while (def->attributes[record->attributes].data.type) {

        len += 3;

        len += sdp_attr_max_size(&def->attributes[record->attributes ++].data,

                        &record->uuids);

    }

    record->uuids = pow2ceil(record->uuids);

    record->attribute_list =

            g_malloc0(record->attributes * sizeof(*record->attribute_list));

    record->uuid =

            g_malloc0(record->uuids * sizeof(*record->uuid));

    data = g_malloc(len);



    record->attributes = 0;

    uuid = record->uuid;

    while (def->attributes[record->attributes].data.type) {

        record->attribute_list[record->attributes].pair = data;



        len = 0;

        data[len ++] = SDP_DTYPE_UINT | SDP_DSIZE_2;

        data[len ++] = def->attributes[record->attributes].id >> 8;

        data[len ++] = def->attributes[record->attributes].id & 0xff;

        len += sdp_attr_write(data + len,

                        &def->attributes[record->attributes].data, &uuid);



        /* Special case: assign a ServiceRecordHandle in sequence */

        if (def->attributes[record->attributes].id == SDP_ATTR_RECORD_HANDLE)

            def->attributes[record->attributes].data.value.uint = handle;

        /* Note: we could also assign a ServiceDescription based on

         * sdp->device.device->lmp_name.  */



        record->attribute_list[record->attributes ++].len = len;

        data += len;

    }



    /* Sort the attribute list by the AttributeID */

    qsort(record->attribute_list, record->attributes,

                    sizeof(*record->attribute_list),

                    (void *) sdp_attributeid_compare);

    /* Sort the searchable UUIDs list for bisection */

    qsort(record->uuid, record->uuids,

                    sizeof(*record->uuid),

                    (void *) sdp_uuid_compare);

}

static void sdp_service_record_build(struct sdp_service_record_s *record,

                struct sdp_def_service_s *def, int handle)

{

    int len = 0;

    uint8_t *data;

    int *uuid;



    record->uuids = 0;

    while (def->attributes[record->attributes].data.type) {

        len += 3;

        len += sdp_attr_max_size(&def->attributes[record->attributes ++].data,

                        &record->uuids);

    }

    record->uuids = pow2ceil(record->uuids);

    record->attribute_list =

            g_malloc0(record->attributes * sizeof(*record->attribute_list));

    record->uuid =

            g_malloc0(record->uuids * sizeof(*record->uuid));

    data = g_malloc(len);



    record->attributes = 0;

    uuid = record->uuid;

    while (def->attributes[record->attributes].data.type) {

        record->attribute_list[record->attributes].pair = data;



        len = 0;

        data[len ++] = SDP_DTYPE_UINT | SDP_DSIZE_2;

        data[len ++] = def->attributes[record->attributes].id >> 8;

        data[len ++] = def->attributes[record->attributes].id & 0xff;

        len += sdp_attr_write(data + len,

                        &def->attributes[record->attributes].data, &uuid);



        

        if (def->attributes[record->attributes].id == SDP_ATTR_RECORD_HANDLE)

            def->attributes[record->attributes].data.value.uint = handle;

        





        record->attribute_list[record->attributes ++].len = len;

        data += len;

    }



    

    qsort(record->attribute_list, record->attributes,

                    sizeof(*record->attribute_list),

                    (void *) sdp_attributeid_compare);

    

    qsort(record->uuid, record->uuids,

                    sizeof(*record->uuid),

                    (void *) sdp_uuid_compare);

}

        data[len ++] = def->attributes[record->attributes].id >> 8;         data[len ++] = def->attributes[record->attributes].id & 0xff;
static void FUNC_0(struct sdp_service_record_s *VAR_0,

                struct sdp_def_service_s *VAR_1, int VAR_2)

{

    int VAR_3 = 0;

    uint8_t *data;

    int *VAR_4;



    VAR_0->uuids = 0;

    while (VAR_1->attributes[VAR_0->attributes].data.type) {

        VAR_3 += 3;

        VAR_3 += sdp_attr_max_size(&VAR_1->attributes[VAR_0->attributes ++].data,

                        &VAR_0->uuids);

    }

    VAR_0->uuids = pow2ceil(VAR_0->uuids);

    VAR_0->attribute_list =

            g_malloc0(VAR_0->attributes * sizeof(*VAR_0->attribute_list));

    VAR_0->VAR_4 =

            g_malloc0(VAR_0->uuids * sizeof(*VAR_0->VAR_4));

    data = g_malloc(VAR_3);



    VAR_0->attributes = 0;

    VAR_4 = VAR_0->VAR_4;

    while (VAR_1->attributes[VAR_0->attributes].data.type) {

        VAR_0->attribute_list[VAR_0->attributes].pair = data;



        VAR_3 = 0;

        data[VAR_3 ++] = SDP_DTYPE_UINT | SDP_DSIZE_2;

        data[VAR_3 ++] = VAR_1->attributes[VAR_0->attributes].id >> 8;

        data[VAR_3 ++] = VAR_1->attributes[VAR_0->attributes].id & 0xff;

        VAR_3 += sdp_attr_write(data + VAR_3,

                        &VAR_1->attributes[VAR_0->attributes].data, &VAR_4);



        

        if (VAR_1->attributes[VAR_0->attributes].id == SDP_ATTR_RECORD_HANDLE)

            VAR_1->attributes[VAR_0->attributes].data.value.uint = VAR_2;

        





        VAR_0->attribute_list[VAR_0->attributes ++].VAR_3 = VAR_3;

        data += VAR_3;

    }



    

    qsort(VAR_0->attribute_list, VAR_0->attributes,

                    sizeof(*VAR_0->attribute_list),

                    (void *) sdp_attributeid_compare);

    

    qsort(VAR_0->VAR_4, VAR_0->uuids,

                    sizeof(*VAR_0->VAR_4),

                    (void *) sdp_uuid_compare);

}

static void FUNC_0(struct sdp_service_record_s *VAR_0,
struct sdp_def_service_s *VAR_1, int VAR_2)
{ int VAR_3 = 0; uint8_t *data; int *VAR_4; VAR_0->uuids = 0; while (VAR_1->attributes[VAR_0->attributes].data.type) { VAR_3 += 3; VAR_3 += sdp_attr_max_size(&VAR_1->attributes[VAR_0->attributes ++].data,
&VAR_0->uuids); } VAR_0->uuids = pow2ceil(VAR_0->uuids); VAR_0->attribute_list =
g_malloc0(VAR_0->attributes * sizeof(*VAR_0->attribute_list)); VAR_0->VAR_4 =
g_malloc0(VAR_0->uuids * sizeof(*VAR_0->VAR_4)); data = g_malloc(VAR_3); VAR_0->attributes = 0; VAR_4 = VAR_0->VAR_4; while (VAR_1->attributes[VAR_0->attributes].data.type) { VAR_0->attribute_list[VAR_0->attributes].pair = data; VAR_3 = 0; data[VAR_3 ++] = SDP_DTYPE_UINT | SDP_DSIZE_2; data[VAR_3 ++] = VAR_1->attributes[VAR_0->attributes].id >> 8; data[VAR_3 ++] = VAR_1->attributes[VAR_0->attributes].id & 0xff; VAR_3 += sdp_attr_write(data + VAR_3,
&VAR_1->attributes[VAR_0->attributes].data, &VAR_4); if (VAR_1->attributes[VAR_0->attributes].id == SDP_ATTR_RECORD_HANDLE)
VAR_1->attributes[VAR_0->attributes].data.value.uint = VAR_2; VAR_0->attribute_list[VAR_0->attributes ++].VAR_3 = VAR_3; data += VAR_3; } qsort(VAR_0->attribute_list, VAR_0->attributes,
sizeof(*VAR_0->attribute_list),
(void *) sdp_attributeid_compare); qsort(VAR_0->VAR_4, VAR_0->uuids,
sizeof(*VAR_0->VAR_4),
(void *) sdp_uuid_compare); }