// File: lega911[P]ijson/src/netfilter.cpp
// Function: NetFilter::NetFilter(Slice&)
NetFilter::NetFilter(Slice &mask) {
    std::string ip;
    int bits = 32;
    for(int i=0;i<mask.size();i++) {
        if(mask.ptr()[i] == '/') {
            ip.append(mask.ptr(), i);
            mask.remove(i + 1);
            bits = mask.atoi();
            break;
        }
    };
    if(ip.empty()) ip = mask.as_string();
    _ip = inet_addr(ip.c_str());

    _mask = 0xffffffff;
    bits = 32 - bits;
    for(int i=0;i<bits;i++) _mask = _mask << 1;
    // swap bytes
    char *b4 = (char*)&_mask;
    char t = b4[0]; b4[0] = b4[3]; b4[3] = t;
    t = b4[1]; b4[1] = b4[2]; b4[2] = t;

    _ip = _ip & _mask;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x193c0
movl $0x20, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1e6d0
movl %eax, -0x8c(%rbp)
jmp 0x2738f
movl -0x90(%rbp), %eax
movl -0x8c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x27449
movq -0x10(%rbp), %rdi
callq 0x1e6f0
movq %rax, -0x98(%rbp)
jmp 0x273b5
movq -0x98(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x27439
movq -0x10(%rbp), %rdi
callq 0x1e6f0
movq %rax, -0xa0(%rbp)
jmp 0x273db
movq -0xa0(%rbp), %rsi
movslq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x19070
jmp 0x273f1
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
incl %esi
callq 0x1ef50
jmp 0x27401
movq -0x10(%rbp), %rdi
callq 0x1efb0
movq %rax, -0xa8(%rbp)
jmp 0x27413
movq -0xa8(%rbp), %rax
movl %eax, -0x34(%rbp)
jmp 0x27449
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x191e0
jmp 0x27546
jmp 0x2743b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x27375
leaq -0x30(%rbp), %rdi
callq 0x19470
testb $0x1, %al
jne 0x27458
jmp 0x27482
movq -0x10(%rbp), %rsi
leaq -0x68(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f340
jmp 0x2746c
leaq -0x30(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x19370
leaq -0x68(%rbp), %rdi
callq 0x191e0
leaq -0x30(%rbp), %rdi
callq 0x19130
movq %rax, %rdi
callq 0x192f0
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, (%rax)
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movl $0x20, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x274d9
movq -0x88(%rbp), %rax
movl 0x4(%rax), %ecx
shll %ecx
movl %ecx, 0x4(%rax)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x274b7
movq -0x88(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x78(%rbp)
movq -0x78(%rbp), %rcx
movb (%rcx), %cl
movb %cl, -0x79(%rbp)
movq -0x78(%rbp), %rcx
movb 0x3(%rcx), %dl
movq -0x78(%rbp), %rcx
movb %dl, (%rcx)
movb -0x79(%rbp), %dl
movq -0x78(%rbp), %rcx
movb %dl, 0x3(%rcx)
movq -0x78(%rbp), %rcx
movb 0x1(%rcx), %cl
movb %cl, -0x79(%rbp)
movq -0x78(%rbp), %rcx
movb 0x2(%rcx), %dl
movq -0x78(%rbp), %rcx
movb %dl, 0x1(%rcx)
movb -0x79(%rbp), %dl
movq -0x78(%rbp), %rcx
movb %dl, 0x2(%rcx)
movl (%rax), %ecx
andl 0x4(%rax), %ecx
movl %ecx, (%rax)
leaq -0x30(%rbp), %rdi
callq 0x191e0
addq $0xb0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x194a0
nop