// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, %rbx
movq 0x80(%rdi), %rdi
testq %rdi, %rdi
je 0x11f62
movl %esi, %ebp
xorl %r15d, %r15d
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x11d0e
testq %rax, %rax
je 0x12001
movq %rax, %r14
bswapl %ebp
movl $0x2d, %r12d
leaq 0x1c(%rsp), %r15
movl $0x20, 0x10(%rsp)
movq 0x28(%rsp), %r13
movq %r13, %rdi
leaq 0x3f09(%rip), %rsi      # 0x15d52
leaq 0xf(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x20(%rsp), %r8
movq %r15, %r9
xorl %eax, %eax
leaq 0x14(%rsp), %r10
pushq %r10
leaq 0x20(%rsp), %r10
pushq %r10
callq 0x5490
addq $0x10, %rsp
cmpl $0x5, %eax
jne 0x11f6d
movzbl 0xf(%rsp), %eax
cmpl $0x2b, %eax
je 0x11e90
cmpl $0x2d, %eax
jne 0x11fd5
cmpl $0xff, 0x24(%rsp)
ja 0x11f92
cmpl $0xff, 0x20(%rsp)
ja 0x11f92
cmpl $0xff, 0x1c(%rsp)
ja 0x11f92
cmpl $0x100, 0x18(%rsp)      # imm = 0x100
jae 0x11f92
movslq 0x14(%rsp), %rdi
addq %r13, %rdi
leaq 0x3ef0(%rip), %rsi      # 0x15dc7
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x5490
testl %eax, %eax
setne %cl
movl 0x10(%rsp), %eax
cmpl $0x21, %eax
setae %dl
andb %cl, %dl
cmpb $0x1, %dl
je 0x11fa9
movl 0x24(%rsp), %ecx
shll $0x18, %ecx
movl 0x20(%rsp), %edx
shll $0x10, %edx
orl %ecx, %edx
movl 0x1c(%rsp), %esi
shll $0x8, %esi
orl %edx, %esi
orl 0x18(%rsp), %esi
movl %eax, %ecx
negb %cl
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
testl %eax, %eax
cmovel %eax, %edx
andl %ebp, %edx
cmpl %edx, %esi
movsbl 0xf(%rsp), %eax
cmovel %eax, %r12d
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x11d0e
movq %rax, %r14
testq %rax, %rax
jne 0x11e32
xorl %r15d, %r15d
cmpl $0x2b, %r12d
sete %r15b
jmp 0x12001
movl $0x1, %r15d
jmp 0x12001
movq %rbx, 0xaecc(%rip)      # 0x1ce40
leaq 0xaa6d(%rip), %rdi      # 0x1c9e8
leaq 0x3de0(%rip), %rsi      # 0x15d62
leaq 0x3dfd(%rip), %rdx      # 0x15d86
xorl %eax, %eax
callq 0xfb6a
jmp 0x11ffb
movq %rbx, 0xaea7(%rip)      # 0x1ce40
leaq 0xaa48(%rip), %rdi      # 0x1c9e8
leaq 0x3e07(%rip), %rsi      # 0x15dae
jmp 0x11fea
movq %rbx, 0xae90(%rip)      # 0x1ce40
leaq 0xaa31(%rip), %rdi      # 0x1c9e8
movl 0x14(%rsp), %ecx
leaq 0x3e09(%rip), %rsi      # 0x15dcb
leaq 0x3dbd(%rip), %rdx      # 0x15d86
movq %r13, %r8
xorl %eax, %eax
callq 0xfb6a
jmp 0x11ffb
movq %rbx, 0xae64(%rip)      # 0x1ce40
leaq 0xaa05(%rip), %rdi      # 0x1c9e8
leaq 0x3da6(%rip), %rsi      # 0x15d90
leaq 0x3d95(%rip), %rdx      # 0x15d86
movq %r13, %rcx
xorl %eax, %eax
callq 0xfb6a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq