// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rdi, %rbx
leaq 0x88(%rdi), %rax
movq %rax, 0x8(%rsp)
movq 0x88(%rdi), %rax
cmpq 0x90(%rdi), %rax
je 0x591e
movq 0x8(%rsp), %rdi
callq 0xd54e
movq 0x190(%rbx), %rax
cmpq %rax, 0x198(%rbx)
je 0x591e
movq %rax, 0x198(%rbx)
movq 0x60(%rbx), %r14
subq 0x58(%rbx), %r14
sarq $0x3, %r14
movabsq $-0x71c71c71c71c71c7, %rax # imm = 0x8E38E38E38E38E39
imulq %rax, %r14
movl (%rbx), %eax
movq %rax, 0x30(%rsp)
movq 0x50(%rbx), %rsi
addq $0x20, %rsi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x4ae4
leaq 0x1c0(%rbx), %rax
movq %rax, 0x28(%rsp)
movq 0x1c0(%rbx), %rdi
movapd (%r15), %xmm0
movupd %xmm0, 0x1c0(%rbx)
movq 0x10(%r15), %rax
movq %rax, 0x1d0(%rbx)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
testq %rdi, %rdi
je 0x59a9
callq 0x21c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x59a9
callq 0x21c0
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0xd628
testl %r14d, %r14d
jle 0x5a96
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl $0x20, %ebp
leaq 0x10(%rsp), %r15
movq 0x58(%rbx), %rax
movq 0x88(%rbx), %rdi
cmpl $-0x1, (%rax,%rbp)
je 0x5a0a
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5a31
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5a39
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rax
cmpq %rax, %rsi
je 0x5a40
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5a58
movq %r15, %rdx
callq 0xe40c
movl $0x1, %eax
jmp 0x5a84
movq %r15, %rdx
callq 0xe40c
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rax
movq $0x0, 0x10(%rsp)
cmpq %rax, %rsi
je 0x5a77
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5a7f
movq %r15, %rdx
callq 0xe40c
movl $0x2, %eax
addl %eax, %r13d
addq $0x48, %rbp
decq %r14
jne 0x59d5
jmp 0x5a99
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq $0x0, 0x10(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5ac5
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5acf
leaq 0x10(%rsp), %rdx
callq 0xe40c
cmpl $-0x1, 0x28(%rbx)
jne 0x5b33
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x5b33
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
movapd 0xa7a1(%rip), %xmm0     # 0x102a0
movsd 0xa7c9(%rip), %xmm1     # 0x102d0
movapd 0xa7a1(%rip), %xmm2     # 0x102b0
movsd (%rax,%rdx,8), %xmm3
movapd %xmm3, %xmm4
andpd %xmm0, %xmm4
ucomisd %xmm4, %xmm1
jae 0x5b2b
xorpd %xmm2, %xmm3
movlpd %xmm3, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x5b0f
movq 0x58(%rbx), %rax
cmpq %rax, 0x60(%rbx)
je 0x5e30
leaq 0x190(%rbx), %rcx
movq %rcx, 0x40(%rsp)
xorl %r14d, %r14d
leaq 0x10(%rsp), %rbp
leaq (%r14,%r14,8), %r12
leaq (%rax,%r12,8), %rsi
addq $0x30, %rsi
movq %rbp, %rdi
callq 0x4ae4
movl %r13d, %r15d
testl %r13d, %r13d
jle 0x5baa
movq $0x0, 0x38(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5b98
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x5ba5
movq %rbp, %rdi
leaq 0x38(%rsp), %rdx
callq 0xe40c
decl %r15d
jne 0x5b71
movq 0x58(%rbx), %rax
movsd 0x28(%rax,%r12,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5bdb
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
movq 0x30(%rsp), %r15
jmp 0x5bf1
movq %rbp, %rdi
leaq 0x38(%rsp), %rdx
callq 0xe528
movq 0x30(%rsp), %r15
movq 0x58(%rbx), %rax
movl 0x20(%rax,%r12,8), %eax
cmpl $-0x1, %eax
je 0x5c77
testl %eax, %eax
jne 0x5d05
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
movsd 0xa6bb(%rip), %xmm1     # 0x102d8
je 0x5c4d
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 0x5c32
movabsq $0x40f869f000000000, %rax # imm = 0x40F869F000000000
movq %rax, (%rsp)
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x5d31
movq %rax, (%rsi)
jmp 0x5d24
leal (%r15,%r14), %eax
movslq %eax, %rcx
movq 0x10(%rsp), %rax
movabsq $-0x4010000000000000, %rdx # imm = 0xBFF0000000000000
movq %rdx, (%rax,%rcx,8)
movq 0x8(%rsp), %rcx
movq (%rcx), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
subq %rcx, %rdx
movsd 0xa62d(%rip), %xmm1     # 0x102d8
je 0x5cd6
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 0x5cbb
movq $0x0, (%rsp)
movq 0x1c8(%rbx), %rsi
movq 0x1d0(%rbx), %rax
cmpq %rax, %rsi
je 0x5d40
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x5d5b
movq $0x0, (%rsp)
movq 0x1c8(%rbx), %rsi
cmpq 0x1d0(%rbx), %rsi
je 0x5d7e
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x5d9d
movq 0x28(%rsp), %rdi
movq %rsp, %rdx
callq 0xe40c
jmp 0x5d9d
movq 0x28(%rsp), %rdi
movq %rsp, %rdx
callq 0xe40c
movq 0x1c8(%rbx), %rsi
movq 0x1d0(%rbx), %rax
movabsq $0x40f869f000000000, %rcx # imm = 0x40F869F000000000
movq %rcx, (%rsp)
cmpq %rax, %rsi
je 0x5d8d
movq %rcx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x1c8(%rbx)
jmp 0x5d9a
movq 0x28(%rsp), %rdi
movq %rsp, %rdx
callq 0xe40c
jmp 0x5d9d
movq 0x28(%rsp), %rdi
movq %rsp, %rdx
callq 0xe40c
incl %r15d
leal (%r14,%r15), %eax
movslq %eax, %rcx
movq 0x10(%rsp), %rdx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, (%rdx,%rcx,8)
movl %ecx, (%rsp)
movq 0x198(%rbx), %rsi
cmpq 0x1a0(%rbx), %rsi
je 0x5dd9
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x198(%rbx)
jmp 0x5de6
movq 0x40(%rsp), %rdi
movq %rsp, %rdx
callq 0xe600
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0xd628
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5e02
callq 0x21c0
movq %r15, 0x30(%rsp)
incq %r14
movq 0x58(%rbx), %rax
movq 0x60(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
imulq %rdx, %rcx
cmpq %r14, %rcx
ja 0x5b55
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5e4b
jmp 0x5e4b
jmp 0x5e4b
jmp 0x5e4b
jmp 0x5e4b
jmp 0x5e4b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5e5d
callq 0x21c0
movq %rbx, %rdi
callq 0x2310
nop