// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movb %dil, %al
andb $0x1, %al
movb %al, -0x2(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2220
leaq -0x98(%rbp), %rdi
callq 0x2110
movb -0x2(%rbp), %al
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %r8
leaq -0x98(%rbp), %rcx
andb $0x1, %al
movzbl %al, %edi
callq 0x21c0
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x2694
cmpq $0x0, -0x28(%rbp)
jne 0x2230
movb $0x0, -0x1(%rbp)
jmp 0x2694
callq 0x1150
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x224f
movb $0x0, -0x1(%rbp)
jmp 0x2694
movq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x11d0
movq %rax, -0xa8(%rbp)
callq 0x3970
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq 0x9261(%rip), %rsi      # 0xb4ee
leaq 0x9269(%rip), %rdx      # 0xb4fd
movb $0x0, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x1050
movq -0x20(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0x22d2
movq -0xb0(%rbp), %rdi
leaq 0x9264(%rip), %rsi      # 0xb52a
callq 0x3e60
movq %rax, -0xb0(%rbp)
testb $0x1, -0x2(%rbp)
je 0x2307
movq -0x20(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x2307
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdx
leaq 0x923a(%rip), %rsi      # 0xb533
movb $0x0, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x2336
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdx
leaq 0x921b(%rip), %rsi      # 0xb543
movb $0x0, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x48(%rax)
je 0x2363
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x48(%rax), %edx
leaq 0x91fb(%rip), %rsi      # 0xb550
movb $0x0, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x2390
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x4c(%rax), %edx
leaq 0x91d8(%rip), %rsi      # 0xb55a
movb $0x0, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movb 0x50(%rax), %cl
xorl %edx, %edx
movl $0x1, %eax
testb $0x1, %cl
cmovnel %eax, %edx
leaq 0x91bb(%rip), %rsi      # 0xb56d
movb $0x0, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x51(%rax)
je 0x23e4
movq -0xb0(%rbp), %rdi
leaq 0x91a8(%rip), %rsi      # 0xb580
callq 0x3e60
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x52(%rax)
je 0x2408
movq -0xb0(%rbp), %rdi
leaq 0x9191(%rip), %rsi      # 0xb58d
callq 0x3e60
movq %rax, -0xb0(%rbp)
testb $0x1, -0x2(%rbp)
je 0x2432
movq -0x20(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x2432
movq -0xb0(%rbp), %rdi
leaq 0x9174(%rip), %rsi      # 0xb59a
callq 0x3e60
movq %rax, -0xb0(%rbp)
testb $0x1, -0x2(%rbp)
je 0x247f
movq -0x20(%rbp), %rax
movsd 0x58(%rax), %xmm0
movsd 0x60(%rax), %xmm1
callq 0x2ab0
testb $0x1, %al
jne 0x2451
jmp 0x247f
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x60(%rax), %xmm1
leaq 0x9135(%rip), %rsi      # 0xb5a6
movb $0x2, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
callq 0x2b20
testb $0x1, %al
jne 0x2492
jmp 0x24d2
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movsd 0x30(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x28(%rax), %xmm1
movq -0x20(%rbp), %rax
movsd 0x20(%rax), %xmm2
movq -0x20(%rbp), %rax
movsd 0x18(%rax), %xmm3
leaq 0x90f7(%rip), %rsi      # 0xb5bb
movb $0x4, %al
callq 0x40e0
movq %rax, -0xb0(%rbp)
movq 0xcaff(%rip), %rax      # 0xefd8
movq (%rax), %rdi
movq -0xb0(%rbp), %rdx
leaq 0x90ed(%rip), %rsi      # 0xb5d7
movb $0x0, %al
callq 0x1190
movq -0xb0(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
callq 0x3970
movq %rax, -0xb8(%rbp)
callq 0x3970
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq 0xcbdb(%rip), %rax      # 0xf108
movq %rax, -0xe0(%rbp)
callq 0x11b0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rdx
movq %rax, %rcx
leaq 0x908e(%rip), %rsi      # 0xb5df
movb $0x0, %al
callq 0x40e0
movq %rax, -0xc0(%rbp)
movq -0xa0(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movl $0x2712, %esi           # imm = 0x2712
movb $0x0, %al
callq 0x1130
movq -0xa0(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movl $0x2722, %esi           # imm = 0x2722
movb $0x0, %al
callq 0x1130
movq -0xa0(%rbp), %rdi
movl $0x4e2b, %esi           # imm = 0x4E2B
leaq 0x5da(%rip), %rdx       # 0x2b80
movb $0x0, %al
callq 0x1130
movq -0xa0(%rbp), %rdi
movl $0x2711, %esi           # imm = 0x2711
leaq -0xb8(%rbp), %rdx
movb $0x0, %al
callq 0x1130
movq -0xa0(%rbp), %rdi
callq 0x1160
movl %eax, -0xc4(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x1140
movq -0xc0(%rbp), %rdi
callq 0x3a10
cmpl $0x0, -0xc4(%rbp)
je 0x260f
movq -0xb8(%rbp), %rdi
callq 0x3a10
movb $0x0, -0x1(%rbp)
jmp 0x2694
movq -0xb8(%rbp), %rdi
callq 0x5bb0
movq %rax, -0xd0(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x3a10
cmpq $0x0, -0xd0(%rbp)
jne 0x263e
movb $0x0, -0x1(%rbp)
jmp 0x2694
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2680
movq -0xd0(%rbp), %rdi
callq 0x5be0
movq %rax, -0xd8(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0xd8(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq (%rcx), %rsi
callq *%rax
movq -0xd8(%rbp), %rdi
callq 0x8460
movq -0xd0(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2bd0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)