// File: /workspace/github_cpp_makefile_star2_O1/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 0x6695
movq %rax, 0x8(%rbx)
cmpl $0x0, (%r14)
jle 0x685a
xorl %r12d, %r12d
xorpd %xmm6, %xmm6
movabsq $-0x3f07961000000000, %r13 # imm = 0xC0F869F000000000
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
movsd 0x998e(%rip), %xmm7     # 0x10050
movsd 0x9c25(%rip), %xmm8     # 0x102f0
movsd 0x9c24(%rip), %xmm9     # 0x102f8
movq 0x88(%r14), %rdx
movq (%rdx), %rax
movsd (%rax,%r12,8), %xmm0
ucomisd %xmm6, %xmm0
jbe 0x66fd
movq (%rdx), %rax
movsd (%rax,%r12,8), %xmm0
movq %r13, 0x8(%rsp)
jmp 0x67ff
jne 0x684b
jp 0x684b
movq 0x90(%r14), %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
imulq %rbp, %rcx
cmpq $0x2, %rcx
jb 0x674c
leaq 0x18(%rdx), %rdi
movl $0x1, %esi
movq (%rdi), %r8
movsd (%r8,%r12,8), %xmm0
ucomisd %xmm7, %xmm0
jne 0x673b
jnp 0x6749
incq %rsi
addq $0x18, %rdi
cmpq %rsi, %rcx
jne 0x672a
jmp 0x674c
movl %esi, %r15d
movq 0x8(%rdx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movsd 0x9b89(%rip), %xmm0     # 0x102e8
movsd 0x9b71(%rip), %xmm2     # 0x102d8
decq %rcx
je 0x67f9
xorps %xmm0, %xmm0
cvtsi2ssl 0x28(%r14), %xmm0
xorps 0x9b40(%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 0x9b3c(%rip), %xmm3     # 0x102d8
movsd 0x9b44(%rip), %xmm0     # 0x102e8
movsd (%rax,%rsi,8), %xmm4
ucomisd %xmm6, %xmm4
jne 0x67b1
jnp 0x67e9
ucomisd %xmm8, %xmm4
jae 0x67e9
movq (%rdx), %rdi
movsd (%rdi,%rsi,8), %xmm5
mulsd %xmm1, %xmm5
movapd %xmm9, %xmm2
divsd %xmm5, %xmm2
mulsd %xmm4, %xmm2
ucomisd %xmm5, %xmm6
jbe 0x67e3
ucomisd %xmm2, %xmm0
jbe 0x67e3
movapd %xmm2, %xmm0
jmp 0x67e9
ucomisd %xmm3, %xmm2
ja 0x67ed
movapd %xmm3, %xmm2
incq %rsi
movapd %xmm2, %xmm3
cmpq %rsi, %rcx
jne 0x67a4
movsd %xmm2, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x6820
movupd 0x8(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%rbx)
jmp 0x684b
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0xe5fa
movsd 0x9ac2(%rip), %xmm9     # 0x102f8
movsd 0x9ab1(%rip), %xmm8     # 0x102f0
movsd 0x9809(%rip), %xmm7     # 0x10050
xorpd %xmm6, %xmm6
incq %r12
movslq (%r14), %rax
cmpq %rax, %r12
jl 0x66d4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop