// File: /workspace/github_cpp_makefile_star2_O1/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 0x31a2
testb %al, %al
je 0x33ba
leaq 0x48(%rbx), %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x60(%rsp)
leaq 0x60(%rbx), %r14
movq %r14, 0x68(%rsp)
leaq 0x78(%rbx), %rax
movq %rax, 0x28(%rsp)
movq %rax, 0x70(%rsp)
leaq 0x90(%rbx), %r15
movq %r15, 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 0x1f(%rsp), %rcx
callq 0x3c10
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rcx, %rax
je 0x337e
movq 0x48(%rsp), %rdx
movslq (%rax), %rsi
testq %rsi, %rsi
js 0x3375
incl (%rdx,%rsi,4)
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x336a
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0x33c1
movq 0x30(%rbx), %rsi
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edi, %edi
xorl %edx, %edx
cmpl $0x0, (%rax,%rdi,4)
jne 0x33b0
movl (%rsi,%rdi,4), %r8d
cmpl %edx, %r8d
cmovgl %r8d, %edx
incq %rdi
cmpq %rdi, %rcx
jne 0x339f
jmp 0x33c3
xorl %ebx, %ebx
jmp 0x3780
xorl %edx, %edx
movq 0xb0(%rbx), %rax
subq 0xa8(%rbx), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %ecx # imm = 0xAAAAAAAB
decl %ecx
cmpl %ecx, %edx
jne 0x3794
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movq 0xa8(%rbx), %rax
movq 0xb0(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
decl %ecx
js 0x3487
movq 0xebbb(%rip), %r12      # 0x11fd0
leaq 0x9e32(%rip), %r14      # 0xd24e
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %r13
movq 0x8(%rax,%rcx,8), %rbp
cmpq %rbp, %r13
je 0x345b
movslq (%r13), %rdx
movq 0x30(%rbx), %rax
movl (%rax,%rdx,4), %r8d
cmpq %r8, %r15
jne 0x3448
addq $0x4, %r13
jmp 0x342c
movq (%r12), %rdi
movq %r14, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x21b0
jmp 0x3442
leaq 0x1(%r15), %rcx
movq 0xa8(%rbx), %rax
movq 0xb0(%rbx), %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 0x341f
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
setg %bpl
jle 0x375e
xorl %r14d, %r14d
xorl %r13d, %r13d
movl (%rax,%r14,4), %ecx
movq 0x48(%rsp), %rax
movl (%rax,%r14,4), %r8d
cmpl %r8d, %ecx
jne 0x388a
leaq (%r14,%r14,2), %r15
xorl %eax, %eax
movq 0x30(%rsp), %r8
movq 0x60(%rsp,%rax,8), %rcx
movq (%rcx), %rdx
movq (%rdx,%r15,8), %rcx
movq 0x8(%rdx,%r15,8), %rdx
cmpq %rdx, %rcx
je 0x34f0
movl (%rcx), %esi
cmpq %rsi, %r14
je 0x3730
addq $0x4, %rcx
jmp 0x34da
incq %rax
cmpq $0x4, %rax
jne 0x34c9
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r14,4)
jle 0x351e
movq (%r8), %rax
movq 0x8(%rax,%r15,8), %rcx
cmpq (%rax,%r15,8), %rcx
jne 0x38aa
movl %r13d, %edx
jmp 0x3709
movb %bpl, 0x7(%rsp)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x3992
movq 0x30(%rsp), %r12
addl %r13d, %eax
movl %eax, 0x8(%rsp)
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %rbp
movq %r15, 0x20(%rsp)
movq 0x8(%rax,%r15,8), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %rbp
je 0x35aa
movslq (%rbp), %r13
movq (%r12), %rax
leaq (,%r13,2), %r15
addq %r13, %r15
movl %r14d, 0xc(%rsp)
movq (%rax,%r15,8), %rdi
movq 0x8(%rax,%r15,8), %rsi
leaq 0xc(%rsp), %rdx
callq 0x3d83
movq (%r12), %rcx
cmpq 0x8(%rcx,%r15,8), %rax
je 0x37b7
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jg 0x37ca
addq $0x4, %rbp
cmpq 0x10(%rsp), %rbp
jne 0x3556
movq 0x40(%rsp), %r12
movq (%r12), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rbp
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %rbp
je 0x361f
movslq (%rbp), %r13
movq (%r12), %rax
leaq (,%r13,2), %r15
addq %r13, %r15
movl %r14d, 0xc(%rsp)
movq (%rax,%r15,8), %rdi
movq 0x8(%rax,%r15,8), %rsi
leaq 0xc(%rsp), %rdx
callq 0x3d83
movq (%r12), %rcx
cmpq 0x8(%rcx,%r15,8), %rax
je 0x37dd
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jg 0x37f0
addq $0x4, %rbp
cmpq 0x10(%rsp), %rbp
jne 0x35cb
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rbp
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %rbp
movq 0x38(%rsp), %r12
je 0x3698
movslq (%rbp), %r13
movq (%r12), %rax
leaq (,%r13,2), %r15
addq %r13, %r15
movl %r14d, 0xc(%rsp)
movq (%rax,%r15,8), %rdi
movq 0x8(%rax,%r15,8), %rsi
leaq 0xc(%rsp), %rdx
callq 0x3d83
movq (%r12), %rcx
cmpq 0x8(%rcx,%r15,8), %rax
je 0x3803
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jg 0x381f
addq $0x4, %rbp
cmpq 0x10(%rsp), %rbp
jne 0x3644
movq (%r12), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %r15
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %r15
je 0x3705
movq 0x28(%rsp), %r13
movslq (%r15), %r12
movq (%r13), %rax
leaq (%r12,%r12,2), %rbp
movl %r14d, 0xc(%rsp)
movq (%rax,%rbp,8), %rdi
movq 0x8(%rax,%rbp,8), %rsi
leaq 0xc(%rsp), %rdx
callq 0x3d83
movq (%r13), %rcx
cmpq 0x8(%rcx,%rbp,8), %rax
je 0x3838
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
jg 0x385e
addq $0x4, %r15
cmpq 0x10(%rsp), %r15
jne 0x36b9
movl 0x8(%rsp), %edx
incq %r14
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
movl %edx, %r13d
cmpq %rcx, %r14
setl %bpl
jl 0x34a8
jmp 0x3760
movq 0xe899(%rip), %rcx      # 0x11fd0
movq (%rcx), %rdi
leaq 0x9d6f(%rip), %rcx      # 0xd4b0
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
leaq 0x9b49(%rip), %rsi      # 0xd298
movl %r14d, %ecx
xorl %eax, %eax
callq 0x21b0
movl %r13d, %edx
jmp 0x3760
xorl %edx, %edx
testb $0x1, %bpl
je 0x376a
xorl %ebx, %ebx
jmp 0x3771
movb $0x1, %bl
testb $0x1, %dl
jne 0x37b0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3780
callq 0x2150
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe835(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9a86(%rip), %rsi      # 0xd22b
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x21b0
jmp 0x3771
callq 0x2298
jmp 0x3766
movq 0xe812(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b05(%rip), %rsi      # 0xd2cd
jmp 0x3814
movq 0xe7ff(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b26(%rip), %rsi      # 0xd301
jmp 0x3830
movq 0xe7ec(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b34(%rip), %rsi      # 0xd322
jmp 0x3814
movq 0xe7d9(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b59(%rip), %rsi      # 0xd35a
jmp 0x3830
movq 0xe7c6(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b69(%rip), %rsi      # 0xd37d
movl %r14d, %edx
movl %r13d, %ecx
movl %r13d, %r8d
jmp 0x3852
movq 0xe7aa(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b83(%rip), %rsi      # 0xd3b3
movl %r14d, %edx
movl %r13d, %ecx
jmp 0x3875
movq 0xe791(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b8b(%rip), %rsi      # 0xd3d4
movl %r14d, %edx
movl %r12d, %ecx
movl %r12d, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x21b0
jmp 0x387c
movq 0xe76b(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x9b9b(%rip), %rsi      # 0xd40a
movl %r14d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x21b0
movb 0x7(%rsp), %bpl
movl 0x8(%rsp), %edx
jmp 0x3760
movq 0xe73f(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x99dc(%rip), %rsi      # 0xd277
movl %r14d, %edx
xorl %eax, %eax
callq 0x21b0
jmp 0x3759
movq 0xe71f(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x99f5(%rip), %rsi      # 0xd2b0
movl %r14d, %edx
xorl %eax, %eax
movq %r8, %rbx
callq 0x21b0
shlq $0x3, %r15
addq (%rbx), %r15
movq 0xe71a(%rip), %rdi      # 0x11ff0
movq %r15, %rsi
callq 0x3ad7
movq %rax, %rdi
callq 0x2090
movl %r13d, %edx
jmp 0x3760
jmp 0x38f6
jmp 0x38f6
jmp 0x38f6
jmp 0x38f6
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3908
callq 0x2150
movq %rbx, %rdi
callq 0x2220