// File: /workspace/github_cpp_makefile_star2_O2/king1600[P]cordpp/src/http.cc
// Function: cordpp::RestClient::handle_response()
void RestClient::handle_response() {
  // if response.gzipped: response.body = ....
  const Json data = Json::parse(
    response.body.empty() ? "{}" : response.body);
  const RestTask task = std::move(tasks.front());
  std::map<std::string, std::string> &headers = response.headers;
  tasks.pop_front();

  // check if next request will be rate limited
  if (headers.find("X-RateLimit-Remaining") != headers.end()) {
    if (std::stoi(headers["X-RateLimit-Remaining"], nullptr, 10) < 1) {

      // get time to wait for rate limit
      long wait_time;
      if (headers.find("X-RateLimit-Reset") != headers.end()) {
        const long now = static_cast<const long>(std::time(nullptr));
        long reset = std::stol(headers["X-RateLimit-Reset"], nullptr, 10);
        wait_time = (reset - now) * 1000;
      } else if (headers.find("Retry-After") != headers.end()) {
        wait_time = std::stol(headers["Retry-After"], nullptr, 10);
      }

      // if global, limit global route
      if (data.find("global") != data.end()) {
        if (data["global"].get<std::string>() == "true") {
          global_route.rate_limited = true;
          service.call_later(wait_time, nullptr, [this](void *data) {
            flush_route(global_route);
          });
        }
      }

      // limit request route as well
      RestRoute &route = get_route(task.req);
      route.rate_limited = true;
      service.call_later(wait_time, &route, [this](void *data) {
        flush_route(*reinterpret_cast<RestRoute*>(data));
      });
    }
  }

  // start parsing again and perform callback with data
  parse_data();
  task.action(data);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rdi, %rbx
movq 0x38(%rdi), %r14
testq %r14, %r14
je 0x1e1ea
leaq 0x30(%rbx), %rsi
leaq 0xb0(%rsp), %rdi
callq 0xa580
jmp 0x1e203
leaq 0x145a6(%rip), %rsi     # 0x32797
leaq 0xb0(%rsp), %rdi
leaq 0x2f(%rsp), %rdx
callq 0xc152
leaq 0x40(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x1a050
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rdx
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x1
popq %rcx
callq 0x19f84
leaq 0x90(%rsp), %rdi
callq 0xe8c8
leaq 0x48(%rsp), %rdi
callq 0xe33a
leaq 0xb0(%rsp), %rdi
callq 0xac38
testq %r14, %r14
leaq 0xd8(%rbx), %r14
movq 0xe8(%rbx), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x1f364
movq %r14, %rdi
callq 0x1f334
leaq 0x1645a(%rip), %rsi     # 0x346e4
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xc152
leaq 0x50(%rbx), %r14
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x201c8
movq %rax, %r15
leaq 0x58(%rbx), %r12
leaq 0x8(%rsp), %rdi
callq 0xac38
cmpq %r12, %r15
je 0x1e532
leaq 0x16419(%rip), %rsi     # 0x346e4
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xc152
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x1f3aa
pushq $0xa
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1f38d
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0xac38
testl %ebp, %ebp
jg 0x1e532
leaq 0x163eb(%rip), %rsi     # 0x346fa
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xc152
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x201c8
movq %rax, %r15
leaq 0x8(%rsp), %rdi
callq 0xac38
cmpq %r12, %r15
je 0x1e390
xorl %edi, %edi
callq 0xa760
movq %rax, %r15
leaq 0x163ac(%rip), %rsi     # 0x346fa
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xc152
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x1f3aa
pushq $0xa
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1f410
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xac38
subq %r15, %r14
imulq $0x3e8, %r14, %r14      # imm = 0x3E8
jmp 0x1e404
leaq 0x16375(%rip), %rsi     # 0x3470c
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xc152
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x201c8
movq %rax, %r15
leaq 0x8(%rsp), %rdi
callq 0xac38
cmpq %r12, %r15
je 0x1e404
leaq 0x16340(%rip), %rsi     # 0x3470c
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xc152
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x1f3aa
pushq $0xa
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1f410
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xac38
jmp 0x1e404
leaq 0x1630d(%rip), %rsi     # 0x34718
leaq 0x70(%rsp), %rdi
leaq 0x2e(%rsp), %rdx
callq 0xc152
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x1f42c
leaq 0x50(%rsp), %r15
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x205b8
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x1f45e
movl %eax, %ebp
leaq 0x70(%rsp), %rdi
callq 0xac38
testb %bpl, %bpl
je 0x1e4e4
leaq 0x162af(%rip), %rsi     # 0x34718
leaq 0x30(%rsp), %rdi
callq 0xee6e
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xeff6
leaq 0x14450(%rip), %rsi     # 0x328d7
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0xfbba
movl %eax, %ebp
movq %r15, %rdi
callq 0xac38
testb %bpl, %bpl
je 0x1e4e4
movb $0x1, 0x80(%rbx)
movq (%rbx), %rdi
leaq 0x8(%rsp), %rcx
andq $0x0, 0x8(%rcx)
movq %rbx, (%rcx)
leaq 0x32d(%rip), %rax       # 0x1e7ee
movq %rax, 0x18(%rcx)
leaq 0x332(%rip), %rax       # 0x1e7fe
movq %rax, 0x10(%rcx)
movq %r14, %rsi
xorl %edx, %edx
callq 0x20bb4
leaq 0x8(%rsp), %rdi
callq 0xe8c8
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0x1daa0
movb $0x1, (%rax)
movq (%rbx), %rdi
leaq 0x8(%rsp), %rcx
andq $0x0, 0x8(%rcx)
movq %rbx, (%rcx)
leaq 0x316(%rip), %rdx       # 0x1e824
movq %rdx, 0x18(%rcx)
leaq 0x317(%rip), %rdx       # 0x1e830
movq %rdx, 0x10(%rcx)
movq %r14, %rsi
movq %rax, %rdx
callq 0x20bb4
leaq 0x8(%rsp), %rdi
callq 0xe8c8
movq %rbx, %rdi
callq 0x1e614
leaq 0x120(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1f468
leaq 0xb0(%rsp), %rdi
callq 0xe1a8
leaq 0x30(%rsp), %rdi
callq 0xc8b0
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1e5f1
jmp 0x1e57f
jmp 0x1e5e2
jmp 0x1e5f1
jmp 0x1e5e2
jmp 0x1e5f1
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xe8c8
jmp 0x1e5f4
jmp 0x1e5f1
jmp 0x1e5f1
jmp 0x1e594
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x1e5ea
jmp 0x1e5f1
jmp 0x1e5e2
jmp 0x1e5f1
jmp 0x1e5e2
jmp 0x1e5f1
jmp 0x1e5e2
jmp 0x1e5f1
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xe8c8
leaq 0x48(%rsp), %rdi
callq 0xe33a
jmp 0x1e5cb
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xac38
jmp 0x1e5dd
movq %rax, %rbx
testq %r14, %r14
jmp 0x1e60b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xac38
jmp 0x1e5f4
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xe1a8
leaq 0x30(%rsp), %rdi
callq 0xc8b0
movq %rbx, %rdi
callq 0xa6c0
nop