static void to_json(const QObject *obj, QString *str, int pretty, int indent)

{

    switch (qobject_type(obj)) {

    case QTYPE_QINT: {

        QInt *val = qobject_to_qint(obj);

        char buffer[1024];



        snprintf(buffer, sizeof(buffer), "%" PRId64, qint_get_int(val));

        qstring_append(str, buffer);

        break;

    }

    case QTYPE_QSTRING: {

        QString *val = qobject_to_qstring(obj);

        const char *ptr;



        ptr = qstring_get_str(val);

        qstring_append(str, "\"");

        while (*ptr) {

            if ((ptr[0] & 0xE0) == 0xE0 &&

                (ptr[1] & 0x80) && (ptr[2] & 0x80)) {

                uint16_t wchar;

                char escape[7];



                wchar  = (ptr[0] & 0x0F) << 12;

                wchar |= (ptr[1] & 0x3F) << 6;

                wchar |= (ptr[2] & 0x3F);

                ptr += 2;



                snprintf(escape, sizeof(escape), "\\u%04X", wchar);

                qstring_append(str, escape);

            } else if ((ptr[0] & 0xE0) == 0xC0 && (ptr[1] & 0x80)) {

                uint16_t wchar;

                char escape[7];



                wchar  = (ptr[0] & 0x1F) << 6;

                wchar |= (ptr[1] & 0x3F);

                ptr++;



                snprintf(escape, sizeof(escape), "\\u%04X", wchar);

                qstring_append(str, escape);

            } else switch (ptr[0]) {

                case '\"':

                    qstring_append(str, "\\\"");

                    break;

                case '\\':

                    qstring_append(str, "\\\\");

                    break;

                case '\b':

                    qstring_append(str, "\\b");

                    break;

                case '\f':

                    qstring_append(str, "\\f");

                    break;

                case '\n':

                    qstring_append(str, "\\n");

                    break;

                case '\r':

                    qstring_append(str, "\\r");

                    break;

                case '\t':

                    qstring_append(str, "\\t");

                    break;

                default: {

                    if (ptr[0] <= 0x1F) {

                        char escape[7];

                        snprintf(escape, sizeof(escape), "\\u%04X", ptr[0]);

                        qstring_append(str, escape);

                    } else {

                        char buf[2] = { ptr[0], 0 };

                        qstring_append(str, buf);

                    }

                    break;

                }

                }

            ptr++;

        }

        qstring_append(str, "\"");

        break;

    }

    case QTYPE_QDICT: {

        ToJsonIterState s;

        QDict *val = qobject_to_qdict(obj);



        s.count = 0;

        s.str = str;

        s.indent = indent + 1;

        s.pretty = pretty;

        qstring_append(str, "{");

        qdict_iter(val, to_json_dict_iter, &s);

        if (pretty) {

            int j;

            qstring_append(str, "\n");

            for (j = 0 ; j < indent ; j++)

                qstring_append(str, "    ");

        }

        qstring_append(str, "}");

        break;

    }

    case QTYPE_QLIST: {

        ToJsonIterState s;

        QList *val = qobject_to_qlist(obj);



        s.count = 0;

        s.str = str;

        s.indent = indent + 1;

        s.pretty = pretty;

        qstring_append(str, "[");

        qlist_iter(val, (void *)to_json_list_iter, &s);

        if (pretty) {

            int j;

            qstring_append(str, "\n");

            for (j = 0 ; j < indent ; j++)

                qstring_append(str, "    ");

        }

        qstring_append(str, "]");

        break;

    }

    case QTYPE_QFLOAT: {

        QFloat *val = qobject_to_qfloat(obj);

        char buffer[1024];

        int len;



        len = snprintf(buffer, sizeof(buffer), "%f", qfloat_get_double(val));

        while (len > 0 && buffer[len - 1] == '0') {

            len--;

        }



        if (len && buffer[len - 1] == '.') {

            buffer[len - 1] = 0;

        } else {

            buffer[len] = 0;

        }

        

        qstring_append(str, buffer);

        break;

    }

    case QTYPE_QBOOL: {

        QBool *val = qobject_to_qbool(obj);



        if (qbool_get_int(val)) {

            qstring_append(str, "true");

        } else {

            qstring_append(str, "false");

        }

        break;

    }

    case QTYPE_QERROR:

        /* XXX: should QError be emitted? */

    case QTYPE_NONE:

        break;

    }

}

static void to_json(const QObject *obj, QString *str, int pretty, int indent)

