// File: /workspace/github_cpp_makefile_star2_O2/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 0x2c40
testb %al, %al
je 0x2e0b
leaq 0x48(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %rax, 0x60(%rsp)
leaq 0x60(%rbx), %rax
movq %rax, 0x38(%rsp)
movq %rax, 0x68(%rsp)
leaq 0x78(%rbx), %r15
movq %r15, 0x70(%rsp)
leaq 0x90(%rbx), %r12
movq %r12, 0x78(%rsp)
movq 0x20(%rbx), %rax
subq 0x18(%rbx), %rax
shrq $0x2, %rax
movslq %eax, %rsi
leaq 0x44(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x48(%rsp), %r14
leaq 0x7(%rsp), %rcx
movq %r14, %rdi
callq 0x3578
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq (%r14), %rdx
cmpq %rcx, %rax
je 0x2e12
movslq (%rax), %rsi
testq %rsi, %rsi
js 0x2e05
incl (%rdx,%rsi,4)
addq $0x4, %rax
jmp 0x2df5
xorl %ebx, %ebx
jmp 0x313b
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rdx
subq %rax, %rdx
shrq $0x2, %rdx
movq 0x30(%rbx), %rsi
xorl %edi, %edi
testl %edx, %edx
cmovlel %edi, %edx
xorl %ecx, %ecx
cmpq %rdi, %rdx
je 0x2e49
cmpl $0x0, (%rax,%rdi,4)
jne 0x2e44
movl (%rsi,%rdi,4), %r8d
cmpl %ecx, %r8d
cmovgl %r8d, %ecx
incq %rdi
jmp 0x2e2e
movq %r12, 0x30(%rsp)
movq 0xa8(%rbx), %rdi
movq 0xb0(%rbx), %rsi
movq %rsi, %rax
subq %rdi, %rax
pushq $0x18
popq %rbp
cqto
idivq %rbp
decl %eax
cmpl %eax, %ecx
jne 0x314f
movq %r15, 0x28(%rsp)
leaq 0x8392(%rip), %r14      # 0xb212
xorl %r15d, %r15d
subq %rdi, %rsi
movq %rsi, %rax
cqto
idivq %rbp
decl %eax
cltq
cmpq %rax, %r15
jg 0x2eec
imulq $0x18, %r15, %rax
movq (%rdi,%rax), %r13
movq 0x8(%rdi,%rax), %r12
cmpq %r12, %r13
je 0x2ed9
movslq (%r13), %rdx
movq 0x30(%rbx), %rax
movl (%rax,%rdx,4), %r8d
cmpq %r8, %r15
jne 0x2ec0
addq $0x4, %r13
jmp 0x2ea4
movq 0xe109(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
movq %r14, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2180
jmp 0x2eba
incq %r15
movq 0xa8(%rbx), %rdi
movq 0xb0(%rbx), %rsi
jmp 0x2e83
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r14
jge 0x316b
movl (%rax,%r14,4), %ecx
movq 0x48(%rsp), %rax
movl (%rax,%r14,4), %r8d
cmpl %r8d, %ecx
jne 0x3258
xorl %eax, %eax
cmpq $0x4, %rax
je 0x2f59
movq 0x60(%rsp,%rax,8), %rdx
movq (%rdx), %rsi
imulq $0x18, %r14, %rdi
movq (%rsi,%rdi), %rdx
movq 0x8(%rsi,%rdi), %rsi
cmpq %rsi, %rdx
je 0x2f54
movl (%rdx), %edi
addq $0x4, %rdx
cmpq %rdi, %r14
jne 0x2f3f
jmp 0x3106
incq %rax
jmp 0x2f24
testl %ecx, %ecx
jle 0x2f7d
movq 0x18(%rsp), %rax
movq (%rax), %rax
imulq $0x18, %r14, %r15
movq 0x8(%rax,%r15), %rcx
cmpq (%rax,%r15), %rcx
je 0x30fe
jmp 0x327a
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3344
addl %eax, %ebp
movl %ebp, 0x24(%rsp)
movq 0x48(%rbx), %rdi
imulq $0x18, %r14, %rax
movq (%rdi,%rax), %rbp
movq %rax, 0x8(%rsp)
movq 0x8(%rdi,%rax), %r13
cmpq %r13, %rbp
je 0x2fe3
movslq (%rbp), %r15
imulq $0x18, %r15, %r12
addq %r12, %rdi
movl %r14d, %esi
callq 0x32d6
movq 0x18(%rsp), %rcx
movq (%rcx), %rdi
cmpq 0x8(%rdi,%r12), %rax
je 0x3193
movq 0x18(%rbx), %rax
addq $0x4, %rbp
cmpl $0x0, (%rax,%r15,4)
jle 0x2fa4
jmp 0x31a6
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rdi,%rax), %rbp
movq 0x8(%rdi,%rax), %r13
cmpq %r13, %rbp
je 0x3038
movslq (%rbp), %r15
imulq $0x18, %r15, %r12
addq %r12, %rdi
movl %r14d, %esi
callq 0x32d6
movq 0x38(%rsp), %rcx
movq (%rcx), %rdi
cmpq 0x8(%rdi,%r12), %rax
je 0x31bc
movq 0x18(%rbx), %rax
addq $0x4, %rbp
cmpl $0x0, (%rax,%r15,4)
jle 0x2ff9
jmp 0x31cf
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %r13
movq 0x8(%rax,%rcx), %rax
movq %rax, 0x10(%rsp)
cmpq 0x10(%rsp), %r13
je 0x3099
movslq (%r13), %r15
imulq $0x18, %r15, %r12
movq 0x30(%rsp), %rbp
movq (%rbp), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x32d6
movq (%rbp), %rcx
cmpq 0x8(%rcx,%r12), %rax
je 0x31e2
movq 0x18(%rbx), %rax
addq $0x4, %r13
cmpl $0x0, (%rax,%r15,4)
jle 0x3053
jmp 0x31f5
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %r13
movq 0x8(%rax,%rcx), %rax
movq %rax, 0x10(%rsp)
cmpq 0x10(%rsp), %r13
je 0x30fa
movslq (%r13), %r15
imulq $0x18, %r15, %rbp
movq 0x28(%rsp), %r12
movq (%r12), %rdi
addq %rbp, %rdi
movl %r14d, %esi
callq 0x32d6
movq (%r12), %rcx
cmpq 0x8(%rcx,%rbp), %rax
je 0x3208
movq 0x18(%rbx), %rax
addq $0x4, %r13
cmpl $0x0, (%rax,%r15,4)
jle 0x30b4
jmp 0x3233
movl 0x24(%rsp), %ebp
incq %r14
jmp 0x2ef1
movq 0xdec3(%rip), %rcx      # 0x10fd0
movq (%rcx), %rdi
leaq 0x835d(%rip), %rcx      # 0xb474
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
leaq 0x8137(%rip), %rsi      # 0xb25c
xorl %ebx, %ebx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2180
leaq 0x48(%rsp), %rdi
callq 0x3660
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xde7a(%rip), %rdx      # 0x10fd0
movq (%rdx), %rdi
leaq 0x808f(%rip), %rsi      # 0xb1ef
xorl %ebx, %ebx
movl %ecx, %edx
movl %eax, %ecx
jmp 0x324c
movb $0x1, %bl
testb $0x1, %bpl
je 0x3131
movq 0xde56(%rip), %rax      # 0x10fd0
movq (%rax), %rcx
leaq 0x7edc(%rip), %rdi      # 0xb060
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
callq 0x2210
xorl %ebx, %ebx
jmp 0x3131
movq 0xde36(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x80ed(%rip), %rsi      # 0xb291
jmp 0x3219
movq 0xde23(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x810e(%rip), %rsi      # 0xb2c5
jmp 0x3244
movq 0xde0d(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8119(%rip), %rsi      # 0xb2e6
jmp 0x3219
movq 0xddfa(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x813e(%rip), %rsi      # 0xb31e
jmp 0x3244
movq 0xdde7(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x814e(%rip), %rsi      # 0xb341
jmp 0x3219
movq 0xddd4(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x8171(%rip), %rsi      # 0xb377
jmp 0x3244
movq 0xddc1(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x817f(%rip), %rsi      # 0xb398
xorl %ebx, %ebx
movl %r14d, %edx
movl %r15d, %ecx
movl %r15d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x2180
jmp 0x3131
movq 0xdd96(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x818a(%rip), %rsi      # 0xb3ce
xorl %ebx, %ebx
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2180
jmp 0x3131
movq 0xdd71(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x7fd2(%rip), %rsi      # 0xb23b
xorl %ebx, %ebx
movl %r14d, %edx
xorl %eax, %eax
callq 0x2180
jmp 0x3131
movq 0xdd4f(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x7fe9(%rip), %rsi      # 0xb274
movl %r14d, %edx
xorl %eax, %eax
callq 0x2180
movq 0x18(%rsp), %rax
addq (%rax), %r15
movq 0xdd4c(%rip), %rdi      # 0x10ff0
movq %r15, %rsi
callq 0x3463
movq %rax, %rdi
callq 0x2080
jmp 0x318f
jmp 0x32c1
jmp 0x32c1
jmp 0x32c1
jmp 0x32c1
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3660
movq %rbx, %rdi
callq 0x21f0