// File: /workspace/github_cpp_makefile_star2_O1/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 0x12bd1
movl 0x8(%rsi), %r13d
xorl %r15d, %r15d
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x12976
testq %rax, %rax
je 0x12c70
movq %rax, %r14
bswapl %r13d
movl $0x2d, %ebp
leaq 0x1c(%rsp), %r15
movl $0x20, 0x10(%rsp)
movq 0x28(%rsp), %r12
movq %r12, %rdi
leaq 0x3299(%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 0x12bdc
movzbl 0xf(%rsp), %eax
cmpl $0x2b, %eax
je 0x12b00
cmpl $0x2d, %eax
jne 0x12c44
cmpl $0xff, 0x24(%rsp)
ja 0x12c01
cmpl $0xff, 0x20(%rsp)
ja 0x12c01
cmpl $0xff, 0x1c(%rsp)
ja 0x12c01
cmpl $0x100, 0x18(%rsp)      # imm = 0x100
jae 0x12c01
movslq 0x14(%rsp), %rdi
addq %r12, %rdi
leaq 0x3280(%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 0x12c18
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 %r13d, %edx
cmpl %edx, %esi
movsbl 0xf(%rsp), %eax
cmovel %eax, %ebp
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x12976
movq %rax, %r14
testq %rax, %rax
jne 0x12aa2
xorl %r15d, %r15d
cmpl $0x2b, %ebp
sete %r15b
jmp 0x12c70
movl $0x1, %r15d
jmp 0x12c70
movq %rbx, 0xa25d(%rip)      # 0x1ce40
leaq 0x9dfe(%rip), %rdi      # 0x1c9e8
leaq 0x3171(%rip), %rsi      # 0x15d62
leaq 0x318e(%rip), %rdx      # 0x15d86
xorl %eax, %eax
callq 0xfc79
jmp 0x12c6a
movq %rbx, 0xa238(%rip)      # 0x1ce40
leaq 0x9dd9(%rip), %rdi      # 0x1c9e8
leaq 0x3198(%rip), %rsi      # 0x15dae
jmp 0x12c59
movq %rbx, 0xa221(%rip)      # 0x1ce40
leaq 0x9dc2(%rip), %rdi      # 0x1c9e8
movl 0x14(%rsp), %ecx
leaq 0x319a(%rip), %rsi      # 0x15dcb
leaq 0x314e(%rip), %rdx      # 0x15d86
movq %r12, %r8
xorl %eax, %eax
callq 0xfc79
jmp 0x12c6a
movq %rbx, 0xa1f5(%rip)      # 0x1ce40
leaq 0x9d96(%rip), %rdi      # 0x1c9e8
leaq 0x3137(%rip), %rsi      # 0x15d90
leaq 0x3126(%rip), %rdx      # 0x15d86
movq %r12, %rcx
xorl %eax, %eax
callq 0xfc79
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq