// File: mororo18[P]simplex-method/src/model.cpp
// Function: Model::tableau_resize(Model::cstr)
void Model::tableau_resize(Model::cstr cstr_new){

    int row_size = tableau[0].size();
    // add new row
    //std::vector<double> row_new = row_vec;
    std::vector<double> row_new = cstr_new.coef_get();

    //if(id == G_EQ){
    if(cstr_new.type_id == G_EQ){
        for(int row = var_qnt; row < tableau[0].size(); row++)
            row_new.push_back(0); 
        row_new.push_back(-1); 
        row_new.push_back(0); 

        //row_new.push_back(value);
        row_new.push_back(cstr_new.value);

        int col_i = row_size - 1;

        for(int row = 0; row < tableau.size(); row++){
            tableau[row].insert(tableau[row].begin() + col_i, 0);
            tableau[row].insert(tableau[row].begin() + col_i, 0);
        }

    }else { 
        for(int row = var_qnt; row < tableau[0].size(); row++)
            row_new.push_back(0); 

        //row_new.push_back(value);
        row_new.push_back(cstr_new.value);

        int col_i = row_size - 1;

        for(int row = 0; row < tableau.size(); row++)
            tableau[row].insert(tableau[row].begin() + col_i, 0);
    }

    // update I_index vec
    I_index.push_back(tableau[0].size() - 2);

    //if(id == G_EQ || id == EQ)
    if(cstr_new.type_id == G_EQ || cstr_new.type_id == EQ)
        vec_add_vec(tableau[0], row_new, -BIG_M);

    int col_i = row_new.size() - 2;
    row_new[col_i] = 1;

    //clean columns of basic vars
    for(int col = 0; col < tableau[0].size() - 1; col++){

        if(tableau[0][col] == 0 && row_new[col] != 0){
            int row_i;
            for(int row = 0; row < tableau.size(); row++){
                if(tableau[row][col] == 1){
                    row_i = row;
                    break;
                }
            }

            double coef = row_new[col];

            vec_add_vec(row_new, tableau[row_i], -coef);

            break;
        }
    }

    tableau.push_back(row_new);
}

