// File: /workspace/github_c_makefile_star2_O1/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 0x197c
testq %rbx, %rbx
je 0x1978
movq %rcx, %r14
callq 0x1170
testq %rax, %rax
jne 0x19d5
xorl %eax, %eax
jmp 0x19c6
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 0x5adb(%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 0x1948
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 0x290b
leaq 0x5ada(%rip), %rsi      # 0x74ce
leaq 0x5ae2(%rip), %rdx      # 0x74dd
movq %rax, %rdi
movq %r13, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x2d46
movq %rax, %r12
movq %r13, %rdi
callq 0x1070
cmpb $0x1, 0x10(%r14)
jne 0x1a2f
leaq 0x5ae6(%rip), %rsi      # 0x750a
movq %r12, %rdi
callq 0x2b30
movq %rax, %r12
testb %bpl, %bpl
je 0x1a51
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0x1a51
leaq 0x5acf(%rip), %rsi      # 0x7513
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d46
movq %rax, %r12
movq 0x40(%r14), %rdx
testq %rdx, %rdx
je 0x1a6e
leaq 0x5ac2(%rip), %rsi      # 0x7523
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d46
movq %rax, %r12
movl 0x48(%r14), %edx
testl %edx, %edx
je 0x1a8a
leaq 0x5ab3(%rip), %rsi      # 0x7530
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d46
movq %rax, %r12
movl 0x4c(%r14), %edx
testl %edx, %edx
je 0x1aa6
leaq 0x5aa1(%rip), %rsi      # 0x753a
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d46
movq %rax, %r12
movzbl 0x50(%r14), %edx
leaq 0x5a9b(%rip), %rsi      # 0x754d
movq %r12, %rdi
xorl %eax, %eax
callq 0x2d46
movq %rax, %r12
cmpb $0x1, 0x51(%r14)
jne 0x1ad8
leaq 0x5a93(%rip), %rsi      # 0x7560
movq %r12, %rdi
callq 0x2b30
movq %rax, %r12
cmpb $0x1, 0x52(%r14)
jne 0x1af1
leaq 0x5a87(%rip), %rsi      # 0x756d
movq %r12, %rdi
callq 0x2b30
movq %rax, %r12
testb %bpl, %bpl
je 0x1b0f
cmpb $0x1, 0x68(%r14)
jne 0x1b0f
leaq 0x5a76(%rip), %rsi      # 0x757a
movq %r12, %rdi
callq 0x2b30
movq %rax, %r12
testb %bpl, %bpl
je 0x1b64
movsd 0x58(%r14), %xmm0
movapd 0x594e(%rip), %xmm2     # 0x7470
movapd %xmm0, %xmm1
andpd %xmm2, %xmm1
movsd 0x595e(%rip), %xmm3     # 0x7490
ucomisd %xmm1, %xmm3
jb 0x1b64
movsd 0x60(%r14), %xmm1
andpd %xmm1, %xmm2
movsd 0x594e(%rip), %xmm3     # 0x7498
ucomisd %xmm2, %xmm3
jb 0x1b64
leaq 0x5a2f(%rip), %rsi      # 0x7586
movq %r12, %rdi
movb $0x2, %al
callq 0x2d46
movq %rax, %r12
movsd 0x18(%r14), %xmm3
movapd 0x58fe(%rip), %xmm0     # 0x7470
movapd %xmm3, %xmm2
andpd %xmm0, %xmm2
movsd 0x590e(%rip), %xmm1     # 0x7490
ucomisd %xmm2, %xmm1
jb 0x1be6
movsd 0x20(%r14), %xmm4
andpd %xmm0, %xmm4
movsd 0x58fe(%rip), %xmm2     # 0x7498
ucomisd %xmm4, %xmm2
jb 0x1be6
movsd 0x28(%r14), %xmm4
andpd %xmm0, %xmm4
ucomisd %xmm4, %xmm1
jb 0x1be6
movsd 0x30(%r14), %xmm1
andpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x1be6
movsd 0x30(%r14), %xmm0
movsd 0x20(%r14), %xmm2
movsd 0x28(%r14), %xmm1
leaq 0x59c2(%rip), %rsi      # 0x759b
movq %r12, %rdi
movb $0x4, %al
callq 0x2d46
movq %rax, %r12
movq 0x93eb(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x59c0(%rip), %rsi      # 0x75b7
movq %r12, %rdx
xorl %eax, %eax
callq 0x11b0
movq %r12, 0x10(%rbx)
callq 0x290b
movq %rsp, %rcx
movq %rax, (%rcx)
callq 0x290b
movq %rax, %rbp
movq 0x94e9(%rip), %r13      # 0xb108
callq 0x11c0
leaq 0x5994(%rip), %rsi      # 0x75bf
movq %rbp, %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2d46
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 0x3b9(%rip), %rdx       # 0x2022
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 0x295d
movq (%r13), %rdi
testl %r12d, %r12d
je 0x1cbb
callq 0x295d
jmp 0x1978
callq 0x4261
movq %rax, %r15
movq (%rsp), %rdi
callq 0x295d
testq %r15, %r15
setne %al
je 0x19c6
cmpq $0x0, 0x8(%r14)
je 0x1cfc
movq %r15, %rdi
callq 0x426a
movq %rax, %r12
movq (%r14), %rsi
movq %rax, %rdi
callq *0x8(%r14)
movq %r12, %rdi
callq 0x5ef8
movq %r15, %rdi
movq %rbx, %rsi
callq 0x204c
movb $0x1, %al
jmp 0x19c6