// File: /workspace/github_c_makefile_star2_O1/sgsfak[P]c-ocgeo/src/ocgeo.c
// Function: parse_response_json
static int
parse_response_json(cJSON* json, ocgeo_response_t* response)
{
    cJSON* obj = NULL;

    memset(response, 0, sizeof(ocgeo_response_t));
    response->results = NULL;
    response->internal = json;

    obj = cJSON_GetObjectItemCaseSensitive(json, "status");
    assert(obj);
    response->status.code = JSON_OBJ_GET_INT(obj,"code");
    response->status.message = JSON_OBJ_GET_STR(obj,"message");

    /* Rate information, may not returned (e.g. for paying customers): */
    obj = cJSON_GetObjectItem(json, "rate");
    if (obj) {
        response->rateInfo.limit = JSON_OBJ_GET_INT(obj,"limit");
        response->rateInfo.remaining = JSON_OBJ_GET_INT(obj,"remaining");
        response->rateInfo.reset = JSON_OBJ_GET_INT(obj,"reset");
    }

    obj = cJSON_GetObjectItem(json, "total_results");
    assert(obj);
    response->total_results = JSON_INT_VALUE(obj);
    if (response->total_results <= 0) {
        return 0;
    }

    response->results = malloc(response->total_results * sizeof(ocgeo_result_t));
    obj = cJSON_GetObjectItemCaseSensitive(json, "results");
    assert(obj);

    cJSON* result_js;
    int k = 0;
    ocgeo_result_t proto = {0};
    for (result_js = obj->child; result_js!= NULL; result_js = result_js->next, k++) {
        ocgeo_result_t* result = response->results + k;
        *result = proto; /* initialize with 0/NULL values */
        result->internal = result_js;

        result->confidence = JSON_OBJ_GET_INT(result_js,"confidence");
        result->formatted = JSON_OBJ_GET_STR(result_js,"formatted");

        cJSON* bounds_js = cJSON_GetObjectItemCaseSensitive(result_js, "bounds");
        // assert(bounds_js);
        if (bounds_js) {
            result->bounds = calloc(1, sizeof(ocgeo_latlng_bounds_t));
            parse_latlng(cJSON_GetObjectItem(bounds_js, "northeast"), &result->bounds->northeast);
            parse_latlng(cJSON_GetObjectItem(bounds_js, "southwest"), &result->bounds->southwest);
        }

        cJSON* geom_js = cJSON_GetObjectItemCaseSensitive(result_js, "geometry");
        // assert(geom_js);
        if (geom_js)
            parse_latlng(geom_js, &result->geometry);
        else
            result->geometry = ocgeo_invalid_point;
        

        cJSON* comp_js = cJSON_GetObjectItemCaseSensitive(result_js, "components");
        assert(comp_js);
        result->ISO_alpha2 = JSON_OBJ_GET_STR(comp_js, "ISO_3166-1_alpha-2");
        result->ISO_alpha3 = JSON_OBJ_GET_STR(comp_js, "ISO_3166-1_alpha-3");
        result->type = JSON_OBJ_GET_STR(comp_js, "_type");
        result->category = JSON_OBJ_GET_STR(comp_js, "_category");
        result->city = JSON_OBJ_GET_STR(comp_js, "city");
        result->city_district = JSON_OBJ_GET_STR(comp_js, "city_district");
        result->continent = JSON_OBJ_GET_STR(comp_js, "continent");
        result->country = JSON_OBJ_GET_STR(comp_js, "country");
        result->country_code = JSON_OBJ_GET_STR(comp_js, "country_code");
        result->county = JSON_OBJ_GET_STR(comp_js, "county");
        result->house_number = JSON_OBJ_GET_STR(comp_js, "house_number");
        result->neighbourhood = JSON_OBJ_GET_STR(comp_js, "neighbourhood");
        result->political_union = JSON_OBJ_GET_STR(comp_js, "political_union");
        result->postcode = JSON_OBJ_GET_STR(comp_js, "postcode");
        result->road = JSON_OBJ_GET_STR(comp_js, "road");
        result->state = JSON_OBJ_GET_STR(comp_js, "state");
        result->state_district = JSON_OBJ_GET_STR(comp_js, "state_district");
        result->suburb = JSON_OBJ_GET_STR(comp_js, "suburb");

        /* Parse annotations, if exist */
        cJSON* ann_js = cJSON_GetObjectItemCaseSensitive(result_js, "annotations");
        if (ann_js) {
            result->callingcode = JSON_OBJ_GET_INT(ann_js,"callingcode");
            
            cJSON* tm_ann = cJSON_GetObjectItemCaseSensitive(ann_js, "timezone");
            if (tm_ann) {
                ocgeo_ann_timezone_t* timezone = calloc(1, sizeof(ocgeo_ann_timezone_t));
                timezone->name = JSON_OBJ_GET_STR(tm_ann, "name");
                timezone->short_name = JSON_OBJ_GET_STR(tm_ann, "short_name");
                timezone->offset_string = JSON_OBJ_GET_STR(tm_ann, "offset_string");
                timezone->offset_sec = JSON_OBJ_GET_INT(tm_ann,"offset_sec");
                timezone->now_in_dst = JSON_OBJ_GET_INT(tm_ann,"now_in_dst") == 1;
                result->timezone = timezone;
            }
            cJSON* ri_ann = cJSON_GetObjectItemCaseSensitive(ann_js, "roadinfo");
            if (ri_ann) {
                ocgeo_ann_roadinfo_t* roadinfo = calloc(1, sizeof(ocgeo_ann_roadinfo_t));
                roadinfo->drive_on = JSON_OBJ_GET_STR(ri_ann, "drive_on");
                roadinfo->speed_in = JSON_OBJ_GET_STR(ri_ann, "speed_in");
                roadinfo->road = JSON_OBJ_GET_STR(ri_ann, "road");
                roadinfo->road_type = JSON_OBJ_GET_STR(ri_ann, "road_type");
                roadinfo->surface = JSON_OBJ_GET_STR(ri_ann, "surface");
                result->roadinfo = roadinfo;
            }
            cJSON* cur_ann = cJSON_GetObjectItemCaseSensitive(ann_js, "currency");
            if (cur_ann) {
                ocgeo_ann_currency_t* currency = calloc(1, sizeof(ocgeo_ann_currency_t));
                currency->name = JSON_OBJ_GET_STR(cur_ann, "name");
                currency->iso_code = JSON_OBJ_GET_STR(cur_ann, "iso_code");
                currency->symbol = JSON_OBJ_GET_STR(cur_ann, "symbol");
                currency->decimal_mark = JSON_OBJ_GET_STR(cur_ann, "decimal_mark");
                currency->thousands_separator = JSON_OBJ_GET_STR(cur_ann, "thousands_separator");
                result->currency = currency;
            }
            result->geohash = JSON_OBJ_GET_STR(ann_js, "geohash");
            cJSON* w3w_ann = cJSON_GetObjectItemCaseSensitive(ann_js, "what3words");
            if (w3w_ann) {
                result->what3words = JSON_OBJ_GET_STR(w3w_ann, "words");
            }
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsi)
movups %xmm0, 0x10(%rsi)
movups %xmm0, (%rsi)
movq %rdi, 0x30(%rsi)
leaq 0x5553(%rip), %rsi      # 0x75cf
callq 0x4a80
testq %rax, %rax
je 0x283c
movq %rax, %r15
leaq 0x51dc(%rip), %rsi      # 0x7270
movq %rax, %rdi
callq 0x4a80
movl 0x28(%rax), %eax
movl %eax, (%rbx)
leaq 0x5573(%rip), %rsi      # 0x761b
movq %r15, %rdi
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x8(%rbx)
leaq 0x5560(%rip), %rsi      # 0x7623
movq %r14, %rdi
callq 0x49c6
testq %rax, %rax
je 0x2112
movq %rax, %r15
leaq 0x554e(%rip), %rsi      # 0x7628
movq %rax, %rdi
callq 0x4a80
movl 0x28(%rax), %eax
movl %eax, 0x18(%rbx)
leaq 0x553f(%rip), %rsi      # 0x762e
movq %r15, %rdi
callq 0x4a80
movl 0x28(%rax), %eax
movl %eax, 0x1c(%rbx)
leaq 0x5534(%rip), %rsi      # 0x7638
movq %r15, %rdi
callq 0x4a80
movl 0x28(%rax), %eax
movl %eax, 0x20(%rbx)
leaq 0x5525(%rip), %rsi      # 0x763e
movq %r14, %rdi
callq 0x49c6
testq %rax, %rax
je 0x285b
movq %rax, %r15
movq %rax, %rdi
callq 0x5cf3
xorl %ecx, %ecx
testl %eax, %eax
jne 0x213f
movl 0x28(%r15), %ecx
movl %ecx, 0x24(%rbx)
testl %ecx, %ecx
jle 0x280b
movl %ecx, %eax
imulq $0xe8, %rax, %rdi
callq 0x1200
movq %rax, 0x28(%rbx)
leaq 0x5009(%rip), %rsi      # 0x716c
movq %r14, %rdi
callq 0x4a80
testq %rax, %rax
je 0x287a
movq %rax, %r14
leaq 0x10(%rsp), %rdi
movl $0xe8, %edx
xorl %esi, %esi
callq 0x10c0
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x280b
xorl %ebp, %ebp
movq %rbx, (%rsp)
movq 0x28(%rbx), %rbx
leaq (%rbx,%rbp), %rdi
movl $0xe8, %edx
leaq 0x10(%rsp), %rsi
callq 0x1110
movq %r14, 0xe0(%rbx,%rbp)
movq %r14, %rdi
leaq 0x5488(%rip), %rsi      # 0x764c
callq 0x4a80
movl 0x28(%rax), %eax
movl %eax, 0xb0(%rbx,%rbp)
movq %r14, %rdi
leaq 0x547a(%rip), %rsi      # 0x7657
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, (%rbx,%rbp)
movq %r14, %rdi
leaq 0x50ce(%rip), %rsi      # 0x72c6
callq 0x4a80
testq %rax, %rax
je 0x22be
movq %rax, %r15
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, 0x8(%rbx,%rbp)
movq %r15, %rdi
leaq 0x543a(%rip), %rsi      # 0x7661
callq 0x49c6
movq %rax, %r12
movq 0x8(%rbx,%rbp), %r13
movq %rax, %rdi
movq %r14, 0x8(%rsp)
leaq 0x4ff0(%rip), %r14      # 0x7233
movq %r14, %rsi
callq 0x4a80
movsd 0x30(%rax), %xmm0
movsd %xmm0, (%r13)
movq %r12, %rdi
leaq 0x55ad(%rip), %rsi      # 0x780d
callq 0x4a80
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x8(%r13)
movq %r15, %rdi
leaq 0x53f1(%rip), %rsi      # 0x766b
callq 0x49c6
movq %rax, %r15
movq 0x8(%rbx,%rbp), %r12
movq %rax, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %r14
callq 0x4a80
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x10(%r12)
movq %r15, %rdi
leaq 0x5560(%rip), %rsi      # 0x780d
callq 0x4a80
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x18(%r12)
movq %r14, %rdi
leaq 0x53ad(%rip), %rsi      # 0x7675
callq 0x4a80
testq %rax, %rax
je 0x230b
movq %rax, %r15
movq %rax, %rdi
leaq 0x4f54(%rip), %rsi      # 0x7233
callq 0x4a80
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x10(%rbx,%rbp)
movq %r15, %rdi
leaq 0x5514(%rip), %rsi      # 0x780d
callq 0x4a80
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x18(%rbx,%rbp)
jmp 0x231d
leaq (%rbx,%rbp), %rax
addq $0x10, %rax
movups 0x5166(%rip), %xmm0     # 0x7480
movups %xmm0, (%rax)
movq %r14, %rdi
leaq 0x5357(%rip), %rsi      # 0x767e
callq 0x4a80
testq %rax, %rax
je 0x281d
movq %rax, %r12
movq %rax, %rdi
leaq 0x534f(%rip), %rsi      # 0x7691
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x20(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5346(%rip), %rsi      # 0x76a4
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x28(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5438(%rip), %rsi      # 0x77b2
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x30(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5321(%rip), %rsi      # 0x76b7
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x38(%rbx,%rbp)
movq %r12, %rdi
leaq 0x530f(%rip), %rsi      # 0x76c1
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x40(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52f8(%rip), %rsi      # 0x76c6
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x48(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52ea(%rip), %rsi      # 0x76d4
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x50(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52d8(%rip), %rsi      # 0x76de
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x58(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52c4(%rip), %rsi      # 0x76e6
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x60(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52b5(%rip), %rsi      # 0x76f3
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x68(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52a0(%rip), %rsi      # 0x76fa
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x70(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5291(%rip), %rsi      # 0x7707
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x78(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5283(%rip), %rsi      # 0x7715
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x80(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5274(%rip), %rsi      # 0x7725
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x88(%rbx,%rbp)
movq %r12, %rdi
leaq 0x525e(%rip), %rsi      # 0x772e
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x90(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5244(%rip), %rsi      # 0x7733
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x98(%rbx,%rbp)
movq %r12, %rdi
leaq 0x522b(%rip), %rsi      # 0x7739
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0xa0(%rbx,%rbp)
movq %r12, %rdi
leaq 0x521b(%rip), %rsi      # 0x7748
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0xa8(%rbx,%rbp)
movq %r14, %rdi
leaq 0x5203(%rip), %rsi      # 0x774f
callq 0x4a80
testq %rax, %rax
je 0x27f4
movq %rax, %r12
movq %rax, %rdi
leaq 0x4cdc(%rip), %rsi      # 0x7243
callq 0x4a80
movl 0x28(%rax), %eax
movl %eax, 0xb4(%rbx,%rbp)
movq %r12, %rdi
leaq 0x51db(%rip), %rsi      # 0x775b
callq 0x4a80
testq %rax, %rax
je 0x262a
movq %rax, %r15
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, %r13
movq %r15, %rdi
leaq 0x51bd(%rip), %rsi      # 0x776a
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, (%r13)
movq %r15, %rdi
leaq 0x519c(%rip), %rsi      # 0x7764
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x8(%r13)
movq %r15, %rdi
leaq 0x518c(%rip), %rsi      # 0x776f
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x10(%r13)
movq %r15, %rdi
leaq 0x517f(%rip), %rsi      # 0x777d
callq 0x4a80
movl 0x28(%rax), %eax
movl %eax, 0x18(%r13)
movq %r15, %rdi
leaq 0x5174(%rip), %rsi      # 0x7788
callq 0x4a80
cmpl $0x1, 0x28(%rax)
sete 0x1c(%r13)
movq %r13, 0xb8(%rbx,%rbp)
movq %r12, %rdi
leaq 0x515f(%rip), %rsi      # 0x7793
callq 0x4a80
testq %rax, %rax
je 0x26e6
movq %rax, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x10f0
movq %rax, %r13
movq %r15, %rdi
leaq 0x513b(%rip), %rsi      # 0x779c
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, (%r13)
movq %r15, %rdi
leaq 0x5129(%rip), %rsi      # 0x77a5
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x8(%r13)
movq %r15, %rdi
leaq 0x5097(%rip), %rsi      # 0x772e
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x10(%r13)
movq %r15, %rdi
leaq 0x50fc(%rip), %rsi      # 0x77ae
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x18(%r13)
movq %r15, %rdi
leaq 0x50eb(%rip), %rsi      # 0x77b8
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x20(%r13)
movq %r13, 0xc0(%rbx,%rbp)
movq %r12, %rdi
leaq 0x50d0(%rip), %rsi      # 0x77c0
callq 0x4a80
testq %rax, %rax
je 0x27a2
movq %rax, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x10f0
movq %rax, %r13
movq %r15, %rdi
leaq 0x504d(%rip), %rsi      # 0x776a
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, (%r13)
movq %r15, %rdi
leaq 0x5091(%rip), %rsi      # 0x77c9
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x8(%r13)
movq %r15, %rdi
leaq 0x507f(%rip), %rsi      # 0x77d2
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x10(%r13)
movq %r15, %rdi
leaq 0x506b(%rip), %rsi      # 0x77d9
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x18(%r13)
movq %r15, %rdi
leaq 0x505d(%rip), %rsi      # 0x77e6
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0x20(%r13)
movq %r13, 0xc8(%rbx,%rbp)
movq %r12, %rdi
leaq 0x504e(%rip), %rsi      # 0x77fa
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0xd0(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5037(%rip), %rsi      # 0x7802
callq 0x4a80
testq %rax, %rax
je 0x27f4
movq %rax, %rdi
leaq 0x5028(%rip), %rsi      # 0x7807
callq 0x4a80
movq %rax, %rdi
callq 0x3b7f
movq %rax, 0xd8(%rbx,%rbp)
movq (%r14), %r14
addq $0xe8, %rbp
testq %r14, %r14
movq (%rsp), %rbx
jne 0x219b
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e65(%rip), %rdi      # 0x7689
leaq 0x4daf(%rip), %rsi      # 0x75da
leaq 0x4db4(%rip), %rcx      # 0x75e6
movl $0x89, %edx
callq 0x10e0
leaq 0x4d93(%rip), %rdi      # 0x75d6
leaq 0x4d90(%rip), %rsi      # 0x75da
leaq 0x4d95(%rip), %rcx      # 0x75e6
movl $0x56, %edx
callq 0x10e0
leaq 0x4d74(%rip), %rdi      # 0x75d6
leaq 0x4d71(%rip), %rsi      # 0x75da
leaq 0x4d76(%rip), %rcx      # 0x75e6
movl $0x63, %edx
callq 0x10e0
leaq 0x4d55(%rip), %rdi      # 0x75d6
leaq 0x4d52(%rip), %rsi      # 0x75da
leaq 0x4d57(%rip), %rcx      # 0x75e6
movl $0x6b, %edx
callq 0x10e0
nopl (%rax)