// Assembly:
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rsi, 0x88(%rsp)
movq %rdi, 0x1a0(%rsp)
movq %rsi, 0x198(%rsp)
movq 0x1a0(%rsp), %rdi
movq %rdi, 0x80(%rsp)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
callq 0x6420
movq 0x88(%rsp), %rsi
movl %eax, 0x194(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x8a60
movq 0x88(%rsp), %rsi
cmpl $-0x1, 0x20(%rsi)
jne 0xca86
movq 0x80(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x174(%rsp)
movq 0x80(%rsp), %rdi
movslq 0x174(%rsp), %rax
movq %rax, 0x78(%rsp)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
callq 0x6420
movq %rax, %rcx
movq 0x78(%rsp), %rax
cmpq %rcx, %rax
jae 0xc84e
movq $0x0, 0x168(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x10b70
jmp 0xc813
jmp 0xc815
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0xc7b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x160(%rsp)
movl %eax, 0x15c(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x6bc0
jmp 0xcf2e
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x150(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x10b70
jmp 0xc877
movq $0x0, 0x148(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x10b70
jmp 0xc89a
movq 0x88(%rsp), %rsi
addq $0x28, %rsi
leaq 0x178(%rsp), %rdi
callq 0x10ba0
jmp 0xc8b5
movl 0x194(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x144(%rsp)
movl $0x0, 0x140(%rsp)
movq 0x80(%rsp), %rdi
movslq 0x140(%rsp), %rax
movq %rax, 0x70(%rsp)
addq $0x88, %rdi
callq 0x10760
movq %rax, %rcx
movq 0x70(%rsp), %rax
cmpq %rcx, %rax
jae 0xca81
movq 0x80(%rsp), %rdi
addq $0x88, %rdi
movq %rdi, 0x58(%rsp)
movslq 0x140(%rsp), %rsi
callq 0x10780
movq 0x58(%rsp), %rdi
movq %rax, 0x60(%rsp)
movslq 0x140(%rsp), %rsi
callq 0x10780
movq %rax, %rdi
callq 0x11540
movq %rax, 0x128(%rsp)
movslq 0x144(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x11570
movq %rax, 0x130(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x115b0
movq 0x60(%rsp), %rdi
movq $0x0, 0x120(%rsp)
movq 0x138(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0x11500
movq %rax, 0x68(%rsp)
jmp 0xc9aa
movq 0x80(%rsp), %rdi
movq 0x68(%rsp), %rax
movq %rax, 0x118(%rsp)
addq $0x88, %rdi
movq %rdi, 0x40(%rsp)
movslq 0x140(%rsp), %rsi
callq 0x10780
movq 0x40(%rsp), %rdi
movq %rax, 0x48(%rsp)
movslq 0x140(%rsp), %rsi
callq 0x10780
movq %rax, %rdi
callq 0x11540
movq %rax, 0x100(%rsp)
movslq 0x144(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x11570
movq %rax, 0x108(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x115b0
movq 0x48(%rsp), %rdi
movq $0x0, 0xf8(%rsp)
movq 0x110(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x11500
movq %rax, 0x50(%rsp)
jmp 0xca5e
movq 0x50(%rsp), %rax
movq %rax, 0xf0(%rsp)
movl 0x140(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x140(%rsp)
jmp 0xc8d1
jmp 0xcc3e
movq 0x80(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xec(%rsp)
movq 0x80(%rsp), %rdi
movslq 0xec(%rsp), %rax
movq %rax, 0x38(%rsp)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
callq 0x6420
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0xcb09
movq $0x0, 0xe0(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x10b70
jmp 0xcaf4
jmp 0xcaf6
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0xca97
movq 0x88(%rsp), %rsi
addq $0x28, %rsi
leaq 0x178(%rsp), %rdi
callq 0x10ba0
jmp 0xcb24
movl 0x194(%rsp), %eax
subl $0x1, %eax
movl %eax, 0xdc(%rsp)
movl $0x0, 0xd8(%rsp)
movq 0x80(%rsp), %rdi
movslq 0xd8(%rsp), %rax
movq %rax, 0x30(%rsp)
addq $0x88, %rdi
callq 0x10760
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0xcc3c
movq 0x80(%rsp), %rdi
addq $0x88, %rdi
movq %rdi, 0x18(%rsp)
movslq 0xd8(%rsp), %rsi
callq 0x10780
movq 0x18(%rsp), %rdi
movq %rax, 0x20(%rsp)
movslq 0xd8(%rsp), %rsi
callq 0x10780
movq %rax, %rdi
callq 0x11540
movq %rax, 0xc0(%rsp)
movslq 0xdc(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x11570
movq %rax, 0xc8(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x115b0
movq 0x20(%rsp), %rdi
movq $0x0, 0xb8(%rsp)
movq 0xd0(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x11500
movq %rax, 0x28(%rsp)
jmp 0xcc19
movq 0x28(%rsp), %rax
movq %rax, 0xb0(%rsp)
movl 0xd8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
jmp 0xcb40
jmp 0xcc3e
movq 0x80(%rsp), %rdi
movq %rdi, %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, 0x10(%rsp)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
callq 0x6420
movq 0x10(%rsp), %rdi
addl $-0x2, %eax
movl %eax, 0xac(%rsp)
leaq 0xac(%rsp), %rsi
callq 0x10c10
jmp 0xcc8a
movq 0x88(%rsp), %rax
cmpl $-0x1, 0x20(%rax)
je 0xcca6
movq 0x88(%rsp), %rax
cmpl $0x0, 0x20(%rax)
jne 0xccde
movq 0x80(%rsp), %rdi
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq 0x80(%rsp), %rdi
movq %rax, %rsi
leaq 0x178(%rsp), %rdx
movsd 0xe5cf(%rip), %xmm0     # 0x1b2a8
callq 0x8bf0
leaq 0x178(%rsp), %rdi
callq 0x6420
subq $0x2, %rax
movl %eax, 0xa8(%rsp)
movslq 0xa8(%rsp), %rsi
leaq 0x178(%rsp), %rdi
callq 0x109f0
movsd 0xe33d(%rip), %xmm0     # 0x1b050
movsd %xmm0, (%rax)
movl $0x0, 0xa4(%rsp)
movq 0x80(%rsp), %rdi
movslq 0xa4(%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 0xcefb
movq 0x80(%rsp), %rdi
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x10780
movq %rax, %rdi
movslq 0xa4(%rsp), %rsi
callq 0x109f0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xcee3
jp 0xcee3
movslq 0xa4(%rsp), %rsi
leaq 0x178(%rsp), %rdi
callq 0x109f0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xcdcc
jp 0xcdcc
jmp 0xcee3
movl $0x0, 0x9c(%rsp)
movq 0x80(%rsp), %rdi
movslq 0x9c(%rsp), %rax
movq %rax, (%rsp)
addq $0x88, %rdi
callq 0x10760
movq %rax, %rcx
movq (%rsp), %rax
cmpq %rcx, %rax
jae 0xce6b
movq 0x80(%rsp), %rdi
addq $0x88, %rdi
movslq 0x9c(%rsp), %rsi
callq 0x10780
movq %rax, %rdi
movslq 0xa4(%rsp), %rsi
callq 0x109f0
movsd (%rax), %xmm0
movsd 0xe215(%rip), %xmm1     # 0x1b050
ucomisd %xmm1, %xmm0
jne 0xce53
jp 0xce53
movl 0x9c(%rsp), %eax
movl %eax, 0xa0(%rsp)
jmp 0xce6b
jmp 0xce55
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0xcdd7
movslq 0xa4(%rsp), %rsi
leaq 0x178(%rsp), %rdi
callq 0x109f0
movq 0x80(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
addq $0x88, %rdi
movslq 0xa0(%rsp), %rsi
callq 0x10780
movq 0x80(%rsp), %rdi
movq %rax, %rdx
movsd 0x90(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
leaq 0x178(%rsp), %rsi
callq 0x8bf0
jmp 0xcefb
jmp 0xcee5
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0xcd22
movq 0x80(%rsp), %rdi
addq $0x88, %rdi
leaq 0x178(%rsp), %rsi
callq 0x10ae0
jmp 0xcf19
leaq 0x178(%rsp), %rdi
callq 0x6bc0
addq $0x1a8, %rsp            # imm = 0x1A8
retq
movq 0x160(%rsp), %rdi
callq 0x2350
nopl (%rax,%rax)