// File: /workspace/github_c_makefile_star2_O0/Cotix[P]cReddit/libreddit/token.c
// Function: redditvRunParser
TokenParserResult redditvRunParser(char *url, char *post, TokenIdent *idents, va_list args)
{
    /* Initalize various pieces that are needed to get and parse the JSON */
    TokenParser *parser = tokenParserNew();
    char *cookieStr = NULL;
    CURL *redditHandle = curl_easy_init();
    jsmnerr_t jsmnResult;
    char fullUseragent[1024];

    DEBUG_PRINT(L"Grabbing %s\n", url);
    if (post)
        DEBUG_PRINT(L"Post: %s\n", post);

    /* Set default response */
    TokenParserResult result = TOKEN_PARSER_SUCCESS;

    /* Sets up curl to get 'url' and use writeToParser as the callback writer */
    curl_easy_setopt(redditHandle, CURLOPT_URL, url);
    curl_easy_setopt(redditHandle, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(redditHandle, CURLOPT_WRITEFUNCTION, writeToParser);
    curl_easy_setopt(redditHandle, CURLOPT_WRITEDATA, (void *)parser);

    /* This gets and sets any cookies, if any are currently in the global state */
    cookieStr = redditGetCookieString();
    if (cookieStr != NULL)
        curl_easy_setopt(redditHandle, CURLOPT_COOKIE, cookieStr);

    /* If we're doing a POST, then this sets curl to use POST and tells it what
     * text to use */
    if (post != NULL) {
        curl_easy_setopt(redditHandle, CURLOPT_POST, 1);
        curl_easy_setopt(redditHandle, CURLOPT_POSTFIELDS, (void *)post);
    }

    /* Set the user agent, A combo of libreddit's useragent and the program
     * using libreddit's useragent */
    strcpy(fullUseragent, LIBREDDIT_USERAGENT);
    strcat(fullUseragent, currentRedditState->userAgent);
    curl_easy_setopt(redditHandle, CURLOPT_USERAGENT, fullUseragent);

    /* Run curl, which will run the callback and store our text in the parser
     * then cleanup */
    curl_easy_perform(redditHandle);
    curl_easy_cleanup(redditHandle);

    /* If we didn't get any memory back for whatever reason, set our
     * result to an error and jump to cleanup code. */
    if (parser->block->size <= 0 || parser->block->memory == NULL) {
        result = TOKEN_PARSER_CURL_FAIL;
        goto cleanup;
    }

    /* Create our tokens */
    jsmnResult = tokenParserCreateTokens(parser);

    if (jsmnResult != JSMN_SUCCESS) {
        result = TOKEN_PARSER_JSON_FAIL;
        goto cleanup;
    }

    /* Run the parser over our tokens using the idents */
    vparseTokens(parser, idents, args);

    /* We're done, set the response and then goto cleanup code */
    result = TOKEN_PARSER_SUCCESS;



    /* Simply frees any allocated memory used in the function */
cleanup:;

    free(cookieStr);
    tokenParserFree(parser);

    return result;
}

// Assembly:
subq $0x458, %rsp            # imm = 0x458
movq %rdi, 0x450(%rsp)
movq %rsi, 0x448(%rsp)
movq %rdx, 0x440(%rsp)
movq %rcx, 0x438(%rsp)
callq 0x5d60
movq %rax, 0x430(%rsp)
movq $0x0, 0x428(%rsp)
callq 0x2240
movq %rax, 0x420(%rsp)
jmp 0x6acf
cmpq $0x0, 0x448(%rsp)
je 0x6ae0
jmp 0x6adc
jmp 0x6ade
jmp 0x6ae0
movl $0x0, 0xc(%rsp)
movq 0x420(%rsp), %rdi
movq 0x450(%rsp), %rdx
movl $0x2712, %esi           # imm = 0x2712
movb $0x0, %al
callq 0x20e0
movq 0x420(%rsp), %rdi
movl $0x34, %esi
movl $0x1, %edx
movb $0x0, %al
callq 0x20e0
movq 0x420(%rsp), %rdi
movl $0x4e2b, %esi           # imm = 0x4E2B
leaq 0x19f(%rip), %rdx       # 0x6cd0
movb $0x0, %al
callq 0x20e0
movq 0x420(%rsp), %rdi
movq 0x430(%rsp), %rdx
movl $0x2711, %esi           # imm = 0x2711
movb $0x0, %al
callq 0x20e0
movb $0x0, %al
callq 0x2170
movq %rax, 0x428(%rsp)
cmpq $0x0, 0x428(%rsp)
je 0x6b8a
movq 0x420(%rsp), %rdi
movq 0x428(%rsp), %rdx
movl $0x2726, %esi           # imm = 0x2726
movb $0x0, %al
callq 0x20e0
cmpq $0x0, 0x448(%rsp)
je 0x6bca
movq 0x420(%rsp), %rdi
movl $0x2f, %esi
movl $0x1, %edx
movb $0x0, %al
callq 0x20e0
movq 0x420(%rsp), %rdi
movq 0x448(%rsp), %rdx
movl $0x271f, %esi           # imm = 0x271F
movb $0x0, %al
callq 0x20e0
leaq 0x10(%rsp), %rdi
leaq 0x190a(%rip), %rsi      # 0x84e0
callq 0x2070
leaq 0x10(%rsp), %rdi
leaq 0x4581(%rip), %rax      # 0xb168
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x2260
movq 0x420(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movl $0x2722, %esi           # imm = 0x2722
movb $0x0, %al
callq 0x20e0
movq 0x420(%rsp), %rdi
callq 0x2130
movq 0x420(%rsp), %rdi
callq 0x20c0
movq 0x430(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x6c49
movq 0x430(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
jne 0x6c53
movl $0x1, 0xc(%rsp)
jmp 0x6ca0
movq 0x430(%rsp), %rdi
callq 0x6da0
movl %eax, 0x41c(%rsp)
cmpl $0x0, 0x41c(%rsp)
je 0x6c7b
movl $0x2, 0xc(%rsp)
jmp 0x6ca0
movq 0x430(%rsp), %rdi
movq 0x440(%rsp), %rsi
movq 0x438(%rsp), %rdx
callq 0x6840
movl $0x0, 0xc(%rsp)
movq 0x428(%rsp), %rdi
callq 0x2040
movq 0x430(%rsp), %rdi
callq 0x5da0
movl 0xc(%rsp), %eax
addq $0x458, %rsp            # imm = 0x458
retq
nopw %cs:(%rax,%rax)