// File: /workspace/github_c_makefile_star2_O3/otrtool[P]otrtool/src/main.c
// Function: contactServer
struct MemoryStruct * contactServer(char *request) {
  // http://curl.haxx.se/libcurl/c/getinmemory.html
  CURL *curl_handle;
  CURLcode res;
  char errbuf[CURL_ERROR_SIZE];
  
  struct MemoryStruct *chunk = malloc(sizeof(struct MemoryStruct));
  chunk->memory=NULL; /* we expect realloc(NULL, size) to work */ 
  chunk->size = 0;    /* no data at this point */ 
  
  curl_global_init(CURL_GLOBAL_ALL);
  
  /* init the curl session */ 
  curl_handle = curl_easy_init();
  
  /* specify URL to get */ 
  curl_easy_setopt(curl_handle, CURLOPT_URL, request);
  
  /* send all data to this function  */ 
  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
  
  /* we pass our 'chunk' struct to the callback function */ 
  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)chunk);
  
  /* imitate the original OTR client */ 
  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Linux-OTR-Decoder/0.4.592");
  curl_easy_setopt(curl_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  
  /* set verbosity and error message buffer */
  if (opts.verbosity >= VERB_DEBUG)
    curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
  curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errbuf);
  
  /* get it! */ 
  *errbuf = 0;
  if ((res = curl_easy_perform(curl_handle)) != CURLE_OK)
    ERROR("cURL error %d: %s", res, *errbuf ? errbuf : curl_easy_strerror(res));
  
  /* cleanup curl stuff */ 
  curl_easy_cleanup(curl_handle);
  
  /*
   * Now, our chunk.memory points to a memory block that is chunk.size
   * bytes big and contains the remote file.
   *
   * Do something nice with it!
   *
   * You should be aware of the fact that at this point we might have an
   * allocated data block, and nothing has yet deallocated that data. So when
   * you're done with it, you should free() it as a nice application.
   */ 
  
  /* we're done with libcurl, so clean it up */ 
  curl_global_cleanup();
  
  // null-terminate response
  chunk->memory = realloc(chunk->memory, chunk->size + 1);
  if (chunk->memory == NULL) PERROR("realloc");
  chunk->memory[chunk->size] = 0;
  return chunk;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movq %rdi, %r15
movl $0x1, %edi
movl $0x10, %esi
callq 0x2130
movq %rax, %rbx
movl $0x3, %edi
callq 0x2080
callq 0x22f0
movq %rax, %r14
movq %rax, %rdi
movl $0x2712, %esi           # imm = 0x2712
movq %r15, %rdx
xorl %eax, %eax
callq 0x2260
leaq 0xd8(%rip), %rdx        # 0x5864
movq %r14, %rdi
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x2260
movq %r14, %rdi
movl $0x2711, %esi           # imm = 0x2711
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x3e16(%rip), %rdx      # 0x95ca
movq %r14, %rdi
movl $0x2722, %esi           # imm = 0x2722
xorl %eax, %eax
callq 0x2260
movq %r14, %rdi
movl $0x54, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2260
cmpb $0x1, 0x7aba(%rip)      # 0xd298
jne 0x57f4
movq %r14, %rdi
movl $0x29, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2260
movq %rsp, %r15
movq %r14, %rdi
movl $0x271a, %esi           # imm = 0x271A
movq %r15, %rdx
xorl %eax, %eax
callq 0x2260
movb $0x0, (%r15)
movq %r14, %rdi
callq 0x2300
testl %eax, %eax
jne 0x5855
movq %r14, %rdi
callq 0x22c0
callq 0x20a0
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
incq %rsi
callq 0x23e0
movq %rax, (%rbx)
testq %rax, %rax
je 0x585f
movq 0x8(%rbx), %rcx
movb $0x0, (%rax,%rcx)
movq %rbx, %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r14
popq %r15
retq
movq %rsp, %rdi
movl %eax, %esi
callq 0x2f38
callq 0x2f96