{

    switch (qobject_type(obj)) {

    case QTYPE_QINT: {

        QInt *val = qobject_to_qint(obj);

        char buffer[1024];



        snprintf(buffer, sizeof(buffer), "%" PRId64, qint_get_int(val));

        qstring_append(str, buffer);

        break;

    }

    case QTYPE_QSTRING: {

        QString *val = qobject_to_qstring(obj);

        const char *ptr;



        ptr = qstring_get_str(val);

        qstring_append(str, "\"");

        while (*ptr) {

            if ((ptr[0] & 0xE0) == 0xE0 &&

                (ptr[1] & 0x80) && (ptr[2] & 0x80)) {

                uint16_t wchar;

                char escape[7];



                wchar  = (ptr[0] & 0x0F) << 12;

                wchar |= (ptr[1] & 0x3F) << 6;

                wchar |= (ptr[2] & 0x3F);

                ptr += 2;



                snprintf(escape, sizeof(escape), "\\u%04X", wchar);

                qstring_append(str, escape);

            } else if ((ptr[0] & 0xE0) == 0xC0 && (ptr[1] & 0x80)) {

                uint16_t wchar;

                char escape[7];



                wchar  = (ptr[0] & 0x1F) << 6;

                wchar |= (ptr[1] & 0x3F);

                ptr++;



                snprintf(escape, sizeof(escape), "\\u%04X", wchar);

                qstring_append(str, escape);

            } else switch (ptr[0]) {

                case '\"':

                    qstring_append(str, "\\\"");

                    break;

                case '\\':

                    qstring_append(str, "\\\\");

                    break;

                case '\b':

                    qstring_append(str, "\\b");

                    break;

                case '\f':

                    qstring_append(str, "\\f");

                    break;

                case '\n':

                    qstring_append(str, "\\n");

                    break;

                case '\r':

                    qstring_append(str, "\\r");

                    break;

                case '\t':

                    qstring_append(str, "\\t");

                    break;

                default: {

                    if (ptr[0] <= 0x1F) {

                        char escape[7];

                        snprintf(escape, sizeof(escape), "\\u%04X", ptr[0]);

                        qstring_append(str, escape);

                    } else {

                        char buf[2] = { ptr[0], 0 };

                        qstring_append(str, buf);

                    }

                    break;

                }

                }

            ptr++;

        }

        qstring_append(str, "\"");

        break;

    }

    case QTYPE_QDICT: {

        ToJsonIterState s;

        QDict *val = qobject_to_qdict(obj);



        s.count = 0;

        s.str = str;

        s.indent = indent + 1;

        s.pretty = pretty;

        qstring_append(str, "{");

        qdict_iter(val, to_json_dict_iter, &s);

        if (pretty) {

            int j;

            qstring_append(str, "\n");

            for (j = 0 ; j < indent ; j++)

                qstring_append(str, "    ");

        }

        qstring_append(str, "}");

        break;

    }

    case QTYPE_QLIST: {

        ToJsonIterState s;

        QList *val = qobject_to_qlist(obj);



        s.count = 0;

        s.str = str;

        s.indent = indent + 1;

        s.pretty = pretty;

        qstring_append(str, "[");

        qlist_iter(val, (void *)to_json_list_iter, &s);

        if (pretty) {

            int j;

            qstring_append(str, "\n");

            for (j = 0 ; j < indent ; j++)

                qstring_append(str, "    ");

        }

        qstring_append(str, "]");

        break;

    }

    case QTYPE_QFLOAT: {

        QFloat *val = qobject_to_qfloat(obj);

        char buffer[1024];

        int len;



        len = snprintf(buffer, sizeof(buffer), "%f", qfloat_get_double(val));

        while (len > 0 && buffer[len - 1] == '0') {

            len--;

        }



        if (len && buffer[len - 1] == '.') {

            buffer[len - 1] = 0;

        } else {

            buffer[len] = 0;

        }

        

        qstring_append(str, buffer);

        break;

    }

    case QTYPE_QBOOL: {

        QBool *val = qobject_to_qbool(obj);



        if (qbool_get_int(val)) {

            qstring_append(str, "true");

        } else {

            qstring_append(str, "false");

        }

        break;

    }

    case QTYPE_QERROR:

        

    case QTYPE_NONE:

        break;

    }

}

static void FUNC_0(const QObject *VAR_0, QString *VAR_1, int VAR_2, int VAR_3)

