// File: /workspace/github_cpp_makefile_star2_O3/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 0x6657
movq %rax, 0x8(%rbx)
cmpl $0x0, (%r14)
jle 0x6813
xorl %r12d, %r12d
xorpd %xmm6, %xmm6
movabsq $-0x3f07961000000000, %r13 # imm = 0xC0F869F000000000
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
movsd 0x99cc(%rip), %xmm7     # 0x10050
movsd 0x9c63(%rip), %xmm8     # 0x102f0
movsd 0x9c62(%rip), %xmm9     # 0x102f8
movq 0x88(%r14), %rdx
movq (%rdx), %rax
movsd (%rax,%r12,8), %xmm0
ucomisd %xmm6, %xmm0
jbe 0x66b6
movq %r13, 0x8(%rsp)
jmp 0x67b8
jne 0x6804
jp 0x6804
movq 0x90(%r14), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
imulq %rbp, %rcx
cmpq $0x2, %rcx
jb 0x6705
leaq 0x18(%rdx), %rdi
movl $0x1, %esi
movq (%rdi), %r8
movsd (%r8,%r12,8), %xmm0
ucomisd %xmm7, %xmm0
jne 0x66f4
jnp 0x6702
incq %rsi
addq $0x18, %rdi
cmpq %rsi, %rcx
jne 0x66e3
jmp 0x6705
movl %esi, %r15d
movq 0x8(%rdx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movsd 0x9bd0(%rip), %xmm0     # 0x102e8
movsd 0x9bb8(%rip), %xmm2     # 0x102d8
decq %rcx
je 0x67b2
xorps %xmm0, %xmm0
cvtsi2ssl 0x28(%r14), %xmm0
xorps 0x9b87(%rip), %xmm0     # 0x102c0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movslq %r15d, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
xorl %esi, %esi
movsd 0x9b83(%rip), %xmm3     # 0x102d8
movsd 0x9b8b(%rip), %xmm0     # 0x102e8
movsd (%rax,%rsi,8), %xmm4
ucomisd %xmm6, %xmm4
jne 0x676a
jnp 0x67a2
ucomisd %xmm8, %xmm4
jae 0x67a2
movq (%rdx), %rdi
movsd (%rdi,%rsi,8), %xmm5
mulsd %xmm1, %xmm5
movapd %xmm9, %xmm2
divsd %xmm5, %xmm2
mulsd %xmm4, %xmm2
ucomisd %xmm5, %xmm6
jbe 0x679c
ucomisd %xmm2, %xmm0
jbe 0x679c
movapd %xmm2, %xmm0
jmp 0x67a2
ucomisd %xmm3, %xmm2
ja 0x67a6
movapd %xmm3, %xmm2
incq %rsi
movapd %xmm2, %xmm3
cmpq %rsi, %rcx
jne 0x675d
movsd %xmm2, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x67d9
movupd 0x8(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%rbx)
jmp 0x6804
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0xe79a
movsd 0x9b09(%rip), %xmm9     # 0x102f8
movsd 0x9af8(%rip), %xmm8     # 0x102f0
movsd 0x9850(%rip), %xmm7     # 0x10050
xorpd %xmm6, %xmm6
incq %r12
movslq (%r14), %rax
cmpq %rax, %r12
jl 0x6696
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq