// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x80(%rdi), %r15
testq %r15, %r15
je 0xdf11
movq %rdi, 0x20(%rsp)
movl 0x8(%rsi), %r14d
bswapl %r14d
pushq $0x2d
popq %r13
leaq 0x14(%rsp), %rbp
pushq $-0x1
popq %rbx
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0xdcda
testq %rax, %rax
je 0xdf19
movq %rax, %r15
movl $0x20, 0x8(%rsp)
movq 0x28(%rsp), %r12
movq %r12, %rdi
leaq 0x4f30(%rip), %rsi      # 0x12d52
leaq 0x7(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq %rbp, %r9
xorl %eax, %eax
leaq 0xc(%rsp), %r10
pushq %r10
leaq 0x18(%rsp), %r10
pushq %r10
callq 0x5470
popq %rcx
popq %rdx
cmpl $0x5, %eax
jne 0xdf27
movzbl 0x7(%rsp), %eax
cmpl $0x2b, %eax
je 0xde67
cmpl $0x2d, %eax
jne 0xdf9e
cmpl $0xff, 0x1c(%rsp)
ja 0xdf51
cmpl $0xff, 0x18(%rsp)
ja 0xdf51
cmpl $0xff, 0x14(%rsp)
ja 0xdf51
cmpl $0x100, 0x10(%rsp)      # imm = 0x100
jae 0xdf51
movslq 0xc(%rsp), %rdi
addq %r12, %rdi
leaq 0x4f19(%rip), %rsi      # 0x12dc7
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x5470
testl %eax, %eax
setne %cl
movl 0x8(%rsp), %eax
cmpl $0x21, %eax
setae %dl
andb %cl, %dl
cmpb $0x1, %dl
je 0xdf6d
movl 0x1c(%rsp), %ecx
shll $0x18, %ecx
movl 0x18(%rsp), %edx
shll $0x10, %edx
orl %ecx, %edx
movl 0x14(%rsp), %esi
shll $0x8, %esi
orl %edx, %esi
orl 0x10(%rsp), %esi
movl %eax, %ecx
negb %cl
movl %ebx, %edx
shll %cl, %edx
testl %eax, %eax
cmovel %eax, %edx
andl %r14d, %edx
cmpl %edx, %esi
movsbl 0x7(%rsp), %eax
cmovel %eax, %r13d
jmp 0xddf0
pushq $0x1
popq %rbx
jmp 0xdfc9
xorl %ebx, %ebx
cmpl $0x2b, %r13d
sete %bl
jmp 0xdfc9
movq 0x20(%rsp), %rax
movq %rax, 0xcf1d(%rip)      # 0x1ae50
leaq 0xcabe(%rip), %rdi      # 0x1a9f8
leaq 0x4e21(%rip), %rsi      # 0x12d62
leaq 0x4e3e(%rip), %rdx      # 0x12d86
xorl %eax, %eax
callq 0xcd67
jmp 0xdfc9
movq 0x20(%rsp), %rax
movq %rax, 0xcef3(%rip)      # 0x1ae50
leaq 0xca94(%rip), %rdi      # 0x1a9f8
leaq 0x4e43(%rip), %rsi      # 0x12dae
jmp 0xdfb8
movq 0x20(%rsp), %rax
movq %rax, 0xced7(%rip)      # 0x1ae50
leaq 0xca78(%rip), %rdi      # 0x1a9f8
movl 0xc(%rsp), %ecx
leaq 0x4e40(%rip), %rsi      # 0x12dcb
leaq 0x4df4(%rip), %rdx      # 0x12d86
movq %r12, %r8
xorl %eax, %eax
callq 0xcd67
jmp 0xdfc9
movq 0x20(%rsp), %rax
movq %rax, 0xcea6(%rip)      # 0x1ae50
leaq 0xca47(%rip), %rdi      # 0x1a9f8
leaq 0x4dd8(%rip), %rsi      # 0x12d90
leaq 0x4dc7(%rip), %rdx      # 0x12d86
movq %r12, %rcx
xorl %eax, %eax
callq 0xcd67
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq