// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_url_decode
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len,
                  int is_form_url_encoded) {
  int i, j, 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] == '%') {
      if (i < src_len - 2 && 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 {
        return -1;
      }
    } else if (is_form_url_encoded && src[i] == '+') {
      dst[j] = ' ';
    } else {
      dst[j] = src[i];
    }
  }

  dst[j] = '\0'; /* Null-terminate the destination */

  return i >= src_len ? j : -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x39(%rbp)
jge 0x12506
movl -0x30(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x12512
jmp 0x1269f
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x25, %eax
jne 0x12649
movl -0x2c(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x1263b
callq 0x36a0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x1263b
callq 0x36a0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movzbl 0x2(%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x1263b
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %edi
callq 0x3410
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl 0x2(%rax,%rcx), %edi
callq 0x3410
movl %eax, -0x38(%rbp)
callq 0x36a0
movq (%rax), %rax
movslq -0x34(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x125db
movl -0x34(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x40(%rbp)
jmp 0x125e4
movl -0x34(%rbp), %eax
subl $0x57, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
shll $0x4, %eax
movl %eax, -0x44(%rbp)
callq 0x36a0
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x12612
movl -0x38(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x48(%rbp)
jmp 0x1261b
movl -0x38(%rbp), %eax
subl $0x57, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movl -0x48(%rbp), %ecx
orl %ecx, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0x12647
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x126cb
jmp 0x12686
cmpl $0x0, -0x28(%rbp)
je 0x1266e
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2b, %eax
jne 0x1266e
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb $0x20, (%rax,%rcx)
jmp 0x12684
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x12686
jmp 0x12688
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x124e8
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x126bb
movl -0x30(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x126c5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x4c(%rbp)
jmp 0x126c5
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)