// File: /workspace/github_c_makefile_star2_O3/sgsfak[P]c-ocgeo/src/ocgeo.c
// Function: do_request
static bool
do_request(bool is_fwd, const char* q, const char* api_key, 
           ocgeo_params_t* params, ocgeo_response_t* response)
{
    if (params == NULL) {
        ocgeo_params_t params = ocgeo_default_params();
        return do_request(is_fwd, q, api_key, &params, response);
    }

    /* Make sure that we have a proper response: */
    if (response == NULL)
        return false;

    CURL *curl = curl_easy_init();
    if (curl == NULL) {
        return false;
    }

    // Build URL:
    char* q_escaped = curl_easy_escape(curl, q, 0);
    sds url = sdsempty();
    url = sdscatprintf(url, "%s?q=%s&key=%s", OCG_API_SERVER, q_escaped, api_key);
    curl_free(q_escaped);
    if (params->abbrv)
        url = sdscat(url, "&abbrv=1");
    if (is_fwd && params->countrycode)
        url = sdscatprintf(url, "&countrycode=%s", params->countrycode);
    if (params->language)
        url = sdscatprintf(url, "&language=%s", params->language);
    if (params->limit)
        url = sdscatprintf(url, "&limit=%d", params->limit);
    if (params->min_confidence)
        url = sdscatprintf(url, "&min_confidence=%d", params->min_confidence);
    url = sdscatprintf(url, "&no_annotations=%d", params->no_annotations ? 1 : 0);
    if (params->no_dedupe)
        url = sdscat(url, "&no_dedupe=1");
    if (params->no_record)
        url = sdscat(url, "&no_record=1");
    if (is_fwd && params->roadinfo)
        url = sdscat(url, "&roadinfo=1");
    if (is_fwd && ocgeo_is_valid_latlng(params->proximity))
        url = sdscatprintf(url, "&proximity=%.8F,%.8F", params->proximity.lat, params->proximity.lng);

    /* The value of the bounds parameter should be specified as two coordinate
       points forming the south-west and north-east corners of a bounding box.
       For example: bounds=-0.563160,51.280430,0.278970,51.683979 (min lon, min
       lat, max lon, max lat). */
    if (ocgeo_is_valid_bounds(&params->bounds))
        url = sdscatprintf(url, "&bounds=%.8F,%.8F,%.8F,%.8F", 
            params->bounds.southwest.lng, params->bounds.southwest.lat, 
            params->bounds.northeast.lng, params->bounds.northeast.lat);

    log("URL=%s\n", url);
	response->url = url;

    struct http_response r; r.data = sdsempty();
    sds user_agent = sdsempty();
    user_agent = sdscatprintf(user_agent, "c-ocgeo/%s (%s)", ocgeo_version, curl_version());
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, user_agent);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &r);
    CURLcode res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    sdsfree(user_agent);

    if (res != CURLE_OK) {
        sdsfree(r.data);
        return false;
    }

    cJSON* json = cJSON_Parse(r.data);
    sdsfree(r.data);

    if (json == NULL)
        return false;

    if (params->dbg_callback != NULL) {
        char* str = cJSON_Print(json);
        params->dbg_callback(str, params->callback_data);
        cJSON_free(str);
    }

    parse_response_json(json, response);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, %rbx
