// File: /workspace/github_cpp_makefile_star2_O2/mororo18[P]simplex-method/src/model.cpp
// Function: Model::c_range_calc(std::vector<std::pair<double, double>, std::allocator<std::pair<double, double>>>&)
void Model::c_range_calc(std::vector<std::pair<double, double>> & c_range){
    
    if(!c_range.empty())
        c_range.clear();

    for(int col = 0; col < var_qnt; col++){
        // non basic
        if(tableau[0][col] > 0){
            // the upper bound is the coef of x_n in the row 0
            std::pair<double, double> range = std::make_pair(-INFINITE, tableau[0][col]);
            c_range.push_back(range);

        // basic
        }else if(tableau[0][col] == 0){
            // subtracts the row where the coef of x_n is 1 from thow row 0, 
            // and with the new values defines the upper and the lower bounds
            // (value >= 0) 

            int row_i;

            // identify the var row, where c_i_row == 1
            for(int row = 1; row < tableau.size(); row++){
                if(tableau[row][col] == 1){
                    row_i = row;
                    break;
                }
            }

            double upper_bound = INFINITE ; 
            double lower_bound = -INFINITE ;

            for(int col_i = 0; col_i < tableau[0].size() - 1; col_i++){
                if(tableau[0][col_i] == 0 || tableau[0][col_i] >= INFINITE -2)
                    continue;

                double coef = -1.0f * type_id * tableau[row_i][col_i];
                double coef_inv = 1.0f / coef;
                double value = -1.0f * tableau[0][col_i];

                value *= coef_inv;

                if(coef < 0 && value < upper_bound){
                    upper_bound = value;
                }else if(value > lower_bound){
                    lower_bound = value;
                }
                
            }

            std::pair<double, double> range = std::make_pair(lower_bound, upper_bound);
            //std::cout << "var X_" << col << "  de " << lower_bound << " a " << upper_bound << std::endl;

            c_range.push_back(range);
            
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rsi), %rax
cmpq 0x8(%rsi), %rax
je 0x55a3
movq %rax, 0x8(%rbx)
xorl %r12d, %r12d
xorpd %xmm6, %xmm6
movabsq $-0x3f07961000000000, %r13 # imm = 0xC0F869F000000000
leaq 0x8(%rsp), %r15
movsd 0x6a8f(%rip), %xmm1     # 0xc050
movsd 0x6d0f(%rip), %xmm7     # 0xc2d8
movsd 0x6ce6(%rip), %xmm8     # 0xc2b8
movslq (%r14), %rax
cmpq %rax, %r12
jge 0x573f
movq 0x88(%r14), %rsi
movq (%rsi), %rcx
movsd (%rcx,%r12,8), %xmm0
ucomisd %xmm6, %xmm0
jbe 0x562c
movq %r13, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9422
movsd 0x6ca5(%rip), %xmm8     # 0xc2b8
movsd 0x6cbd(%rip), %xmm7     # 0xc2d8
movsd 0x6a2d(%rip), %xmm1     # 0xc050
xorpd %xmm6, %xmm6
jmp 0x5737
jne 0x5737
jp 0x5737
movq 0x90(%r14), %rax
subq %rsi, %rax
cqto
pushq $0x18
popq %rdi
idivq %rdi
leaq 0x18(%rsi), %rdi
pushq $0x1
popq %rdx
cmpq %rdx, %rax
jbe 0x5672
movq (%rdi), %r8
movsd (%r8,%r12,8), %xmm0
ucomisd %xmm1, %xmm0
jne 0x5667
jnp 0x5670
incq %rdx
addq $0x18, %rdi
jmp 0x5651
movl %edx, %ebp
movq 0x8(%rsi), %rax
subq %rcx, %rax
sarq $0x3, %rax
decq %rax
cvtsi2ssl 0x28(%r14), %xmm0
xorps 0x6c13(%rip), %xmm0     # 0xc2a0
cvtss2sd %xmm0, %xmm0
movslq %ebp, %rdx
imulq $0x18, %rdx, %rdx
addq %rsi, %rdx
xorl %esi, %esi
movsd 0x6c2b(%rip), %xmm1     # 0xc2d0
movsd 0x6c13(%rip), %xmm2     # 0xc2c0
cmpq %rsi, %rax
je 0x5703
movsd (%rcx,%rsi,8), %xmm4
ucomisd %xmm6, %xmm4
jne 0x56bf
jnp 0x56f6
ucomisd %xmm7, %xmm4
jae 0x56f6
movq (%rdx), %rdi
movsd (%rdi,%rsi,8), %xmm5
mulsd %xmm0, %xmm5
movapd %xmm8, %xmm3
divsd %xmm5, %xmm3
mulsd %xmm4, %xmm3
ucomisd %xmm5, %xmm6
jbe 0x56f0
ucomisd %xmm3, %xmm1
jbe 0x56f0
movapd %xmm3, %xmm1
jmp 0x56f6
ucomisd %xmm2, %xmm3
ja 0x56fa
movapd %xmm2, %xmm3
incq %rsi
movapd %xmm3, %xmm2
jmp 0x56ad
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9422
movsd 0x6b95(%rip), %xmm8     # 0xc2b8
movsd 0x6bad(%rip), %xmm7     # 0xc2d8
xorpd %xmm6, %xmm6
movsd 0x6919(%rip), %xmm1     # 0xc050
incq %r12
jmp 0x55d2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq