// File: /workspace/github_cpp_makefile_star2_O1/mororo18[P]simplex-method/src/model.cpp
// Function: Model::tableau_generate()
void Model::tableau_generate(){

    if(!tableau.empty()){
        tableau.clear();
        I_index.clear();
    }

    const int cstr_qnt = cstr_vec.size();
    int n = var_qnt;

    // store the original coef value
    original_coef = main_func->coef_get();

    // insert the first row
    tableau.push_back(original_coef);

    int slack_cols = 0;

    // columns for slack variables of first row 
    for(int i = 0; i < cstr_qnt; i++){
        if(cstr_vec[i].type_id == G_EQ){
            // the two cols of the artificial variables of the geq constraint
            tableau[0].push_back(0);
            tableau[0].push_back(0);
            slack_cols += 2;
        }else {
            tableau[0].push_back(0);
            slack_cols++;
        }
    }
    
    // current solution value
    tableau[0].push_back(0);

    if(type_id == MAX)
        vec_multiply_scalar(tableau[0], MAX);

    for(int i = 0; i < cstr_vec.size(); i++){
        std::vector<double> tableau_row = cstr_vec[i].coef_get();

        // slack vars cols
        for(int j = 0; j < slack_cols; j++){
            tableau_row.push_back(0);
        }

        double cstr_value = cstr_vec[i].value;
        tableau_row.push_back(cstr_value);

        if(cstr_vec[i].type_id == EQ){
            // subtract the first row(obj_func) by the current row times BIG_M (eq_cstr)
            vec_add_vec(tableau[0], tableau_row, -BIG_M);

            // store the original coef value of the slack var
            original_coef.push_back(BIG_M);
        }else if(cstr_vec[i].type_id == G_EQ){
            //vec_multiply_scalar(cstr_cpy, G_EQ);
            tableau_row[n+i] = -1;
            n++;
            vec_add_vec(tableau[0], tableau_row, -BIG_M);

            // store the original coef value of the slack var
            original_coef.push_back(0);
            original_coef.push_back(BIG_M);
        }else
            // store the original coef value of the slack var
            original_coef.push_back(0);

        //add the identity sub-matrix 
        tableau_row[n + i] = 1;

        // store the identity sub-matrix col indexes
        I_index.push_back(n + i);
    
        tableau.push_back(tableau_row);
    }


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x88(%rdi), %r14
movq 0x88(%rdi), %rax
cmpq 0x90(%rdi), %rax
je 0x5941
movq %r14, %rdi
callq 0xd3d2
movq 0x190(%rbx), %rax
cmpq %rax, 0x198(%rbx)
je 0x5941
movq %rax, 0x198(%rbx)
movq %r14, 0x48(%rsp)
movq 0x60(%rbx), %r12
subq 0x58(%rbx), %r12
sarq $0x3, %r12
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %r12
movl (%rbx), %eax
movq %rax, 0x38(%rsp)
movq 0x50(%rbx), %rsi
addq $0x20, %rsi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x4b20
movq 0x1c0(%rbx), %rdi
movapd (%r15), %xmm0
movq 0x10(%r15), %rax
movq %rdi, (%r15)
movupd 0x1c8(%rbx), %xmm1
movupd %xmm0, 0x1c0(%rbx)
movq %rax, 0x1d0(%rbx)
movupd %xmm1, 0x8(%r15)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
testq %rdi, %rdi
je 0x59c7
callq 0x21c0
leaq 0x1c0(%rbx), %rax
movq %rax, 0x30(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movq 0x48(%rsp), %r15
je 0x59e7
callq 0x21c0
movq %r15, %rdi
movq 0x30(%rsp), %rsi
callq 0xd4a6
testl %r12d, %r12d
jle 0x5ac7
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl $0x20, %ebp
leaq 0x10(%rsp), %r14
movq 0x58(%rbx), %rax
movq 0x88(%rbx), %rdi
cmpl $-0x1, (%rax,%rbp)
je 0x5a46
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5a6a
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5a72
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5a79
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5a81
movq %r14, %rdx
callq 0xe26c
movl $0x1, %eax
jmp 0x5ab5
movq %r14, %rdx
callq 0xe26c
movq (%r15), %rdi
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5aa8
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5ab0
movq %r14, %rdx
callq 0xe26c
movl $0x2, %eax
addl %eax, %r13d
addq $0x48, %rbp
decq %r12
jne 0x5a11
jmp 0x5aca
xorl %r13d, %r13d
movq (%r15), %rdi
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5af1
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5afb
leaq 0x10(%rsp), %rdx
callq 0xe26c
cmpl $-0x1, 0x28(%rbx)
jne 0x5b5a
movq (%r15), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x5b5a
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
movapd 0xa77a(%rip), %xmm0     # 0x102a0
movsd 0xa7a2(%rip), %xmm1     # 0x102d0
movapd 0xa77a(%rip), %xmm2     # 0x102b0
movsd (%rax,%rdx,8), %xmm3
movapd %xmm3, %xmm4
andpd %xmm0, %xmm4
ucomisd %xmm4, %xmm1
jae 0x5b52
xorpd %xmm2, %xmm3
movlpd %xmm3, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x5b36
movq 0x58(%rbx), %rax
cmpq %rax, 0x60(%rbx)
je 0x5e5b
leaq 0x190(%rbx), %rcx
movq %rcx, 0x50(%rsp)
xorl %r12d, %r12d
leaq 0x10(%rsp), %rbp
leaq (%r12,%r12,8), %r14
leaq (%rax,%r14,8), %rsi
addq $0x30, %rsi
movq %rbp, %rdi
callq 0x4b20
movl %r13d, %r15d
testl %r13d, %r13d
jle 0x5bd1
movq $0x0, 0x40(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5bbf
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x5bcc
movq %rbp, %rdi
leaq 0x40(%rsp), %rdx
callq 0xe26c
decl %r15d
jne 0x5b98
movq 0x58(%rbx), %rax
movsd 0x28(%rax,%r14,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
movq 0x48(%rsp), %r15
je 0x5c02
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x5c0f
movq %rbp, %rdi
leaq 0x40(%rsp), %rdx
callq 0xe388
movq 0x58(%rbx), %rax
movl 0x20(%rax,%r14,8), %eax
cmpl $-0x1, %eax
je 0x5c95
testl %eax, %eax
jne 0x5d20
movq (%r15), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
movsd 0xa69e(%rip), %xmm1     # 0x102d8
je 0x5c6a
sarq $0x3, %rcx
movq 0x10(%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm0
mulsd %xmm1, %xmm0
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x5c4f
movabsq $0x40f869f000000000, %rax # imm = 0x40F869F000000000
movq %rax, 0x8(%rsp)
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x5d4d
movq %rax, (%rsi)
jmp 0x5d40
movq 0x38(%rsp), %rax
addl %r12d, %eax
movslq %eax, %rcx
movq 0x10(%rsp), %rax
movabsq $-0x4010000000000000, %rdx # imm = 0xBFF0000000000000
movq %rdx, (%rax,%rcx,8)
movq (%r15), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
subq %rcx, %rdx
movsd 0xa610(%rip), %xmm1     # 0x102d8
je 0x5cf3
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm0
mulsd %xmm1, %xmm0
addsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x5cd8
movq $0x0, 0x8(%rsp)
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x5d5e
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x5d6d
movq $0x0, 0x8(%rsp)
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x5d9c
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x5dc8
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xe26c
jmp 0x5dc8
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xe26c
movabsq $0x40f869f000000000, %rax # imm = 0x40F869F000000000
movq %rax, 0x8(%rsp)
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x5dad
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x5dbc
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xe26c
jmp 0x5dc8
movq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xe26c
movq 0x38(%rsp), %rax
incl %eax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
addl %r12d, %eax
movslq %eax, %rcx
movq 0x10(%rsp), %rdx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, (%rdx,%rcx,8)
movl %ecx, 0x8(%rsp)
movq 0x198(%rbx), %rsi
cmpq 0x1a0(%rbx), %rsi
je 0x5e09
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x198(%rbx)
jmp 0x5e18
movq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xe460
movq %r15, %rdi
movq %rbp, %rsi
callq 0xd4a6
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5e32
callq 0x21c0
incq %r12
movq 0x58(%rbx), %rax
movq 0x60(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
imulq %rdx, %rcx
cmpq %r12, %rcx
ja 0x5b7c
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5e76
jmp 0x5e76
jmp 0x5e76
jmp 0x5e76
jmp 0x5e76
jmp 0x5e76
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5e88
callq 0x21c0
movq %rbx, %rdi
callq 0x2310