movq %rdx, %r12
movq %rsi, %r13
movl %edi, %ebp
testq %rcx, %rcx
je 0x1994
testq %rbx, %rbx
je 0x1990
movq %rcx, %r14
callq 0x1170
testq %rax, %rax
jne 0x19ed
xorl %eax, %eax
jmp 0x19de
xorps %xmm0, %xmm0
movq %rsp, %rcx
movaps %xmm0, 0x60(%rcx)
movaps %xmm0, 0x50(%rcx)
movaps %xmm0, 0x30(%rcx)
movaps %xmm0, 0x20(%rcx)
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, 0x40(%rcx)
movaps %xmm0, (%rcx)
movupd 0x5ac3(%rip), %xmm0     # 0x7480
movupd %xmm0, 0x58(%rcx)
movupd %xmm0, 0x28(%rcx)
movupd %xmm0, 0x18(%rcx)
movzbl %bpl, %edi
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x1960
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x11e0
movq %rax, %r13
callq 0x28ff
leaq 0x5ac2(%rip), %rsi      # 0x74ce
leaq 0x5aca(%rip), %rdx      # 0x74dd
movq %rax, %rdi
movq %r13, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x2d7d
movq %rax, %r12
movq %r13, %rdi
callq 0x1070
cmpb $0x1, 0x10(%r14)
jne 0x1a47
leaq 0x5ace(%rip), %rsi      # 0x750a
movq %r12, %rdi
callq 0x2b6d
movq %rax, %r12
testb %bpl, %bpl
je 0x1a69
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0x1a69
leaq 0x5ab7(%rip), %rsi      # 0x7513
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d7d
movq %rax, %r12
movq 0x40(%r14), %rdx
testq %rdx, %rdx
je 0x1a86
leaq 0x5aaa(%rip), %rsi      # 0x7523
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d7d
movq %rax, %r12
movl 0x48(%r14), %edx
testl %edx, %edx
je 0x1aa2
leaq 0x5a9b(%rip), %rsi      # 0x7530
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d7d
movq %rax, %r12
movl 0x4c(%r14), %edx
testl %edx, %edx
je 0x1abe
leaq 0x5a89(%rip), %rsi      # 0x753a
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d7d
movq %rax, %r12
movzbl 0x50(%r14), %edx
leaq 0x5a83(%rip), %rsi      # 0x754d
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d7d
movq %rax, %r12
cmpb $0x1, 0x51(%r14)
jne 0x1af0
leaq 0x5a7b(%rip), %rsi      # 0x7560
movq %r12, %rdi
callq 0x2b6d
movq %rax, %r12
cmpb $0x1, 0x52(%r14)
jne 0x1b09
leaq 0x5a6f(%rip), %rsi      # 0x756d
movq %r12, %rdi
callq 0x2b6d
movq %rax, %r12
testb %bpl, %bpl
je 0x1b77
cmpb $0x1, 0x68(%r14)
jne 0x1b27
leaq 0x5a5e(%rip), %rsi      # 0x757a
movq %r12, %rdi
callq 0x2b6d
movq %rax, %r12
movsd 0x58(%r14), %xmm0
movapd 0x593b(%rip), %xmm2     # 0x7470
movapd %xmm0, %xmm1
andpd %xmm2, %xmm1
movsd 0x594b(%rip), %xmm3     # 0x7490
ucomisd %xmm1, %xmm3
jb 0x1b77
movsd 0x60(%r14), %xmm1
andpd %xmm1, %xmm2
movsd 0x593b(%rip), %xmm3     # 0x7498
ucomisd %xmm2, %xmm3
jb 0x1b77
leaq 0x5a1c(%rip), %rsi      # 0x7586
movq %r12, %rdi
movb $0x2, %al
callq 0x2d7d
movq %rax, %r12
movsd 0x18(%r14), %xmm3
movapd 0x58eb(%rip), %xmm4     # 0x7470
movapd %xmm3, %xmm1
andpd %xmm4, %xmm1
movsd 0x58fb(%rip), %xmm0     # 0x7490
ucomisd %xmm1, %xmm0
jb 0x1bef
movsd 0x20(%r14), %xmm2
movapd %xmm2, %xmm1
andpd %xmm4, %xmm1
movsd 0x58e7(%rip), %xmm5     # 0x7498
ucomisd %xmm1, %xmm5
jb 0x1bef
movsd 0x28(%r14), %xmm1
movapd %xmm1, %xmm6
andpd %xmm4, %xmm6
ucomisd %xmm6, %xmm0
jb 0x1bef
movsd 0x30(%r14), %xmm0
andpd %xmm0, %xmm4
ucomisd %xmm4, %xmm5
jb 0x1bef
leaq 0x59b9(%rip), %rsi      # 0x759b
movq %r12, %rdi
movb $0x4, %al
callq 0x2d7d
movq %rax, %r12
movq 0x93e2(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x59b7(%rip), %rsi      # 0x75b7
movq %r12, %rdx
xorl %eax, %eax
callq 0x11b0
movq %r12, 0x10(%rbx)
callq 0x28ff
movq %rsp, %rcx
movq %rax, (%rcx)
callq 0x28ff
movq %rax, %rbp
movq 0x94e0(%rip), %r13      # 0xb108
callq 0x11c0
leaq 0x598b(%rip), %rsi      # 0x75bf
movq %rbp, %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2d7d
movq %rax, %rbp
movq %r15, %rdi
movl $0x2712, %esi           # imm = 0x2712
movq %r12, %rdx
xorl %eax, %eax
callq 0x1150
movq %r15, %rdi
movl $0x2722, %esi           # imm = 0x2722
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1150
leaq 0x3a6(%rip), %rdx       # 0x2018
movq %r15, %rdi
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x1150
movq %r15, %rdi
movl $0x2711, %esi           # imm = 0x2711
movq %rsp, %r13
movq %r13, %rdx
xorl %eax, %eax
callq 0x1150
movq %r15, %rdi
callq 0x1180
movl %eax, %r12d
movq %r15, %rdi
callq 0x1160
movq %rbp, %rdi
callq 0x299f
movq (%r13), %rdi
testl %r12d, %r12d
je 0x1cc4
callq 0x299f
jmp 0x1990
callq 0x4184
movq %rax, %r15
movq (%rsp), %rdi
callq 0x299f
testq %r15, %r15
je 0x1990
cmpq $0x0, 0x8(%r14)
je 0x1d02
movq %r15, %rdi
callq 0x418d
movq %rax, %r12
movq (%r14), %rsi
movq %rax, %rdi
callq *0x8(%r14)
movq %r12, %rdi
callq 0x5dd1
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2042
movb $0x1, %al
jmp 0x19de