// File: /workspace/github_c_makefile_star2_O3/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 0x555d(%rip), %rsi      # 0x75cf
callq 0x49a1
testq %rax, %rax
je 0x2833
movq %rax, %r15
leaq 0x51e2(%rip), %rsi      # 0x726c
movq %rax, %rdi
callq 0x49a1
movl 0x28(%rax), %eax
movl %eax, (%rbx)
leaq 0x557d(%rip), %rsi      # 0x761b
movq %r15, %rdi
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x8(%rbx)
leaq 0x556a(%rip), %rsi      # 0x7623
movq %r14, %rdi
callq 0x48d0
testq %rax, %rax
je 0x2108
movq %rax, %r15
leaq 0x5558(%rip), %rsi      # 0x7628
movq %rax, %rdi
callq 0x49a1
movl 0x28(%rax), %eax
movl %eax, 0x18(%rbx)
leaq 0x5549(%rip), %rsi      # 0x762e
movq %r15, %rdi
callq 0x49a1
movl 0x28(%rax), %eax
movl %eax, 0x1c(%rbx)
leaq 0x553e(%rip), %rsi      # 0x7638
movq %r15, %rdi
callq 0x49a1
movl 0x28(%rax), %eax
movl %eax, 0x20(%rbx)
leaq 0x552f(%rip), %rsi      # 0x763e
movq %r14, %rdi
callq 0x48d0
testq %rax, %rax
je 0x2852
movq %rax, %r15
movq %rax, %rdi
callq 0x5bcc
testl %eax, %eax
je 0x2148
movl $0x0, 0x24(%rbx)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x28(%r15), %rax
movl %eax, 0x24(%rbx)
testq %rax, %rax
jle 0x2136
imulq $0xe8, %rax, %rdi
callq 0x1200
movq %rax, 0x28(%rbx)
leaq 0x5001(%rip), %rsi      # 0x716c
movq %r14, %rdi
callq 0x49a1
testq %rax, %rax
je 0x2871
movq %rax, %r14
leaq 0x10(%rsp), %rdi
movl $0xe8, %edx
xorl %esi, %esi
callq 0x10c0
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x2136
xorl %ebp, %ebp
movq %rbx, (%rsp)
movq 0x28(%rbx), %rbx
leaq (%rbx,%rbp), %rdi
movl $0xe0, %edx
leaq 0x10(%rsp), %rsi
callq 0x1110
movq %r14, 0xe0(%rbx,%rbp)
movq %r14, %rdi
leaq 0x5484(%rip), %rsi      # 0x764c
callq 0x49a1
movl 0x28(%rax), %eax
movl %eax, 0xb0(%rbx,%rbp)
movq %r14, %rdi
leaq 0x5476(%rip), %rsi      # 0x7657
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, (%rbx,%rbp)
movq %r14, %rdi
leaq 0x50c6(%rip), %rsi      # 0x72c2
callq 0x49a1
testq %rax, %rax
je 0x22c2
movq %rax, %r15
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, 0x8(%rbx,%rbp)
movq %r15, %rdi
leaq 0x5436(%rip), %rsi      # 0x7661
callq 0x48d0
movq %rax, %r12
movq 0x8(%rbx,%rbp), %r13
movq %rax, %rdi
movq %r14, 0x8(%rsp)
leaq 0x4fe8(%rip), %r14      # 0x722f
movq %r14, %rsi
callq 0x49a1
movsd 0x30(%rax), %xmm0
movsd %xmm0, (%r13)
movq %r12, %rdi
leaq 0x55a9(%rip), %rsi      # 0x780d
callq 0x49a1
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x8(%r13)
movq %r15, %rdi
leaq 0x53ed(%rip), %rsi      # 0x766b
callq 0x48d0
movq %rax, %r15
movq 0x8(%rbx,%rbp), %r12
movq %rax, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %r14
callq 0x49a1
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x10(%r12)
movq %r15, %rdi
leaq 0x555c(%rip), %rsi      # 0x780d
callq 0x49a1
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x18(%r12)
movq %r14, %rdi
leaq 0x53a9(%rip), %rsi      # 0x7675
callq 0x49a1
testq %rax, %rax
je 0x230f
movq %rax, %r15
movq %rax, %rdi
leaq 0x4f4c(%rip), %rsi      # 0x722f
callq 0x49a1
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x10(%rbx,%rbp)
movq %r15, %rdi
leaq 0x5510(%rip), %rsi      # 0x780d
callq 0x49a1
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0x18(%rbx,%rbp)
jmp 0x2321
leaq (%rbx,%rbp), %rax
addq $0x10, %rax
movups 0x5162(%rip), %xmm0     # 0x7480
movups %xmm0, (%rax)
movq %r14, %rdi
leaq 0x5353(%rip), %rsi      # 0x767e
callq 0x49a1
testq %rax, %rax
je 0x2814
movq %rax, %r12
movq %rax, %rdi
leaq 0x534b(%rip), %rsi      # 0x7691
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x20(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5342(%rip), %rsi      # 0x76a4
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x28(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5434(%rip), %rsi      # 0x77b2
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x30(%rbx,%rbp)
movq %r12, %rdi
leaq 0x531d(%rip), %rsi      # 0x76b7
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x38(%rbx,%rbp)
movq %r12, %rdi
leaq 0x530b(%rip), %rsi      # 0x76c1
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x40(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52f4(%rip), %rsi      # 0x76c6
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x48(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52e6(%rip), %rsi      # 0x76d4
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x50(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52d4(%rip), %rsi      # 0x76de
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x58(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52c0(%rip), %rsi      # 0x76e6
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x60(%rbx,%rbp)
movq %r12, %rdi
leaq 0x52b1(%rip), %rsi      # 0x76f3
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x68(%rbx,%rbp)
movq %r12, %rdi
leaq 0x529c(%rip), %rsi      # 0x76fa
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x70(%rbx,%rbp)
movq %r12, %rdi
leaq 0x528d(%rip), %rsi      # 0x7707
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x78(%rbx,%rbp)
movq %r12, %rdi
leaq 0x527f(%rip), %rsi      # 0x7715
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x80(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5270(%rip), %rsi      # 0x7725
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x88(%rbx,%rbp)
movq %r12, %rdi
leaq 0x525a(%rip), %rsi      # 0x772e
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x90(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5240(%rip), %rsi      # 0x7733
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x98(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5227(%rip), %rsi      # 0x7739
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0xa0(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5217(%rip), %rsi      # 0x7748
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0xa8(%rbx,%rbp)
movq %r14, %rdi
leaq 0x51ff(%rip), %rsi      # 0x774f
callq 0x49a1
testq %rax, %rax
je 0x27f8
movq %rax, %r12
movq %rax, %rdi
leaq 0x4cd4(%rip), %rsi      # 0x723f
callq 0x49a1
movl 0x28(%rax), %eax
movl %eax, 0xb4(%rbx,%rbp)
movq %r12, %rdi
leaq 0x51d7(%rip), %rsi      # 0x775b
callq 0x49a1
testq %rax, %rax
je 0x262e
movq %rax, %r15
movl $0x1, %edi
movl $0x20, %esi
callq 0x10f0
movq %rax, %r13
movq %r15, %rdi
leaq 0x51b9(%rip), %rsi      # 0x776a
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, (%r13)
movq %r15, %rdi
leaq 0x5198(%rip), %rsi      # 0x7764
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x8(%r13)
movq %r15, %rdi
leaq 0x5188(%rip), %rsi      # 0x776f
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x10(%r13)
movq %r15, %rdi
leaq 0x517b(%rip), %rsi      # 0x777d
callq 0x49a1
movl 0x28(%rax), %eax
movl %eax, 0x18(%r13)
movq %r15, %rdi
leaq 0x5170(%rip), %rsi      # 0x7788
callq 0x49a1
cmpl $0x1, 0x28(%rax)
sete 0x1c(%r13)
movq %r13, 0xb8(%rbx,%rbp)
movq %r12, %rdi
leaq 0x515b(%rip), %rsi      # 0x7793
callq 0x49a1
testq %rax, %rax
je 0x26ea
movq %rax, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x10f0
movq %rax, %r13
movq %r15, %rdi
leaq 0x5137(%rip), %rsi      # 0x779c
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, (%r13)
movq %r15, %rdi
leaq 0x5125(%rip), %rsi      # 0x77a5
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x8(%r13)
movq %r15, %rdi
leaq 0x5093(%rip), %rsi      # 0x772e
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x10(%r13)
movq %r15, %rdi
leaq 0x50f8(%rip), %rsi      # 0x77ae
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x18(%r13)
movq %r15, %rdi
leaq 0x50e7(%rip), %rsi      # 0x77b8
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x20(%r13)
movq %r13, 0xc0(%rbx,%rbp)
movq %r12, %rdi
leaq 0x50cc(%rip), %rsi      # 0x77c0
callq 0x49a1
testq %rax, %rax
je 0x27a6
movq %rax, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x10f0
movq %rax, %r13
movq %r15, %rdi
leaq 0x5049(%rip), %rsi      # 0x776a
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, (%r13)
movq %r15, %rdi
leaq 0x508d(%rip), %rsi      # 0x77c9
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x8(%r13)
movq %r15, %rdi
leaq 0x507b(%rip), %rsi      # 0x77d2
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x10(%r13)
movq %r15, %rdi
leaq 0x5067(%rip), %rsi      # 0x77d9
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x18(%r13)
movq %r15, %rdi
leaq 0x5059(%rip), %rsi      # 0x77e6
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0x20(%r13)
movq %r13, 0xc8(%rbx,%rbp)
movq %r12, %rdi
leaq 0x504a(%rip), %rsi      # 0x77fa
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0xd0(%rbx,%rbp)
movq %r12, %rdi
leaq 0x5033(%rip), %rsi      # 0x7802
callq 0x49a1
testq %rax, %rax
je 0x27f8
movq %rax, %rdi
leaq 0x5024(%rip), %rsi      # 0x7807
callq 0x49a1
movq %rax, %rdi
callq 0x3b2f
movq %rax, 0xd8(%rbx,%rbp)
movq (%r14), %r14
addq $0xe8, %rbp
testq %r14, %r14
movq (%rsp), %rbx
jne 0x219f
jmp 0x2136
leaq 0x4e6e(%rip), %rdi      # 0x7689
leaq 0x4db8(%rip), %rsi      # 0x75da
leaq 0x4dbd(%rip), %rcx      # 0x75e6
movl $0x89, %edx
callq 0x10e0
leaq 0x4d9c(%rip), %rdi      # 0x75d6
leaq 0x4d99(%rip), %rsi      # 0x75da
leaq 0x4d9e(%rip), %rcx      # 0x75e6
movl $0x56, %edx
callq 0x10e0
leaq 0x4d7d(%rip), %rdi      # 0x75d6
leaq 0x4d7a(%rip), %rsi      # 0x75da
leaq 0x4d7f(%rip), %rcx      # 0x75e6
movl $0x63, %edx
callq 0x10e0
leaq 0x4d5e(%rip), %rdi      # 0x75d6
leaq 0x4d5b(%rip), %rsi      # 0x75da
leaq 0x4d60(%rip), %rcx      # 0x75e6
movl $0x6b, %edx
callq 0x10e0