// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: url_decode
static size_t url_decode(const char *src, size_t src_len, char *dst,
                         size_t dst_len, int is_form_url_encoded) {
  size_t i, j;
  int a, b;
#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')

  for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
    if (src[i] == '%' &&
        isxdigit(* (const unsigned char *) (src + i + 1)) &&
        isxdigit(* (const unsigned char *) (src + i + 2))) {
      a = tolower(* (const unsigned char *) (src + i + 1));
      b = tolower(* (const unsigned char *) (src + i + 2));
      dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
      i += 2;
    } else if (is_form_url_encoded && src[i] == '+') {
      dst[j] = ' ';
    } else {
      dst[j] = src[i];
    }
  }

  dst[j] = '\0'; /* Null-terminate the destination */

  return j;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movl %r8d, 0x34(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rcx
xorl %eax, %eax
cmpq 0x48(%rsp), %rcx
movb %al, 0x17(%rsp)
jae 0x174a9
movq 0x20(%rsp), %rax
movq 0x38(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
setb %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x174b6
jmp 0x17658
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x25, %eax
jne 0x175ef
callq 0x5610
movq (%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x28(%rsp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x175ef
callq 0x5610
movq (%rax), %rax
movq 0x50(%rsp), %rcx
movq 0x28(%rsp), %rdx
movzbl 0x2(%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x175ef
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movzbl 0x1(%rax,%rcx), %edi
callq 0x5870
movl %eax, 0x1c(%rsp)
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movzbl 0x2(%rax,%rcx), %edi
callq 0x5870
movl %eax, 0x18(%rsp)
callq 0x5610
movq (%rax), %rax
movslq 0x1c(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x1757d
movl 0x1c(%rsp), %eax
subl $0x30, %eax
movl %eax, 0x10(%rsp)
jmp 0x17588
movl 0x1c(%rsp), %eax
subl $0x57, %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
shll $0x4, %eax
movl %eax, 0xc(%rsp)
callq 0x5610
movq (%rax), %rax
movslq 0x18(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x175bb
movl 0x18(%rsp), %eax
subl $0x30, %eax
movl %eax, 0x8(%rsp)
jmp 0x175c6
movl 0x18(%rsp), %eax
subl $0x57, %eax
movl %eax, 0x8(%rsp)
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ecx
orl %ecx, %eax
movb %al, %dl
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x28(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x28(%rsp)
jmp 0x17635
cmpl $0x0, 0x34(%rsp)
je 0x17619
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2b, %eax
jne 0x17619
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x20, (%rax,%rcx)
jmp 0x17633
movq 0x50(%rsp), %rax
movq 0x28(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x17635
jmp 0x17637
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x1747f
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x20(%rsp), %rax
addq $0x58, %rsp
retq