// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: check_acl
static int check_acl(struct mg_context *ctx, const struct usa *usa) {
  int a, b, c, d, n, mask, allowed;
  char flag;
  uint32_t acl_subnet, acl_mask, remote_ip;
  struct vec vec;
  const char *list = ctx->config[ACCESS_CONTROL_LIST];

  if (list == NULL) {
    return 1;
  }

  (void) memcpy(&remote_ip, &usa->u.sin.sin_addr, sizeof(remote_ip));

  // If any ACL is set, deny by default
  allowed = '-';

  while ((list = next_option(list, &vec, NULL)) != NULL) {
    mask = 32;

    if (sscanf(vec.ptr, "%c%d.%d.%d.%d%n", &flag, &a, &b, &c, &d, &n) != 5) {
      cry(fc(ctx), "%s: subnet must be [+|-]x.x.x.x[/x]", __func__);
      return -1;
    } else if (flag != '+' && flag != '-') {
      cry(fc(ctx), "%s: flag must be + or -: [%s]", __func__, vec.ptr);
      return -1;
    } else if (!isbyte(a)||!isbyte(b)||!isbyte(c)||!isbyte(d)) {
      cry(fc(ctx), "%s: bad ip address: [%s]", __func__, vec.ptr);
      return -1;
    } else if (sscanf(vec.ptr + n, "/%d", &mask) == 0) {
      // Do nothing, no mask specified
    } else if (mask < 0 || mask > 32) {
      cry(fc(ctx), "%s: bad subnet mask: %d [%s]", __func__, n, vec.ptr);
      return -1;
    }

    acl_subnet = (a << 24) | (b << 16) | (c << 8) | d;
    acl_mask = mask ? 0xffffffffU << (32 - mask) : 0;

    if (acl_subnet == (ntohl(remote_ip) & acl_mask)) {
      allowed = flag;
    }
  }

  return allowed == '+';
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq 0x68(%rsp), %rax
movq 0x80(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x1aed4
movl $0x1, 0x74(%rsp)
jmp 0x1b135
movq 0x60(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x34(%rsp)
movl $0x2d, 0x44(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1ab00
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x1b124
movl $0x20, 0x48(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x7e3c(%rip), %rsi      # 0x22d5a
leaq 0x43(%rsp), %rdx
leaq 0x5c(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x54(%rsp), %r9
leaq 0x50(%rsp), %r10
leaq 0x4c(%rsp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x5540
cmpl $0x5, %eax
je 0x1af80
movq 0x68(%rsp), %rdi
callq 0x18750
movq %rax, %rdi
leaq 0x7e05(%rip), %rsi      # 0x22d6a
leaq 0x7e22(%rip), %rdx      # 0x22d8e
movb $0x0, %al
callq 0x184e0
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x1b135
movsbl 0x43(%rsp), %eax
cmpl $0x2b, %eax
je 0x1afc8
movsbl 0x43(%rsp), %eax
cmpl $0x2d, %eax
je 0x1afc8
movq 0x68(%rsp), %rdi
callq 0x18750
movq %rax, %rdi
movq 0x20(%rsp), %rcx
leaq 0x7deb(%rip), %rsi      # 0x22d98
leaq 0x7dda(%rip), %rdx      # 0x22d8e
movb $0x0, %al
callq 0x184e0
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x1b135
movl 0x5c(%rsp), %edi
callq 0x1b140
cmpl $0x0, %eax
je 0x1b000
movl 0x58(%rsp), %edi
callq 0x1b140
cmpl $0x0, %eax
je 0x1b000
movl 0x54(%rsp), %edi
callq 0x1b140
cmpl $0x0, %eax
je 0x1b000
movl 0x50(%rsp), %edi
callq 0x1b140
cmpl $0x0, %eax
jne 0x1b034
movq 0x68(%rsp), %rdi
callq 0x18750
movq %rax, %rdi
movq 0x20(%rsp), %rcx
leaq 0x7d9d(%rip), %rsi      # 0x22db6
leaq 0x7d6e(%rip), %rdx      # 0x22d8e
movb $0x0, %al
callq 0x184e0
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x1b135
movq 0x20(%rsp), %rdi
movslq 0x4c(%rsp), %rax
addq %rax, %rdi
leaq 0x7d87(%rip), %rsi      # 0x22dcf
leaq 0x48(%rsp), %rdx
movb $0x0, %al
callq 0x5540
cmpl $0x0, %eax
jne 0x1b05b
jmp 0x1b0a3
cmpl $0x0, 0x48(%rsp)
jl 0x1b069
cmpl $0x20, 0x48(%rsp)
jle 0x1b0a1
movq 0x68(%rsp), %rdi
callq 0x18750
movq %rax, %rdi
movl 0x4c(%rsp), %ecx
movq 0x20(%rsp), %r8
leaq 0x7d4d(%rip), %rsi      # 0x22dd3
leaq 0x7d01(%rip), %rdx      # 0x22d8e
movb $0x0, %al
callq 0x184e0
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
jmp 0x1b135
jmp 0x1b0a3
jmp 0x1b0a5
jmp 0x1b0a7
jmp 0x1b0a9
movl 0x5c(%rsp), %eax
shll $0x18, %eax
movl 0x58(%rsp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl 0x54(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
orl 0x50(%rsp), %eax
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x48(%rsp)
je 0x1b0e7
movl $0x20, %ecx
subl 0x48(%rsp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %eax, 0x14(%rsp)
jmp 0x1b0ef
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x1b0ef
movl 0x14(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x34(%rsp), %edi
callq 0x5740
movl %eax, %ecx
movl 0x10(%rsp), %eax
andl 0x38(%rsp), %ecx
cmpl %ecx, %eax
jne 0x1b11f
movsbl 0x43(%rsp), %eax
movl %eax, 0x44(%rsp)
jmp 0x1aee8
cmpl $0x2b, 0x44(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nop