// File: mh0fm4[P]SCDC/src/lib/redirect/redirect/redirect_cache.cc
// Function: redirect_cache_check_cmd
int redirect_cache_check_cmd(redirect_cache_t *rch, const char *cmd, const char *params, scdc_result_t *result)
{
  TRACE_F("cmd: '%s', params: '%s', result: %p", cmd, params, result);

  if (strcmp(cmd, "cache_check") != 0) return 0;

  redirect_cache_reset_params(rch);

  const char *s = params;
  char *r = SCDC_RESULT_STR(result);
  rdint_t r_size = 0;

  sscanf(s, "%" rdint_fmt ":", &rch->nparams);
  s = strchr(s, ':') + 1;
  rdint_t i, j;
  for (i = 0; i < rch->nparams; ++i)
  {
    sscanf(s, "t%d:s%" rdint_fmt ":", &rch->params[i].type, &rch->params[i].size);
    s = strchr(s, ':') + 1;
    s = strchr(s, ':') + 1;
    TRACE_F("param %" rdint_fmt ": type: %d, size: %" rdint_fmt, i, rch->params[i].type, rch->params[i].size);

    rch->params[i].buf = 0;
    rch->params[i].entry_index = 0;

    rdint_t entries[REDIRECT_CACHE_FIND_ENTRIES_MAX];
    rdint_t nentries = redirect_cache_find_entries(rch, rch->params[i].type, rch->params[i].size, entries);

    r_size += sprintf(r + r_size, "%" rdint_fmt ":", nentries);

    for (j = 0; j < nentries; ++j)
    {
      redirect_param_hash_t h = redirect_cache_get_entry_hash(rch, entries[j]);
      r_size += sprintf(r + r_size, "%" redirect_param_hash_fmt ":%" rdint_fmt ":", h, entries[j]);
    }
  }

  TRACE_F("return: %d, result: '%s'", 1, r);

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq 0xc303e(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x945fb(%rip), %rsi     # 0xa5577
leaq 0x94783(%rip), %rdx     # 0xa5706
movb $0x0, %al
callq 0xc9a0
movq 0xc301f(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
leaq 0x94778(%rip), %rsi     # 0xa571f
movb $0x0, %al
callq 0xc9a0
movq 0xc2ffb(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x948e9(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x18(%rbp), %rdi
leaq 0x94631(%rip), %rsi     # 0xa5602
callq 0xc970
cmpl $0x0, %eax
je 0x10fe7
movl $0x0, -0x4(%rbp)
jmp 0x112a9
movq -0x10(%rbp), %rdi
callq 0x10520
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
leaq 0x9460b(%rip), %rsi     # 0xa562a
movb $0x0, %al
callq 0xc640
movq -0x30(%rbp), %rdi
movl $0x3a, %esi
callq 0xc220
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x11248
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x18, %rdx
imulq $0x28, -0x48(%rbp), %rax
addq %rax, %rdx
movq -0x10(%rbp), %rcx
addq $0x18, %rcx
imulq $0x28, -0x48(%rbp), %rax
addq %rax, %rcx
addq $0x8, %rcx
leaq 0x945aa(%rip), %rsi     # 0xa562f
movb $0x0, %al
callq 0xc640
movq -0x30(%rbp), %rdi
movl $0x3a, %esi
callq 0xc220
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl $0x3a, %esi
callq 0xc220
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq 0xc2ef1(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x944ae(%rip), %rsi     # 0xa5577
leaq 0x94636(%rip), %rdx     # 0xa5706
movb $0x0, %al
callq 0xc9a0
movq 0xc2ed2(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
addq $0x18, %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x18, %rax
imulq $0x28, -0x48(%rbp), %rsi
addq %rsi, %rax
movq 0x8(%rax), %r8
leaq 0x94531(%rip), %rsi     # 0xa5643
movb $0x0, %al
callq 0xc9a0
movq 0xc2e90(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x9477e(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x10(%rbp), %rax
addq $0x18, %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
addq $0x18, %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x18, %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %esi
movq -0x10(%rbp), %rax
addq $0x18, %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
leaq -0xd0(%rbp), %rcx
callq 0x112c0
movq %rax, -0xd8(%rbp)
movq -0x38(%rbp), %rdi
addq -0x40(%rbp), %rdi
movq -0xd8(%rbp), %rdx
leaq 0x94476(%rip), %rsi     # 0xa562a
movb $0x0, %al
callq 0xc0f0
cltq
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0xd8(%rbp), %rax
jge 0x11235
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rax
movq -0xd0(%rbp,%rax,8), %rsi
callq 0x11370
movl %eax, -0xdc(%rbp)
movq -0x38(%rbp), %rdi
addq -0x40(%rbp), %rdi
movl -0xdc(%rbp), %edx
movq -0x50(%rbp), %rax
movq -0xd0(%rbp,%rax,8), %rcx
leaq 0x9452d(%rip), %rsi     # 0xa5743
movb $0x0, %al
callq 0xc0f0
cltq
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x111cd
jmp 0x11237
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x11044
jmp 0x1124a
movq 0xc2d5f(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x9431c(%rip), %rsi     # 0xa5577
leaq 0x944a4(%rip), %rdx     # 0xa5706
movb $0x0, %al
callq 0xc9a0
movq 0xc2d40(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x38(%rbp), %rcx
leaq 0x944cf(%rip), %rsi     # 0xa574d
movl $0x1, %edx
movb $0x0, %al
callq 0xc9a0
movq 0xc2d1f(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x9460d(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)