{

    switch (qobject_type(VAR_0)) {

    case QTYPE_QINT: {

        QInt *val = qobject_to_qint(VAR_0);

        char VAR_9[1024];



        snprintf(VAR_9, sizeof(VAR_9), "%" PRId64, qint_get_int(val));

        qstring_append(VAR_1, VAR_9);

        break;

    }

    case QTYPE_QSTRING: {

        QString *val = qobject_to_qstring(VAR_0);

        const char *VAR_5;



        VAR_5 = qstring_get_str(val);

        qstring_append(VAR_1, "\"");

        while (*VAR_5) {

            if ((VAR_5[0] & 0xE0) == 0xE0 &&

                (VAR_5[1] & 0x80) && (VAR_5[2] & 0x80)) {

                uint16_t wchar;

                char VAR_7[7];



                wchar  = (VAR_5[0] & 0x0F) << 12;

                wchar |= (VAR_5[1] & 0x3F) << 6;

                wchar |= (VAR_5[2] & 0x3F);

                VAR_5 += 2;



                snprintf(VAR_7, sizeof(VAR_7), "\\u%04X", wchar);

                qstring_append(VAR_1, VAR_7);

            } else if ((VAR_5[0] & 0xE0) == 0xC0 && (VAR_5[1] & 0x80)) {

                uint16_t wchar;

                char VAR_7[7];



                wchar  = (VAR_5[0] & 0x1F) << 6;

                wchar |= (VAR_5[1] & 0x3F);

                VAR_5++;



                snprintf(VAR_7, sizeof(VAR_7), "\\u%04X", wchar);

                qstring_append(VAR_1, VAR_7);

            } else switch (VAR_5[0]) {

                case '\"':

                    qstring_append(VAR_1, "\\\"");

                    break;

                case '\\':

                    qstring_append(VAR_1, "\\\\");

                    break;

                case '\b':

                    qstring_append(VAR_1, "\\b");

                    break;

                case '\f':

                    qstring_append(VAR_1, "\\f");

                    break;

                case '\n':

                    qstring_append(VAR_1, "\\n");

                    break;

                case '\r':

                    qstring_append(VAR_1, "\\r");

                    break;

                case '\t':

                    qstring_append(VAR_1, "\\t");

                    break;

                default: {

                    if (VAR_5[0] <= 0x1F) {

                        char VAR_7[7];

                        snprintf(VAR_7, sizeof(VAR_7), "\\u%04X", VAR_5[0]);

                        qstring_append(VAR_1, VAR_7);

                    } else {

                        char VAR_7[2] = { VAR_5[0], 0 };

                        qstring_append(VAR_1, VAR_7);

                    }

                    break;

                }

                }

            VAR_5++;

        }

        qstring_append(VAR_1, "\"");

        break;

    }

    case QTYPE_QDICT: {

        ToJsonIterState s;

        QDict *val = qobject_to_qdict(VAR_0);



        s.count = 0;

        s.VAR_1 = VAR_1;

        s.VAR_3 = VAR_3 + 1;

        s.VAR_2 = VAR_2;

        qstring_append(VAR_1, "{");

        qdict_iter(val, to_json_dict_iter, &s);

        if (VAR_2) {

            int VAR_9;

            qstring_append(VAR_1, "\n");

            for (VAR_9 = 0 ; VAR_9 < VAR_3 ; VAR_9++)

                qstring_append(VAR_1, "    ");

        }

        qstring_append(VAR_1, "}");

        break;

    }

    case QTYPE_QLIST: {

        ToJsonIterState s;

        QList *val = qobject_to_qlist(VAR_0);



        s.count = 0;

        s.VAR_1 = VAR_1;

        s.VAR_3 = VAR_3 + 1;

        s.VAR_2 = VAR_2;

        qstring_append(VAR_1, "[");

        qlist_iter(val, (void *)to_json_list_iter, &s);

        if (VAR_2) {

            int VAR_9;

            qstring_append(VAR_1, "\n");

            for (VAR_9 = 0 ; VAR_9 < VAR_3 ; VAR_9++)

                qstring_append(VAR_1, "    ");

        }

        qstring_append(VAR_1, "]");

        break;

    }

    case QTYPE_QFLOAT: {

        QFloat *val = qobject_to_qfloat(VAR_0);

        char VAR_9[1024];

        int VAR_9;



        VAR_9 = snprintf(VAR_9, sizeof(VAR_9), "%f", qfloat_get_double(val));

        while (VAR_9 > 0 && VAR_9[VAR_9 - 1] == '0') {

            VAR_9--;

        }



        if (VAR_9 && VAR_9[VAR_9 - 1] == '.') {

            VAR_9[VAR_9 - 1] = 0;

        } else {

            VAR_9[VAR_9] = 0;

        }

        

        qstring_append(VAR_1, VAR_9);

        break;

    }

    case QTYPE_QBOOL: {

        QBool *val = qobject_to_qbool(VAR_0);



        if (qbool_get_int(val)) {

            qstring_append(VAR_1, "true");

        } else {

            qstring_append(VAR_1, "false");

        }

        break;

    }

    case QTYPE_QERROR:

        

    case QTYPE_NONE:

        break;

    }

}

