// File: /workspace/github_cpp_makefile_star2_O3/sharmaeklavya2[P]ddos-on-anycast/src/lib/attack.cpp
// Function: attack(Network const&, std::vector<int, std::allocator<int>> const&, std::vector<int, std::allocator<int>>&, int, int)
void attack(const Network& network, const ivec& victims, ivec& target, int in_weight, int side_weight) {
    // TODO: Remove side edge transitivity

    normalize_edge_weights(in_weight, side_weight);
    int n = network.size();
    int h = network.height();

    // init targets
    target.resize(n, -1);
    ivec target_dist(n, -1);
    for(int v: victims) {
        target[v] = v;
        target_dist[v] = 0;
    }

    /*
    vector<ivec> depthwise_victims(h+1);
    for(int victim: victims) {
        depthwise_victims[network.depth[victim]].push_back(victim);
    }
    */

    // Apply Dijkstra's algorithm
    vector<bool> visited(n, false);
    for(int d=h; d>=0; --d) {
        // initialize targets, target_dists and heap
        PQ pq;
        for(int u: network.depthwise[d]) {
            if(target[u] == -1 && !network.down_nbrs[u].empty()) {
                ipvec dvlist;
                dvlist.reserve(network.down_nbrs[u].size());
                for(int v: network.down_nbrs[u]) {
                    if(target_dist[v] != -1) {
                        dvlist.emplace_back(target_dist[v], target[v]);
                    }
                }
                if(!dvlist.empty()) {
                    iipair min_elem = *(std::min_element(dvlist.begin(), dvlist.end()));
                    target[u] = min_elem.second;
                    target_dist[u] = 0;
                }
            }
            if(target_dist[u] != -1) {
                if(target_dist[u] != 0) {
                    fprintf(stderr, "target_dist[%d] = %d instead of 0 or -1\n", u, target_dist[u]);
                }
                pq.push(PQElem(0, u));
            }
        }

        dijkstra(network, pq, target, target_dist, visited, in_weight, side_weight);
    }

    typedef tuple<int, int, int> itrip;
    ivec target_depth(network.depth.begin(), network.depth.end());

    for(int d=1; d<=h; ++d) {
        PQ pq;
        for(int u: network.depthwise[d]) {
            if(target_dist[u] == -1 && !network.up_nbrs[u].empty()) {
                vector<itrip> dvlist;
                for(int v: network.up_nbrs[u]) {
                    if(target_dist[v] != -1) {
                        dvlist.emplace_back(-target_depth[v], target_dist[v], target[v]);
                    }
                }
                if(!dvlist.empty()) {
                    int v = std::get<2>(*(std::min_element(dvlist.begin(), dvlist.end())));
                    target[u] = target[v];
                    target_dist[u] = 0;
                    target_depth[u] = target_depth[v];
                    pq.emplace(target_dist[u], u);
                }
            }
        }

        dijkstra(network, pq, target, target_dist, visited, in_weight, side_weight);
    }
    // cerr << "target_dist: " << target_dist << endl;

    for(int i=0; i<n; ++i) {
        if(network.netsize[i] == 0 && (target[i] == -1 || target_dist[i] < 0)) {
            fprintf(stderr, "target[%d] = %d and target_dist[%d] = %d\n", i, target[i], i, target_dist[i]);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x1c(%rsp), %rdi
movl %ecx, (%rdi)
leaq 0x18(%rsp), %rsi
movl %r8d, (%rsi)
callq 0x797c
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
movq 0xb0(%r15), %r14
shrq $0x2, %rax
movq %r15, 0x68(%rsp)
subq 0xa8(%r15), %r14
movq %rax, 0xf0(%rsp)
movslq %eax, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0xc0(%rsp), %r13
movl %ebp, (%r13)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x38d2
movl %ebp, (%r13)
leaq 0x48(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
leaq 0x80(%rsp), %rcx
movq %r15, %rsi
callq 0x3b06
movq (%r12), %rax
movq 0x8(%r12), %rcx
cmpq %rcx, %rax
je 0x7d72
movq (%rbx), %rdx
movq 0x48(%rsp), %rsi
movslq (%rax), %rdi
movl %edi, (%rdx,%rdi,4)
movl $0x0, (%rsi,%rdi,4)
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x7d5c
leaq 0x80(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rcx
movq %r15, %rsi
callq 0x83fa
sarq $0x3, %r14
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rcx
movq %rcx, %rax
movq %rcx, 0xe8(%rsp)
decl %eax
movl %eax, 0x40(%rsp)
movq 0x68(%rsp), %rbp
js 0x7fc5
movl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x40(%rsp), %ecx
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movq 0xa8(%rbp), %rax
movq %rcx, 0x60(%rsp)
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r15
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x70(%rsp)
cmpq %rax, %r15
je 0x7f75
movl (%r15), %r13d
movslq %r13d, %r14
movq (%rbx), %rax
cmpl $-0x1, (%rax,%r14,4)
je 0x7e67
movq 0x48(%rsp), %rax
movl (%rax,%r14,4), %ecx
cmpl $-0x1, %ecx
je 0x7e57
testl %ecx, %ecx
jne 0x7f55
movl %r13d, 0x20(%rsp)
movl $0x0, 0x24(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x8462
addq $0x4, %r15
cmpq 0x70(%rsp), %r15
jne 0x7e12
jmp 0x7f75
movq 0x90(%rbp), %rax
leaq (%r14,%r14,2), %r12
movq (%rax,%r12,8), %rcx
cmpq 0x8(%rax,%r12,8), %rcx
je 0x7e22
leaq (%rax,%r12,8), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x2, %rsi
leaq 0x20(%rsp), %rdi
callq 0x6980
movq 0x90(%rbp), %rax
movq (%rax,%r12,8), %rbp
movq 0x8(%rax,%r12,8), %r12
cmpq %r12, %rbp
je 0x7ee6
movslq (%rbp), %rdx
movq 0x48(%rsp), %rax
cmpl $-0x1, (%rax,%rdx,4)
je 0x7ee0
leaq (%rax,%rdx,4), %rsi
shlq $0x2, %rdx
addq (%rbx), %rdx
leaq 0x20(%rsp), %rdi
callq 0x6740
addq $0x4, %rbp
jmp 0x7eb7
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
cmpq %rax, %rdi
movq 0x68(%rsp), %rbp
je 0x7f42
leaq 0x8(%rdi), %rcx
movq %rdi, %rdx
cmpq %rax, %rcx
je 0x7f2b
movq %rdi, %rdx
movl (%rcx), %esi
movl (%rdx), %r8d
cmpl %r8d, %esi
jge 0x7f18
movq %rcx, %rdx
jmp 0x7f22
jg 0x7f22
movl 0x4(%rcx), %esi
cmpl 0x4(%rdx), %esi
jl 0x7f13
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x7f09
movl 0x4(%rdx), %eax
movq (%rbx), %rcx
movl %eax, (%rcx,%r14,4)
movq 0x48(%rsp), %rax
movl $0x0, (%rax,%r14,4)
testq %rdi, %rdi
je 0x7e22
callq 0x2150
jmp 0x7e22
movq 0x9074(%rip), %rax      # 0x10fd0
movq (%rax), %rdi
leaq 0x471d(%rip), %rsi      # 0xc683
movl %r13d, %edx
xorl %eax, %eax
callq 0x21b0
jmp 0x7e38
movl 0x10(%rsp), %eax
movl %eax, (%rsp)
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
movq %rbx, %rdx
leaq 0x48(%rsp), %rcx
leaq 0xc0(%rsp), %r8
movl 0x14(%rsp), %r9d
callq 0x7a07
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
movq 0x60(%rsp), %r14
je 0x7fb8
callq 0x2150
leaq -0x1(%r14), %rcx
testq %r14, %r14
jg 0x7dd4
movq 0x30(%rbp), %rsi
movq 0x38(%rbp), %rdx
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rcx
callq 0x84cc
cmpl $0x0, 0x40(%rsp)
jle 0x81cc
movl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0xe8(%rsp), %eax
movq %rax, 0x40(%rsp)
movl $0x1, %r14d
leaq 0xa0(%rsp), %r13
leaq 0x7c(%rsp), %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movq 0xa8(%rbp), %rax
movq %r14, 0x60(%rsp)
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %r14
movq 0x8(%rax,%rcx,8), %rsi
cmpq %rsi, %r14
movq %rsi, 0x70(%rsp)
je 0x817b
movslq (%r14), %rax
movl %eax, 0xc(%rsp)
movq 0x48(%rsp), %rcx
cmpl $-0x1, (%rcx,%rax,4)
jne 0x816e
movq 0x78(%rbp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rdx
cmpq 0x8(%rcx,%rax,8), %rdx
je 0x816e
leaq (%rcx,%rax,8), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movq (%rax), %rbp
movq 0x8(%rax), %r15
cmpq %r15, %rbp
je 0x8164
movslq (%rbp), %rcx
movq 0x48(%rsp), %rax
cmpl $-0x1, (%rax,%rcx,4)
je 0x80e2
leaq (%rax,%rcx,4), %rdx
movq 0x20(%rsp), %rax
xorl %esi, %esi
subl (%rax,%rcx,4), %esi
shlq $0x2, %rcx
movl %esi, 0x7c(%rsp)
addq (%rbx), %rcx
movq %r13, %rdi
movq %r12, %rsi
callq 0x8506
addq $0x4, %rbp
cmpq %r15, %rbp
jne 0x80af
movq 0xa0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
cmpq %rsi, %rdi
je 0x815a
callq 0x8bed
movslq (%rax), %rax
movq (%rbx), %rcx
movl (%rcx,%rax,4), %edx
movslq 0xc(%rsp), %rsi
movl %edx, (%rcx,%rsi,4)
movslq 0xc(%rsp), %rcx
movq 0x48(%rsp), %rdx
movl $0x0, (%rdx,%rcx,4)
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %eax
movslq 0xc(%rsp), %rsi
movl %eax, (%rcx,%rsi,4)
movslq 0xc(%rsp), %rax
leaq (%rdx,%rax,4), %rsi
leaq 0x80(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x8536
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x8164
callq 0x2150
movq 0x68(%rsp), %rbp
movq 0x70(%rsp), %rsi
addq $0x4, %r14
cmpq %rsi, %r14
jne 0x8057
movl 0x10(%rsp), %eax
movl %eax, (%rsp)
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
movq %rbx, %rdx
leaq 0x48(%rsp), %rcx
leaq 0xc0(%rsp), %r8
movl 0x14(%rsp), %r9d
callq 0x7a07
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
movq 0x60(%rsp), %r14
je 0x81be
callq 0x2150
incq %r14
cmpq 0x40(%rsp), %r14
jne 0x8019
movq 0xf0(%rsp), %r13
testl %r13d, %r13d
jle 0x8235
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x8de9(%rip), %r14      # 0x10fd0
leaq 0x44be(%rip), %r15      # 0xc6ac
xorl %r12d, %r12d
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax,%r12,4)
jne 0x8216
movq (%rbx), %rax
movl (%rax,%r12,4), %ecx
movq 0x48(%rsp), %rax
movl (%rax,%r12,4), %r9d
cmpl $-0x1, %ecx
je 0x8220
testl %r9d, %r9d
js 0x8220
incq %r12
cmpq %r12, %r13
jne 0x81f1
jmp 0x8235
movq (%r14), %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x21b0
jmp 0x8216
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x8244
callq 0x2150
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x8262
callq 0x2150
movq $0x0, 0xc0(%rsp)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x8271
callq 0x2150
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x82f4
movq %rax, %rbx
jmp 0x8323
movq %rax, %rbx
jmp 0x82b7
jmp 0x829d
jmp 0x82a2
jmp 0x82a2
jmp 0x82d0
movq %rax, %rbx
jmp 0x82e2
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x82b7
callq 0x2150
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x82c9
callq 0x2150
movq 0x20(%rsp), %rdi
jmp 0x82ea
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x82e2
callq 0x2150
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x82f4
callq 0x2150
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x8323
callq 0x2150
xorl %eax, %eax
movq %rax, 0xc0(%rsp)
movl $0x0, 0xc8(%rsp)
movq %rax, 0xd0(%rsp)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x8332
callq 0x2150
movq %rbx, %rdi
callq 0x2220