// File: dtsaras[P]GCW/rwgraph.cpp
// Function: HyperGraph::pollingLT2(Graph&, std::vector<unsigned int, std::allocator<unsigned int>>&, unsigned int, std::vector<bool, std::allocator<bool>>&, std::vector<int, std::allocator<int>>&, sampler<int>&, int)
bool HyperGraph::pollingLT2(Graph &g, vector<unsigned int> & link, unsigned int k, vector<bool> &visit, vector<int> &visit_mark, sampler<int> &samp, int p)
{   
    // cout << "&&&&&&&&&&&&&&&&&& 1" << endl;
    unsigned int i;
    bool t = false;
    unsigned int gSize = g.getSize();
    // cout << "&&&&&&&&&&&&&&&&&& 2" << endl;
    // unsigned int cur = sfmt_genrand_uint32(&sfmtSeed)%gSize+1; // rand node
    unsigned cur = samp();
    unsigned int num_marked = 0;
    // cout << "startLT2: " << cur << endl;
    for (i = 0; i < gSize; ++i){ // Goes over all nodes
        // cout << cur << " &&&&&&&&&&&&&&&&&& 3" << endl;
        if (visit[cur] == true) break; // Only unvisited
        // cout << "&&&&&&&&&&&&&&&&&& 3" << endl;
        visit[cur] = true;  // marks it visited
        // cout << "&&&&&&&&&&&&&&&&&& 3" << endl;
        visit_mark[num_marked] = cur; // tracks which one was marked at each iteration
        // cout << "&&&&&&&&&&&&&&&&&& 3" << endl;
        num_marked++; // How many were visited
        // cout << "&&&&&&&&&&&&&&&&&& 4" << endl;
        if (link[cur] < k) // Has been influenced
            t=true;
        int ind;
        // cout << "&&&&&&&&&&&&&&&&&& 5" << endl;
        ind = randIndex_lin(g, g.weights[cur],g.inv_node_deg[cur], cur, p);
        // if (g.weights[cur].size() >= 32)
        //     ind = randIndex_bin(g, g.weights[cur],g.inv_node_deg[cur], cur, p);
        // else
        //     ind = randIndex_lin(g, g.weights[cur],g.inv_node_deg[cur], cur, p);

        if (ind == -1)
            break;
        // cout << "&&&&&&&&&&&&&&&&&& 6" << endl;
        // cur = g.invAdjList[cur][ind-1];
        cur = g.invAdjList[cur][ind];
        // cout << "&&&&&&&&&&&&&&&&&& 7" << endl;
        // cout << cur << endl;
    }
    // cout << "&&&&&&&&&&&&&&&&&& 8" << endl;
    edge_node.push_back(vector<int>(visit_mark.begin(),visit_mark.begin()+num_marked));
    for (i = 0; i < num_marked; ++i){
        visit[visit_mark[i]]=false;
    }
    // cout << "&&&&&&&&&&&&&&&&&& 9" << endl;
    return t;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movl 0x118(%rsp), %eax
movq 0x110(%rsp), %rax
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq %rdx, 0xf0(%rsp)
movl %ecx, 0xec(%rsp)
movq %r8, 0xe0(%rsp)
movq %r9, 0xd8(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x38(%rsp)
movb $0x0, 0xd3(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x1db70
movl %eax, 0xcc(%rsp)
movq 0x110(%rsp), %rdi
callq 0x24d10
movl %eax, 0xc8(%rsp)
movl $0x0, 0xc4(%rsp)
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jae 0x202f8
movq 0xe0(%rsp), %rdi
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0xe790
movq %rax, 0xb0(%rsp)
movq %rdx, 0xb8(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xeb50
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x2018e
jmp 0x202f8
movq 0xe0(%rsp), %rdi
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0xe790
movq %rax, 0xa0(%rsp)
movq %rdx, 0xa8(%rsp)
leaq 0xa0(%rsp), %rdi
movl $0x1, %esi
callq 0xe7f0
movl 0xc8(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0xd8(%rsp), %rdi
movl 0xc4(%rsp), %eax
movl %eax, %esi
callq 0xe3b0
movl 0x34(%rsp), %ecx
movl %ecx, (%rax)
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
movq 0xf0(%rsp), %rdi
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0xee00
movl (%rax), %eax
cmpl 0xec(%rsp), %eax
jae 0x20227
movb $0x1, 0xd3(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xf8(%rsp), %rdi
addq $0xaa0, %rdi            # imm = 0xAA0
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0x24890
movq %rax, 0x28(%rsp)
movq 0xf8(%rsp), %rdi
addq $0xa70, %rdi            # imm = 0xA70
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0xe3b0
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl (%rax), %ecx
movl 0xc8(%rsp), %r8d
movl 0x118(%rsp), %r9d
callq 0x24e30
movl %eax, 0x9c(%rsp)
cmpl $-0x1, 0x9c(%rsp)
jne 0x202ac
jmp 0x202f8
movq 0xf8(%rsp), %rdi
addq $0xa88, %rdi            # imm = 0xA88
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0x24850
movq %rax, %rdi
movslq 0x9c(%rsp), %rsi
callq 0xe3b0
movl (%rax), %eax
movl %eax, 0xc8(%rsp)
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x20138
movq 0x38(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x10(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x13b30
movq %rax, 0x78(%rsp)
movq 0xd8(%rsp), %rdi
callq 0x13b30
movq %rax, 0x68(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, %esi
leaq 0x68(%rsp), %rdi
callq 0x14a30
movq %rax, 0x70(%rsp)
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xe180
movq 0x18(%rsp), %rcx
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x80(%rsp), %rdi
callq 0x24ff0
jmp 0x2036f
movq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x24fc0
jmp 0x20383
leaq 0x80(%rsp), %rdi
callq 0xe2e0
leaq 0x67(%rsp), %rdi
callq 0xe210
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0xc4(%rsp), %eax
jae 0x20449
movq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xd8(%rsp), %rdi
movl 0xd4(%rsp), %eax
movl %eax, %esi
callq 0xe3b0
movq 0x8(%rsp), %rdi
movslq (%rax), %rsi
callq 0xe790
movq %rax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0xe7f0
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x203a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x2043d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xe2e0
leaq 0x67(%rsp), %rdi
callq 0xe210
jmp 0x2045a
movb 0xd3(%rsp), %al
andb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
retq
movq 0x58(%rsp), %rdi
callq 0x4690
nopw %cs:(%rax,%rax)