// File: 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:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rdi
callq 0x110b0
testb $0x1, %al
jne 0x9d22
movq 0x98(%rsp), %rdi
callq 0x107c0
movl $0x0, 0x94(%rsp)
movq 0x18(%rsp), %rcx
movl 0x94(%rsp), %eax
cmpl (%rcx), %eax
jge 0xa0b4
movq 0x18(%rsp), %rdi
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
movslq 0x94(%rsp), %rsi
callq 0x109f0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x9de3
movq 0x18(%rsp), %rdi
movl $0xfffe7961, 0x6c(%rsp) # imm = 0xFFFE7961
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
movslq 0x94(%rsp), %rsi
callq 0x109f0
movq %rax, %rsi
leaq 0x6c(%rsp), %rdi
callq 0x11190
movl %eax, 0x70(%rsp)
movsd %xmm0, 0x78(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x111d0
movq 0x98(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x11120
jmp 0xa09c
movq 0x18(%rsp), %rdi
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
movslq 0x94(%rsp), %rsi
callq 0x109f0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xa09a
jp 0xa09a
movl $0x1, 0x64(%rsp)
movq 0x18(%rsp), %rdi
movslq 0x64(%rsp), %rax
movq %rax, 0x10(%rsp)
addq $0x88, %rdi
callq 0x10760
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x9ea2
movq 0x18(%rsp), %rdi
addq $0x88, %rdi
movslq 0x64(%rsp), %rsi
callq 0x10780
movq %rax, %rdi
movslq 0x94(%rsp), %rsi
callq 0x109f0
movsd (%rax), %xmm0
movsd 0x111cf(%rip), %xmm1    # 0x1b050
ucomisd %xmm1, %xmm0
jne 0x9e93
jp 0x9e93
movl 0x64(%rsp), %eax
movl %eax, 0x68(%rsp)
jmp 0x9ea2
jmp 0x9e95
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x9e27
movsd 0x11406(%rip), %xmm0    # 0x1b2b0
movsd %xmm0, 0x58(%rsp)
movsd 0x113f0(%rip), %xmm0    # 0x1b2a8
movsd %xmm0, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x18(%rsp), %rdi
movslq 0x4c(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
callq 0x6420
movq %rax, %rcx
movq 0x8(%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0xa06d
movq 0x18(%rsp), %rdi
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
movslq 0x4c(%rsp), %rsi
callq 0x109f0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x9f35
jp 0x9f35
jmp 0x9f69
movq 0x18(%rsp), %rdi
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
movslq 0x4c(%rsp), %rsi
callq 0x109f0
movsd (%rax), %xmm0
movsd 0x11355(%rip), %xmm1    # 0x1b2b8
ucomisd %xmm1, %xmm0
jb 0x9f6e
jmp 0xa05d
movq 0x18(%rsp), %rdi
cvtsi2ssl 0x28(%rdi), %xmm1
movss 0x11340(%rip), %xmm0    # 0x1b2c0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, (%rsp)
addq $0x88, %rdi
movslq 0x68(%rsp), %rsi
callq 0x10780
movq %rax, %rdi
movslq 0x4c(%rsp), %rsi
callq 0x109f0
movsd (%rsp), %xmm0
movq 0x18(%rsp), %rdi
mulsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x11089(%rip), %xmm0    # 0x1b050
divsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
movslq 0x4c(%rsp), %rsi
callq 0x109f0
movsd 0x112a8(%rip), %xmm0    # 0x1b2a0
mulsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x38(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x40(%rsp), %xmm0
jbe 0xa03f
movsd 0x30(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa03f
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
jmp 0xa05b
movsd 0x30(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
jbe 0xa059
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
jmp 0xa05b
jmp 0xa05d
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x9ec6
leaq 0x50(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x11200
movsd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x28(%rsp)
movq 0x98(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11120
jmp 0xa09c
jmp 0xa09e
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x9d2d
addq $0xa8, %rsp
retq
nopl (%rax)