// File: JenTus[P]TCEM/src_TCEM/allocator.cc
// Function: Cide::allocator::lowerBoundOPT()
double allocator::lowerBoundOPT() {

        double epsilon_1 = epsilon * 2.0; //

        for (int x = 1; x < log2(n); x++) {

            int64 theta_x = (2+2.0/3.0 * epsilon_1)* (ell * log(n) + logP(n,k_r,tao) + log(log2(n))) * pow(2.0,x) / (epsilon_1 * epsilon_1);
            //int64 theta_x =  (2+2.0/3.0 * epsilon_1)* (ell * log(n) + logcnk(n*(n-1), k_r*k_b) + log(log2(n))) * pow(2.0,x) / (epsilon_1 * epsilon_1);
            
//            std::cout << "theta_x " << theta_x << std::endl;
            generateRCSets(theta_x);
            
            double ept = rcGreedy(theta_x, false);

//            cout << "ept is: " << ept << endl;

            if (ept > ((1+epsilon_1) / pow(2.0, x))) {
                double lowerBound = ept * n / (1 + epsilon_1);
                // kontrol:
//                std:cout << "x and theta_x " << x << " " << theta_x << std::endl;
                return lowerBound;
            }
        }
        cout << "returning naive lower bound  " << endl;
        double naive = 1.0;
        return naive;
    }

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x40(%rsp)
movsd 0x18d7a(%rip), %xmm0    # 0x24118
mulsd 0x90(%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
movl $0x1, 0x6c(%rsp)
movq 0x40(%rsp), %rax
cvtsi2sdl 0x6c(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0x68(%rax), %edi
callq 0xe010
movsd 0x38(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb579
movq 0x40(%rsp), %rax
movsd 0x70(%rsp), %xmm0
movsd 0x18d30(%rip), %xmm1    # 0x24120
mulsd %xmm1, %xmm0
movsd 0x18d1c(%rip), %xmm1    # 0x24118
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0xa0(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0x68(%rax), %edi
callq 0xded0
movq 0x40(%rsp), %rax
movsd %xmm0, (%rsp)
movl 0x68(%rax), %edi
movl 0x78(%rax), %esi
movl 0x80(%rax), %edx
callq 0xdef0
movsd (%rsp), %xmm2
movq 0x40(%rsp), %rax
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x68(%rax), %edi
callq 0xe010
callq 0x42b0
movsd 0x10(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x18(%rsp), %xmm0
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movl 0x6c(%rsp), %edi
movsd 0x18c8a(%rip), %xmm0    # 0x24118
callq 0xe030
movq 0x40(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x70(%rsp), %xmm1
mulsd 0x70(%rsp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rsi
callq 0xb5d0
movq 0x40(%rsp), %rdi
movq 0x60(%rsp), %rsi
xorl %edx, %edx
callq 0xb910
movsd %xmm0, 0x58(%rsp)
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x18bfc(%rip), %xmm0    # 0x240f0
addsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movl 0x6c(%rsp), %edi
movsd 0x18c0c(%rip), %xmm0    # 0x24118
callq 0xe030
movsd 0x28(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x30(%rsp), %xmm0
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb567
movq 0x40(%rsp), %rax
movsd 0x58(%rsp), %xmm0
cvtsi2sdl 0x68(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x18baa(%rip), %xmm1    # 0x240f0
addsd 0x70(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
jmp 0xb5b8
jmp 0xb569
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0xb3b4
movq 0x23a58(%rip), %rdi     # 0x2efd8
leaq 0x18c84(%rip), %rsi     # 0x2420b
callq 0x4370
movq %rax, %rdi
movq 0x23a32(%rip), %rsi     # 0x2efc8
callq 0x43c0
movsd 0x18b4d(%rip), %xmm0    # 0x240f0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x80(%rsp), %xmm0
addq $0x88, %rsp
retq
nopl (%rax)