// File: /workspace/github_cpp_makefile_star2_O3/sharmaeklavya2[P]ddos-on-anycast/src/lib/network.cpp
// Function: Network::long_sanity_check() const
bool Network::long_sanity_check() const {
    if(!basic_sanity_check()) {
        return false;
    }
    int s = 0;

    typedef const nbrs_list_t* pnbrs_list_t;
    pnbrs_list_t nbrs_ptrs[] = {&in_nbrs, &side_nbrs, &up_nbrs, &down_nbrs};
    const char* nbrs_names[] = {"in_nbrs", "side_nbrs", "up_nbrs", "down_nbrs"};

    // consistency of nid and netsize
    ivec netsize2(size(), 0);
    for(int vnode: nid) {
        if(vnode >= 0) {
            netsize2[vnode]++;
        }
    }

    int height2 = 0;
    for(int u=0; u<size(); ++u) {
        if(netsize[u] == 0 && depth[u] > height2) {
            height2 = depth[u];
        }
    }
    if(height2 != height()) {
        fprintf(stderr, "height should be %d instead of %d\n", height2, height());
        return false;
    }

    for(int i=0; i<=height(); ++i) {
        for(int u: depthwise[i]) {
            if(depth[u] != i) {
                fprintf(stderr, "%d is in depthwise[%d] but has depth %d\n", u, i, depth[u]);
            }
        }
    }

    for(int u=0; u<size(); ++u) {

        // consistency of nid and netsize
        if(netsize[u] != netsize2[u]) {
            fprintf(stderr, "netsize[%d] is %d instead of %d\n", u, netsize[u], netsize2[u]);
            return false;
        }

        // no self-loops are allowed
        for(int i=0; i<4; ++i) {
            for(int v: (*(nbrs_ptrs[i]))[u]) {
                if(v == u) {
                    fprintf(stderr, "%s[%d] contains itself\n", nbrs_names[i], u);
                    return false;
                }
            }
        }

        if(is_virtual(u)) {
            // virtual node shouldn't have any in_nbrs
            if(in_nbrs[u].size() > 0) {
                fprintf(stderr, "virtual node %d has in_nbrs ", u);
                cerr << in_nbrs[u] << endl;
                return false;
            }
            /*
            else if(down_nbrs[u].size() > 0) {
                fprintf(stderr, "virtual node %d has down_nbrs ", u);
                cerr << down_nbrs[u] << endl;
                return false;
            }
            */
        }
        else {
            s += degree(u);
            // Network should be symmetric because it is undirected
            for(int v: in_nbrs[u]) {
                if(find(in_nbrs[v], u) == in_nbrs[v].end()) {
                    fprintf(stderr, "in_nbrs[%d] has %d but in_nbrs[%d] doesn't have %d\n", u, v, v, u);
                    return false;
                }
                if(is_virtual(v)) {
                    fprintf(stderr, "in_nbrs[%d] has virtual node %d\n", u, v);
                    return false;
                }
            }
            for(int v: side_nbrs[u]) {
                if(find(side_nbrs[v], u) == side_nbrs[v].end()) {
                    fprintf(stderr, "side_nbrs[%d] has %d but side_nbrs[%d] doesn't have %d\n", u, v, v, u);
                    return false;
                }
                if(is_virtual(v)) {
                    fprintf(stderr, "side_nbrs[%d] has virtual node %d\n", u, v);
                    return false;
                }
                /*
                int nid_u = nid[u];
                if(nid_u >= 0) {
                    if(find(side_nbrs[nid_u], v) == side_nbrs[nid_u].end()) {
                        fprintf(stderr, "%d has a side_nbr %d but %d's nid doesn't\n", u, v, u);
                        return false;
                    }
                }
                */
            }
            for(int v: up_nbrs[u]) {
                if(find(down_nbrs[v], u) == down_nbrs[v].end()) {
                    fprintf(stderr, "up_nbrs[%d] has %d but down_nbrs[%d] doesn't have %d\n", u, v, v, u);
                    return false;
                }
                if(is_virtual(v)) {
                    fprintf(stderr, "up_nbrs[%d] has virtual node %d\n", u, v);
                    return false;
                }
                /*
                int nid_u = nid[u];
                if(nid_u >= 0) {
                    if(find(up_nbrs[nid_u], v) == up_nbrs[nid_u].end()) {
                        fprintf(stderr, "%d has a up_nbr %d but %d's nid doesn't\n", u, v, u);
                        return false;
                    }
                }
                */
            }
            for(int v: down_nbrs[u]) {
                if(find(up_nbrs[v], u) == up_nbrs[v].end()) {
                    fprintf(stderr, "down_nbrs[%d] has %d but up_nbrs[%d] doesn't have %d\n", u, v, v, u);
                    return false;
                }
                if(is_virtual(v)) {
                    fprintf(stderr, "down_nbrs[%d] has virtual node %d\n", u, v);
                    return false;
                }
            }
        }
    }
    if(s % 2 != 0) {
        fprintf(stderr, "Degree sum is odd.\n");
        return false;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
callq 0x30ce
testb %al, %al
je 0x32e6
leaq 0x48(%rbx), %rax
movq %rax, 0x28(%rsp)
movq %rax, 0x60(%rsp)
leaq 0x60(%rbx), %rax
movq %rax, 0x40(%rsp)
movq %rax, 0x68(%rsp)
leaq 0x78(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %rax, 0x70(%rsp)
leaq 0x90(%rbx), %rax
movq %rax, 0x38(%rsp)
movq %rax, 0x78(%rsp)
movq 0x20(%rbx), %rax
subq 0x18(%rbx), %rax
shrq $0x2, %rax
movslq %eax, %rsi
leaq 0xc(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x48(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x3b06
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rcx, %rax
je 0x32aa
movq 0x48(%rsp), %rdx
movslq (%rax), %rsi
testq %rsi, %rsi
js 0x32a1
incl (%rdx,%rsi,4)
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x3296
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0x32ed
movq 0x30(%rbx), %rsi
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edi, %edi
xorl %edx, %edx
cmpl $0x0, (%rax,%rdi,4)
jne 0x32dc
movl (%rsi,%rdi,4), %r8d
cmpl %edx, %r8d
cmovgl %r8d, %edx
incq %rdi
cmpq %rdi, %rcx
jne 0x32cb
jmp 0x32ef
xorl %ebp, %ebp
jmp 0x3672
xorl %edx, %edx
movq 0xa8(%rbx), %rax
movq 0xb0(%rbx), %rsi
movq %rsi, %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
decl %ecx
cmpl %ecx, %edx
jne 0x3686
movq 0xdcb2(%rip), %rbp      # 0x10fd0
leaq 0x8f29(%rip), %r14      # 0xc24e
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %r12
movq 0x8(%rax,%rcx,8), %r13
cmpq %r13, %r12
jne 0x334f
jmp 0x3377
movq (%rbp), %rdi
movq %r14, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x21b0
jmp 0x3360
movslq (%r12), %rdx
movq 0x30(%rbx), %rax
movl (%rax,%rdx,4), %r8d
cmpq %r8, %r15
jne 0x333c
addq $0x4, %r12
cmpq %r13, %r12
jne 0x334f
movq 0xa8(%rbx), %rax
movq 0xb0(%rbx), %rsi
leaq 0x1(%r15), %rcx
movq %rsi, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
imull $0xaaaaaaab, %edx, %edx # imm = 0xAAAAAAAB
decl %edx
movslq %edx, %rdx
cmpq %rdx, %r15
movq %rcx, %r15
jl 0x3328
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movb $0x1, %bpl
testl %ecx, %ecx
jle 0x3663
xorl %r14d, %r14d
xorl %r9d, %r9d
movl (%rax,%r14,4), %ecx
movq 0x48(%rsp), %rdx
movl (%rdx,%r14,4), %r8d
cmpl %r8d, %ecx
jne 0x376c
leaq (%r14,%r14,2), %r12
xorl %edx, %edx
movq 0x60(%rsp,%rdx,8), %rsi
movq (%rsi), %rdi
movq (%rdi,%r12,8), %rsi
movq 0x8(%rdi,%r12,8), %rdi
cmpq %rdi, %rsi
je 0x33fc
movl (%rsi), %r8d
cmpq %r8, %r14
je 0x3638
addq $0x4, %rsi
jmp 0x33e5
incq %rdx
cmpq $0x4, %rdx
jne 0x33d4
testl %ecx, %ecx
jle 0x3425
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx,%r12,8), %rdx
cmpq (%rcx,%r12,8), %rdx
je 0x360e
jmp 0x378e
movl %r9d, 0x10(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3878
movl %eax, 0x34(%rsp)
movq 0x48(%rbx), %rcx
movq (%rcx,%r12,8), %r15
movq 0x8(%rcx,%r12,8), %rax
movq %rax, 0x18(%rsp)
cmpq %rax, %r15
je 0x34a3
movslq (%r15), %r13
leaq (,%r13,2), %rbp
addq %r13, %rbp
movq (%rcx,%rbp,8), %rdi
movq 0x8(%rcx,%rbp,8), %rsi
movl %r14d, 0xc(%rsp)
leaq 0xc(%rsp), %rdx
callq 0x3c82
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx,%rbp,8), %rax
je 0x369e
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jg 0x36b1
addq $0x4, %r15
cmpq 0x18(%rsp), %r15
jne 0x3450
movq 0x40(%rsp), %rax
movq (%rax), %rcx
movq (%rcx,%r12,8), %r15
movq 0x8(%rcx,%r12,8), %rax
movq %rax, 0x18(%rsp)
cmpq %rax, %r15
je 0x3511
movslq (%r15), %r13
leaq (,%r13,2), %rbp
addq %r13, %rbp
movq (%rcx,%rbp,8), %rdi
movq 0x8(%rcx,%rbp,8), %rsi
movl %r14d, 0xc(%rsp)
leaq 0xc(%rsp), %rdx
callq 0x3c82
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx,%rbp,8), %rax
je 0x36c4
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jg 0x36d7
addq $0x4, %r15
cmpq 0x18(%rsp), %r15
jne 0x34be
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %r15
movq 0x8(%rax,%r12,8), %rdx
movq 0x38(%rsp), %rax
movq (%rax), %rcx
movq %rdx, 0x18(%rsp)
cmpq %rdx, %r15
je 0x3587
movslq (%r15), %r13
leaq (,%r13,2), %rbp
addq %r13, %rbp
movq (%rcx,%rbp,8), %rdi
movq 0x8(%rcx,%rbp,8), %rsi
movl %r14d, 0xc(%rsp)
leaq 0xc(%rsp), %rdx
callq 0x3c82
movq 0x38(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx,%rbp,8), %rax
je 0x36ea
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jg 0x3708
addq $0x4, %r15
cmpq 0x18(%rsp), %r15
jne 0x3534
movl 0x10(%rsp), %r9d
addl 0x34(%rsp), %r9d
movq (%rcx,%r12,8), %r15
movq 0x8(%rcx,%r12,8), %r13
cmpq %r13, %r15
je 0x3607
movl %r9d, 0x10(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movslq (%r15), %r12
leaq (%r12,%r12,2), %rbp
movq (%rcx,%rbp,8), %rdi
movq 0x8(%rcx,%rbp,8), %rsi
movl %r14d, 0xc(%rsp)
leaq 0xc(%rsp), %rdx
callq 0x3c82
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx,%rbp,8), %rax
je 0x3723
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
movq 0xd9e2(%rip), %rdx      # 0x10fd0
jg 0x374e
addq $0x4, %r15
cmpq %r13, %r15
jne 0x35ac
movb $0x1, %bpl
movl 0x10(%rsp), %r9d
jmp 0x360e
movq 0x18(%rbx), %rax
movb $0x1, %bpl
incq %r14
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r14
jl 0x33b8
testb $0x1, %r9b
je 0x3663
callq 0x2298
jmp 0x37cc
movq 0xd991(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8e67(%rip), %rax      # 0xc4b0
movslq (%rax,%rdx,4), %rdx
addq %rax, %rdx
leaq 0x8c41(%rip), %rsi      # 0xc298
xorl %ebp, %ebp
movl %r14d, %ecx
xorl %eax, %eax
callq 0x21b0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3672
callq 0x2150
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd943(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8b94(%rip), %rsi      # 0xc22b
xorl %ebp, %ebp
jmp 0x3760
movq 0xd92b(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8c1e(%rip), %rsi      # 0xc2cd
jmp 0x36fb
movq 0xd918(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8c3f(%rip), %rsi      # 0xc301
jmp 0x3719
movq 0xd905(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8c4d(%rip), %rsi      # 0xc322
jmp 0x36fb
movq 0xd8f2(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8c72(%rip), %rsi      # 0xc35a
jmp 0x3719
movq 0xd8df(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8c82(%rip), %rsi      # 0xc37d
xorl %ebp, %ebp
movl %r14d, %edx
movl %r13d, %ecx
movl %r13d, %r8d
jmp 0x373f
movq 0xd8c1(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8c9a(%rip), %rsi      # 0xc3b3
xorl %ebp, %ebp
movl %r14d, %edx
movl %r13d, %ecx
jmp 0x3760
movq 0xd8a6(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8ca0(%rip), %rsi      # 0xc3d4
xorl %ebp, %ebp
movl %r14d, %edx
movl %r12d, %ecx
movl %r12d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x21b0
jmp 0x3663
movq (%rdx), %rdi
leaq 0x8cb2(%rip), %rsi      # 0xc40a
xorl %ebp, %ebp
movl %r14d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x21b0
jmp 0x3663
movq 0xd85d(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8afa(%rip), %rsi      # 0xc277
xorl %ebp, %ebp
movl %r14d, %edx
xorl %eax, %eax
callq 0x21b0
jmp 0x3663
movq 0xd83b(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8b11(%rip), %rsi      # 0xc2b0
movl %r14d, %edx
xorl %eax, %eax
callq 0x21b0
shlq $0x3, %r12
movq 0x28(%rsp), %rax
addq (%rax), %r12
movq 0xd834(%rip), %rdi      # 0x10ff0
movq %r12, %rsi
callq 0x39c5
movq %rax, %rdi
callq 0x2090
xorl %ebp, %ebp
jmp 0x3663
jmp 0x37db
jmp 0x37db
jmp 0x37db
jmp 0x37db
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x37ed
callq 0x2150
movq %rbx, %rdi
callq 0x2220
nop