// File: /workspace/github_cpp_makefile_star2_O2/JenTus[P]TCEM/src_TCEM/allocator.cc
// Function: Cide::allocator::allocator(AnyOption*)
allocator::allocator(AnyOption* opt1) {
        
        opt = opt1;
        probGraphFile = opt->getValue("x");
        compareFile = opt->getValue("p"); // it can be empty

        //delim = " \t";
        delim = " ";

        readGraphNodes(); // assign n and m

        sfmt_init_gen_rand(&sfmtSeed , 95082);

        if (compareFile == NULL) {
            cout << "Red k_r and k_b" << endl;
            k_r = strToInt(opt->getValue("r"));
            k_b = strToInt(opt->getValue("b"));
            cout << "kr is " << k_r << " " << "kb is " << k_b << endl;
        } else{
            std::string cF(compareFile);
            int beginIdx = cF.rfind('/');
            compareFileShort = cF.substr(beginIdx + 1);
            for (int j = 0; j < 4; ++j) {
                compareFileShort.pop_back();
            }
            readCompareNodes();
        }

        tao = ceil((double)k_b/(double)k_r);

//        P = Permutation(n, k_r*(tao + 1)) / (double) (pow(fact(tao), k_r) * fact(k_r));

        nrItems = 2;
        epsilon = strToDouble(opt->getValue("epsilon"));
        ell = strToDouble(opt->getValue("ell"));
        outFolderName = opt->getValue("outputFolder");
    
        nrPairs = n * nrItems; // multiple items

        nodeDegree.resize(n);
        
        for(int i = 0; i < n; i++)
            graphT.emplace_back(vector<int>());

        prevSize = 0; // when sample the first node
        //for(int i = 0; i < nrPairs; i++)
        //    hyperG.emplace_back(std::vector<int>());

        // create new pairs-related functions
        hyper_degreepairs = std::vector<double>(n*n, 0);
        for (int i = 0; i < n*n; ++i) {
           hyperGpairs.emplace_back(std::vector<int>());
        }

        rcList = new itemGraphList();
        //item-specific probT is aligned with graphT for each item
        for(int i = 0; i < nrItems; i++) {
            //_Cide::itemGraph *ig = new _Cide::itemGraph(n);
            auto *ig = new _Cide::itemGraph(n);
            for (int j = 0; j < n; j++)
                ig->probT.emplace_back(std::vector< double>());
            rcList->push_back(ig);
        }

        //nodeDegree = std::vector<double>(n,0.0);
        
        cout << "nr items " << nrItems << endl;
        //cout << "assignment size " << k << endl;

        readTICGraph();

        cout << "successfully read everything " << endl;

        arrangeOutputFiles();
        cout << "starting assignment for tcem" << endl;
        tdem();
        
// comment out below to run the baselines
        degreeVersionOne(theta);
        degreeVersionTwo(theta);
        mni(theta);
        if(compareFile!=NULL){
            compareGivenNodes(theta);
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x20(%rdi), %rax
movq %rax, 0x68(%rsp)
leaq 0x30(%rdi), %rax
movq %rax, 0x20(%rdi)
andq $0x0, 0x28(%rdi)
xorl %eax, %eax
movb %al, 0x30(%rdi)
leaq 0x48(%rdi), %rcx
movq %rcx, 0x48(%rsp)
leaq 0x58(%rdi), %rcx
movq %rcx, 0x48(%rdi)
andq $0x0, 0x50(%rdi)
movb %al, 0x58(%rdi)
leaq 0xd8(%rdi), %rcx
movq %rcx, 0x58(%rsp)
leaq 0xb40(%rdi), %r13
leaq 0xb88(%rdi), %rcx
xorpd %xmm0, %xmm0
movupd %xmm0, 0xa8(%rdi)
movupd %xmm0, 0xb8(%rdi)
movupd %xmm0, 0xc8(%rdi)
movupd %xmm0, 0xd8(%rdi)
movupd %xmm0, 0xe8(%rdi)
andq $0x0, 0x118(%rdi)
movupd %xmm0, 0xf8(%rdi)
movupd %xmm0, 0x108(%rdi)
movupd %xmm0, 0xaf0(%rdi)
movupd %xmm0, 0xb00(%rdi)
movupd %xmm0, 0xb10(%rdi)
movupd %xmm0, 0xb28(%rdi)
movupd %xmm0, 0xb38(%rdi)
movupd %xmm0, 0xb48(%rdi)
movupd %xmm0, 0xb58(%rdi)
andq $0x0, 0xb68(%rdi)
movq %rcx, 0xb78(%rdi)
andq $0x0, 0xb80(%rdi)
leaq 0xb58(%rdi), %rcx
movq %rcx, 0x50(%rsp)
leaq 0xb78(%rdi), %rcx
movq %rcx, 0x60(%rsp)
movb %al, 0xb88(%rdi)
addq $0xb98, %rdi            # imm = 0xB98
movq %rdi, 0x8(%rsp)
callq 0x3520
leaq 0xda8(%r15), %rax
movq %rax, 0xd98(%r15)
andq $0x0, 0xda0(%r15)
xorl %eax, %eax
movb %al, 0xda8(%r15)
leaq 0xdc8(%r15), %rcx
movq %rcx, 0xdb8(%r15)
andq $0x0, 0xdc0(%r15)
leaq 0xd98(%r15), %rcx
movq %rcx, 0x18(%rsp)
movb %al, 0xdc8(%r15)
movq %rbx, 0x18(%r15)
leaq 0xa4ed(%rip), %rsi      # 0xe0bf
movq %rbx, %rdi
callq 0xceb8
movq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x35a0
movq 0x18(%r15), %rdi
leaq 0xa4cb(%rip), %rsi      # 0xe0bd
callq 0xceb8
movq %rax, 0x40(%r15)
leaq 0xa645(%rip), %rsi      # 0xe247
movq 0x60(%rsp), %rdi
callq 0x35a0
movq %r15, %rdi
callq 0x4190
leaq 0x120(%r15), %rdi
movl $0x1736a, %esi          # imm = 0x1736A
callq 0xdb1d
movq 0x40(%r15), %rsi
testq %rsi, %rsi
je 0x3cb2
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x3100
leaq 0x20(%rsp), %rbx
pushq $0x2f
popq %rsi
pushq $-0x1
popq %r12
movq %rbx, %rdi
movq %r12, %rdx
callq 0x35c0
incl %eax
movslq %eax, %rdx
leaq 0x78(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rcx
callq 0x32e0
leaq 0x78(%rsp), %rbx
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x3380
movq %rbx, %rdi
callq 0x3130
pushq $0x4
popq %rbx
subl $0x1, %ebx
jb 0x3c9b
movq 0x48(%rsp), %rdi
callq 0x3370
jmp 0x3c8a
movq %r15, %rdi
callq 0x43a6
leaq 0x20(%rsp), %rdi
callq 0x3130
jmp 0x3d56
movq 0x1131f(%rip), %rdi     # 0x14fd8
leaq 0xa4b0(%rip), %rsi      # 0xe170
callq 0x32c0
movq %rax, %rdi
callq 0x3150
movq 0x18(%r15), %rdi
leaq 0xa3d4(%rip), %rsi      # 0xe0ac
callq 0xceb8
movq %rax, %rdi
callq 0x81dc
movl %eax, 0x78(%r15)
movq 0x18(%r15), %rdi
leaq 0xa48a(%rip), %rsi      # 0xe17e
callq 0xceb8
movq %rax, %rdi
callq 0x81dc
movl %eax, 0x7c(%r15)
movq 0x112cc(%rip), %rdi     # 0x14fd8
leaq 0xa46d(%rip), %rsi      # 0xe180
callq 0x32c0
movl 0x78(%r15), %esi
movq %rax, %rdi
callq 0x3530
leaq 0xa51c(%rip), %rsi      # 0xe247
movq %rax, %rdi
callq 0x32c0
leaq 0xa44d(%rip), %rsi      # 0xe187
movq %rax, %rdi
callq 0x32c0
movl 0x7c(%r15), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3150
cvtsi2sdl 0x7c(%r15), %xmm0
cvtsi2sdl 0x78(%r15), %xmm1
divsd %xmm1, %xmm0
callq 0x3070
cvttsd2si %xmm0, %eax
movl %eax, 0x80(%r15)
movl $0x2, 0x70(%r15)
movq 0x18(%r15), %rdi
leaq 0xa325(%rip), %rsi      # 0xe0ae
callq 0xceb8
leaq 0xb8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %rax, %rsi
callq 0x3100
leaq 0xb8(%rsp), %rdi
callq 0x82b5
movsd %xmm0, 0x90(%r15)
leaq 0xb8(%rsp), %rdi
callq 0x3130
movq 0x18(%r15), %rdi
leaq 0xa2e5(%rip), %rsi      # 0xe0b6
callq 0xceb8
leaq 0x98(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %rax, %rsi
callq 0x3100
leaq 0x98(%rsp), %rdi
callq 0x82b5
movsd %xmm0, 0xa0(%r15)
leaq 0x98(%rsp), %rdi
callq 0x3130
movq 0x18(%r15), %rdi
leaq 0xa288(%rip), %rsi      # 0xe0a1
callq 0xceb8
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x35a0
movslq 0x68(%r15), %rsi
movl 0x70(%r15), %eax
imull %esi, %eax
movl %eax, 0x74(%r15)
movq 0x58(%rsp), %rdi
callq 0x8326
xorl %ebp, %ebp
leaq 0x114cb(%rip), %rbx     # 0x15318
leaq 0x20(%rsp), %r12
movl 0x68(%r15), %esi
cmpl %esi, %ebp
jge 0x3e81
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x8358
movq %r12, %rdi
callq 0x8e40
incl %ebp
jmp 0x3e52
andq $0x0, 0xb20(%r15)
imull %esi, %esi
leaq 0x78(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x838e
leaq 0x20(%rsp), %rbx
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x9248
movq %rbx, %rdi
callq 0x8e4e
xorl %ebp, %ebp
movl 0x68(%r15), %eax
imull %eax, %eax
cmpl %eax, %ebp
jae 0x3ef2
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8358
movq %rbx, %rdi
callq 0x8e40
incl %ebp
jmp 0x3ec0
pushq $0x18
popq %rdi
callq 0x32d0
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %rax, 0xae8(%r15)
xorl %r14d, %r14d
leaq 0x20(%rsp), %rbx
leaq 0x78(%rsp), %r12
cmpl 0x70(%r15), %r14d
jge 0x3f84
movl $0xa88, %edi            # imm = 0xA88
callq 0x32d0
movq %rax, %rbp
movl 0x68(%r15), %esi
movq %rax, %rdi
callq 0xb490
movq %rbp, 0x78(%rsp)
xorl %ebp, %ebp
cmpl 0x68(%r15), %ebp
jge 0x3f70
movq 0x78(%rsp), %rdi
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %rbx, %rsi
callq 0x83ea
movq %rbx, %rdi
callq 0x8e4e
incl %ebp
jmp 0x3f41
movq 0xae8(%r15), %rdi
movq %r12, %rsi
callq 0x841a
incl %r14d
jmp 0x3f1b
movq 0x1104d(%rip), %rdi     # 0x14fd8
leaq 0xa1fc(%rip), %rsi      # 0xe18e
callq 0x32c0
movl 0x70(%r15), %esi
movq %rax, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x3150
movq %r15, %rdi
callq 0x4798
movq 0x1101e(%rip), %rdi     # 0x14fd8
leaq 0xa1d7(%rip), %rsi      # 0xe198
callq 0x32c0
movq %rax, %rdi
callq 0x3150
movq %r15, %rdi
callq 0x4b16
movq 0x10ffb(%rip), %rdi     # 0x14fd8
leaq 0xa1d2(%rip), %rsi      # 0xe1b6
callq 0x32c0
movq %rax, %rdi
callq 0x3150
movq %r15, %rdi
callq 0x4fee
movq 0x10(%r15), %rsi
movq %r15, %rdi
callq 0x5152
movq 0x10(%r15), %rsi
movq %r15, %rdi
callq 0x56f4
movq 0x10(%r15), %rsi
movq %r15, %rdi
callq 0x5cde
cmpq $0x0, 0x40(%r15)
je 0x4030
movq 0x10(%r15), %rsi
movq %r15, %rdi
callq 0x6a98
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4044
movq %rax, %r14
leaq 0x20(%rsp), %rdi
jmp 0x406c
jmp 0x409a
jmp 0x409a
movq %rax, %r14
leaq 0x98(%rsp), %rdi
jmp 0x406c
jmp 0x409a
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x3130
jmp 0x40ac
jmp 0x409a
movq %rax, %r14
jmp 0x40cf
jmp 0x409a
movq %rax, %r14
movq %rbp, %rdi
callq 0x32b0
jmp 0x40ac
jmp 0x408b
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x8e40
jmp 0x40ac
movq %rax, %r14
jmp 0x40ac
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x8e4e
movq 0x8(%rsp), %rbx
leaq 0xdb8(%r15), %rdi
callq 0x3130
movq 0x18(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x3460
leaq 0xa8(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0xaf0(%r15), %rbp
leaq 0xb28(%r15), %rbx
leaq 0xb08(%r15), %r12
leaq 0x108(%r15), %rax
movq %rax, 0x70(%rsp)
leaq 0xf0(%r15), %rax
movq %rax, 0x8(%rsp)
addq $0xc0, %r15
movq 0x60(%rsp), %rdi
callq 0x3130
movq 0x50(%rsp), %rdi
callq 0x8e4e
movq %r13, %rdi
callq 0x8438
movq %rbx, %rdi
callq 0x8438
movq %r12, %rdi
callq 0x8e40
movq %rbp, %rdi
callq 0x8e4e
movq 0x70(%rsp), %rdi
callq 0x8e40
movq 0x8(%rsp), %rdi
callq 0x8e40
movq 0x58(%rsp), %rdi
callq 0x8e4e
movq %r15, %rdi
callq 0x8e4e
movq 0x18(%rsp), %rdi
callq 0x8e40
movq 0x48(%rsp), %rdi
callq 0x3130
movq 0x68(%rsp), %rdi
callq 0x3130
movq %r14, %rdi
callq 0x3560
nop