static void FUNC_0(const QObject *VAR_0, QString *VAR_1, int VAR_2, int VAR_3)
{ switch (qobject_type(VAR_0)) { case QTYPE_QINT: { QInt *val = qobject_to_qint(VAR_0); char VAR_9[1024]; snprintf(VAR_9, sizeof(VAR_9), "%" PRId64, qint_get_int(val)); qstring_append(VAR_1, VAR_9); break; } case QTYPE_QSTRING: { QString *val = qobject_to_qstring(VAR_0); const char *VAR_5; VAR_5 = qstring_get_str(val); qstring_append(VAR_1, "\""); while (*VAR_5) { if ((VAR_5[0] & 0xE0) == 0xE0 &&
(VAR_5[1] & 0x80) && (VAR_5[2] & 0x80)) { uint16_t wchar; char VAR_7[7]; wchar  = (VAR_5[0] & 0x0F) << 12; wchar |= (VAR_5[1] & 0x3F) << 6; wchar |= (VAR_5[2] & 0x3F); VAR_5 += 2; snprintf(VAR_7, sizeof(VAR_7), "\\u%04X", wchar); qstring_append(VAR_1, VAR_7); } else if ((VAR_5[0] & 0xE0) == 0xC0 && (VAR_5[1] & 0x80)) { uint16_t wchar; char VAR_7[7]; wchar  = (VAR_5[0] & 0x1F) << 6; wchar |= (VAR_5[1] & 0x3F); VAR_5++; snprintf(VAR_7, sizeof(VAR_7), "\\u%04X", wchar); qstring_append(VAR_1, VAR_7); } else switch (VAR_5[0]) { case '\"':
qstring_append(VAR_1, "\\\""); break; case '\\':
qstring_append(VAR_1, "\\\\"); break; case '\b':
qstring_append(VAR_1, "\\b"); break; case '\f':
qstring_append(VAR_1, "\\f"); break; case '\n':
qstring_append(VAR_1, "\\n"); break; case '\r':
qstring_append(VAR_1, "\\r"); break; case '\t':
qstring_append(VAR_1, "\\t"); break; default: { if (VAR_5[0] <= 0x1F) { char VAR_7[7]; snprintf(VAR_7, sizeof(VAR_7), "\\u%04X", VAR_5[0]); qstring_append(VAR_1, VAR_7); } else { char VAR_7[2] = { VAR_5[0], 0 }; qstring_append(VAR_1, VAR_7); } break; } } VAR_5++; } qstring_append(VAR_1, "\""); break; } case QTYPE_QDICT: { ToJsonIterState s; QDict *val = qobject_to_qdict(VAR_0); s.count = 0; s.VAR_1 = VAR_1; s.VAR_3 = VAR_3 + 1; s.VAR_2 = VAR_2; qstring_append(VAR_1, "{"); qdict_iter(val, to_json_dict_iter, &s); if (VAR_2) { int VAR_9; qstring_append(VAR_1, "\n"); for (VAR_9 = 0 ; VAR_9 < VAR_3 ; VAR_9++) qstring_append(VAR_1, "    "); } qstring_append(VAR_1, "}"); break; } case QTYPE_QLIST: { ToJsonIterState s; QList *val = qobject_to_qlist(VAR_0); s.count = 0; s.VAR_1 = VAR_1; s.VAR_3 = VAR_3 + 1; s.VAR_2 = VAR_2; qstring_append(VAR_1, "["); qlist_iter(val, (void *)to_json_list_iter, &s); if (VAR_2) { int VAR_9; qstring_append(VAR_1, "\n"); for (VAR_9 = 0 ; VAR_9 < VAR_3 ; VAR_9++) qstring_append(VAR_1, "    "); } qstring_append(VAR_1, "]"); break; } case QTYPE_QFLOAT: { QFloat *val = qobject_to_qfloat(VAR_0); char VAR_9[1024]; int VAR_9; VAR_9 = snprintf(VAR_9, sizeof(VAR_9), "%f", qfloat_get_double(val)); while (VAR_9 > 0 && VAR_9[VAR_9 - 1] == '0') { VAR_9--; } if (VAR_9 && VAR_9[VAR_9 - 1] == '.') { VAR_9[VAR_9 - 1] = 0; } else { VAR_9[VAR_9] = 0; } qstring_append(VAR_1, VAR_9); break; } case QTYPE_QBOOL: { QBool *val = qobject_to_qbool(VAR_0); if (qbool_get_int(val)) { qstring_append(VAR_1, "true"); } else { qstring_append(VAR_1, "false"); } break; } case QTYPE_QERROR:
case QTYPE_NONE:
break; } }