// File: /workspace/github_cpp_makefile_star2_O2/JenTus[P]TCEM/src_TCEM/allocator.cc
// Function: Cide::allocator::degreeVersionTwo(long long)
double allocator::degreeVersionTwo(int64 rcSampleSize) {


        clock_t begin = clock();
        priority_queue<pair<int, double>, vector<pair<int, double>>, CompareBySecond> heap;

        float totalscore = 0;
        int bestNodeID;
//
        for (int i = 0; i < n; i++) {
            double val = (double) nodeDegree[i];
            std::pair<int, double> pairVal(std::make_pair(i, val));
            heap.push(pairVal);
        }

        std::set<int> rednodes, bluenodes;
        seedSet.clear();
        seedScores.clear();
        //std::set<int> rrRed;
        //std::set<int> rrBlue;
        //int testt;

        //rrRed.reserve(n*k_r);
        //rrBlue.reserve(n*k_b);

        while ((int) seedSet.size() < k_r + k_r) {
            pair<int, double> pairVal = heap.top();
            heap.pop();
            bestNodeID = pairVal.first;
           // for (int j = 0; j < hyperG[bestNodeID].size(); ++j) {
           //     int id = hyperG[bestNodeID][j];
           //     rrRed.insert(id);
           // }

            seedSet.push_back(bestNodeID);
            rednodes.insert(bestNodeID);

            pairVal = heap.top();
            heap.pop();
            bestNodeID = pairVal.first;
           // for (int j = 0; j < hyperG[bestNodeID + n].size(); ++j) {
           //     int id = hyperG[bestNodeID + n][j];
           //     rrBlue.insert(id);
           // }

            seedSet.push_back(bestNodeID);
            bluenodes.insert(bestNodeID);
        }

        while ((int) seedSet.size() < k_r + k_b) {
            pair<int, double> pairVal = heap.top();
            heap.pop();
            bestNodeID = pairVal.first;
           // for (int l = 0; l < hyperG[bestNodeID + n].size(); ++l) {
           //     int id = hyperG[bestNodeID + n][l];
           //     rrBlue.insert(id);
           // }
            seedSet.push_back(bestNodeID);
            bluenodes.insert(bestNodeID);
        }

        /*

        vector<int> rrRedV(rrRed.begin(), rrRed.end());
        vector<int> rrBlueV(rrBlue.begin(), rrBlue.end());

        std::sort(rrRedV.begin(), rrRedV.end());
        std::sort(rrBlueV.begin(), rrBlueV.end());

        testt = intersection_size(rrRedV, rrBlueV);
        cout << "intersection is " << testt;
        */

        int redbluecount = 0;

        vector<int> s1(rednodes.begin(), rednodes.end());
        vector<int> s2(bluenodes.begin(), bluenodes.end());
        sort(s1.begin(), s1.end());
        sort(s2.begin(), s2.end());


        for (int i = 0; i < rcSampleSize; ++i) {
            vector<int> RedList = rcList->at(0)->hyperGT[i];
            vector<int> BlueList = rcList->at(1)->hyperGT[i];

            sort(RedList.begin(), RedList.end());
            sort(BlueList.begin(), BlueList.end());

            if(intersection_size(s1, RedList) >= 1){
                if(intersection_size(s2, BlueList) >= 1){
                    redbluecount +=1;
                }
            }
        }


        //cout << " redBluecount is " << redbluecount << endl;

        totalscore = (float) redbluecount / (float) rcSampleSize;

        // end of extra results
        clock_t end = clock();
        totalDuration = double(end - begin) / CLOCKS_PER_SEC + duration_common; // in seconds
        totalMemory = getCurrentMemoryUsage(); // in MB


        cout << "Total score of degree two is " << totalscore*n << endl;
        std::ostringstream streamObj1;
        streamObj1 << std::fixed << std::setprecision(2)<<totalscore*n;

        writeInMasterOutputFile("DegreeVersionTwo", totalDuration,  totalMemory, streamObj1.str(), rednodes, bluenodes);
        return totalscore;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
callq 0x31c0
movq %rax, %r13
leaq 0x80(%rsp), %r14
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
xorl %r12d, %r12d
leaq 0x180(%rsp), %r15
movslq 0x68(%rbx), %rax
cmpq %rax, %r12
jge 0x576b
movq 0xd8(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movl %r12d, 0x180(%rsp)
movsd %xmm0, 0x188(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x8764
incq %r12
jmp 0x5734
leaq 0xd8(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0xa8(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq 0xa8(%rbx), %rax
cmpq %rax, 0xb0(%rbx)
je 0x57bc
movq %rax, 0xb0(%rbx)
leaq 0xa8(%rbx), %r14
movq 0xc0(%rbx), %rax
cmpq %rax, 0xc8(%rbx)
je 0x57da
movq %rax, 0xc8(%rbx)
movq 0xb0(%rbx), %rax
subq 0xa8(%rbx), %rax
shrq $0x2, %rax
movl 0x78(%rbx), %ecx
addl %ecx, %ecx
cmpl %eax, %ecx
jle 0x5860
leaq 0x80(%rsp), %rdi
movq (%rdi), %rax
movl (%rax), %ebp
callq 0x877a
leaq 0xc(%rsp), %rsi
movl %ebp, (%rsi)
movq %r14, %rdi
callq 0x854e
leaq 0xd0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x98b4
leaq 0x80(%rsp), %rdi
movq (%rdi), %rax
movl (%rax), %ebp
callq 0x877a
leaq 0xc(%rsp), %rsi
movl %ebp, (%rsi)
movq %r14, %rdi
callq 0x854e
leaq 0xa0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x98b4
jmp 0x57da
movq %r13, 0x20(%rsp)
leaq 0x80(%rsp), %r15
leaq 0xc(%rsp), %rbp
leaq 0xa0(%rsp), %r12
movq 0xb0(%rbx), %rax
subq 0xa8(%rbx), %rax
shrq $0x2, %rax
movl 0x7c(%rbx), %ecx
addl 0x78(%rbx), %ecx
cmpl %eax, %ecx
jle 0x58c6
movq 0x80(%rsp), %rax
movl (%rax), %r13d
movq %r15, %rdi
callq 0x877a
movl %r13d, 0xc(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x854e
movq %r12, %rdi
movq %rbp, %rsi
callq 0x98b4
jmp 0x587a
movq 0xe8(%rsp), %rsi
leaq 0x68(%rsp), %rdi
leaq 0x180(%rsp), %rcx
leaq 0xd8(%rsp), %rdx
callq 0x86a2
movq 0xb8(%rsp), %rsi
leaq 0x50(%rsp), %rdi
leaq 0x180(%rsp), %rcx
leaq 0xa8(%rsp), %rdx
callq 0x86a2
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x9b85
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x9b85
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
testq %rax, %rax
movl $0x0, %r15d
cmovgq %rax, %r15
leaq 0x180(%rsp), %r12
leaq 0x30(%rsp), %rbp
xorl %r14d, %r14d
subq $0x1, %r15
jb 0x59fc
movq 0xae8(%rbx), %rdi
xorl %esi, %esi
callq 0x856c
movq (%rax), %rax
movq 0x18(%rax), %rsi
addq %r13, %rsi
movq %r12, %rdi
callq 0x86d4
movq 0xae8(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x856c
movq (%rax), %rax
movq 0x18(%rax), %rsi
addq %r13, %rsi
movq %rbp, %rdi
callq 0x86d4
movq 0x180(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x9b85
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x9b85
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x8721
testq %rax, %rax
je 0x59e3
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq 0x8721
cmpq $0x1, %rax
sbbl $-0x1, %r14d
movq %rbp, %rdi
callq 0x8e40
movq %r12, %rdi
callq 0x8e40
addq $0x18, %r13
jmp 0x594d
callq 0x31c0
subq 0x20(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x872d(%rip), %xmm0     # 0xe140
addsd 0x8(%rbx), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xb70(%rbx)
callq 0xadf0
movss %xmm0, 0xb74(%rbx)
movq 0xf5a0(%rip), %rdi      # 0x14fd8
leaq 0x889a(%rip), %rsi      # 0xe2d9
callq 0x32c0
cvtsi2ss %r14d, %xmm1
cvtsi2ssq 0x10(%rsp), %xmm0
divss %xmm0, %xmm1
cvtsi2ssl 0x68(%rbx), %xmm0
movss %xmm1, 0x10(%rsp)
mulss %xmm1, %xmm0
movq %rax, %rdi
callq 0x31f0
movq %rax, %rdi
callq 0x3150
leaq 0x180(%rsp), %rdi
callq 0x33f0
leaq 0x180(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rcx
movl $0xfffffefb, %edx       # imm = 0xFFFFFEFB
andl 0x198(%rsp,%rcx), %edx
orl $0x4, %edx
movl %edx, 0x198(%rsp,%rcx)
movq -0x18(%rax), %rax
movq $0x2, 0x188(%rsp,%rax)
cvtsi2ssl 0x68(%rbx), %xmm0
mulss 0x10(%rsp), %xmm0
callq 0x31f0
leaq 0x882b(%rip), %rsi      # 0xe2f7
leaq 0x30(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x3100
movss 0xb70(%rbx), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0xb74(%rbx), %xmm0
movss %xmm0, 0x2c(%rsp)
leaq 0x188(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x34b0
leaq 0x150(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x8b5e
leaq 0x120(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x8b5e
leaq 0x30(%rsp), %rsi
leaq 0x100(%rsp), %rdx
leaq 0x150(%rsp), %rcx
leaq 0x120(%rsp), %r8
movq %rbx, %rdi
movss 0x20(%rsp), %xmm0
movss 0x2c(%rsp), %xmm1
callq 0x7ec8
leaq 0x120(%rsp), %rdi
callq 0x8d86
leaq 0x150(%rsp), %rdi
callq 0x8d86
leaq 0x100(%rsp), %rdi
callq 0x3130
leaq 0x30(%rsp), %rdi
callq 0x3130
cvtss2sd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x30b0
leaq 0x50(%rsp), %rdi
callq 0x8e40
leaq 0x68(%rsp), %rdi
callq 0x8e40
leaq 0xa0(%rsp), %rdi
callq 0x8d86
leaq 0xd0(%rsp), %rdi
callq 0x8d86
leaq 0x80(%rsp), %rdi
callq 0x8d9a
movsd 0x10(%rsp), %xmm0
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x8d86
jmp 0x5c19
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x8d86
jmp 0x5c2b
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x3130
jmp 0x5c3d
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3130
jmp 0x5c4e
jmp 0x5c4b
movq %rax, %rbx
leaq 0x180(%rsp), %rdi
callq 0x30b0
jmp 0x5c95
jmp 0x5c6f
movq %rax, %rbx
jmp 0x5c9f
jmp 0x5cab
jmp 0x5c6f
jmp 0x5c6f
movq %rax, %rbx
jmp 0x5cc8
movq %rax, %rbx
jmp 0x5c95
movq %rax, %rbx
jmp 0x5c88
jmp 0x5cab
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8e40
leaq 0x180(%rsp), %rdi
callq 0x8e40
leaq 0x50(%rsp), %rdi
callq 0x8e40
leaq 0x68(%rsp), %rdi
callq 0x8e40
jmp 0x5cae
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x8d86
leaq 0xd0(%rsp), %rdi
callq 0x8d86
leaq 0x80(%rsp), %rdi
callq 0x8d9a
movq %rbx, %rdi
callq 0x3560
nop