// File: /workspace/github_c_makefile_star2_O3/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_add_table
lxw_error
worksheet_add_table(lxw_worksheet *self, lxw_row_t first_row,
                    lxw_col_t first_col, lxw_row_t last_row,
                    lxw_col_t last_col, lxw_table_options *user_options)
{
    lxw_row_t tmp_row;
    lxw_col_t tmp_col;
    lxw_col_t num_cols;
    lxw_error err;
    lxw_table_obj *table_obj;
    lxw_table_column **columns;

    if (self->optimize) {
        LXW_WARN_FORMAT("worksheet_add_table(): "
                        "worksheet tables aren't supported in "
                        "'constant_memory' mode");
        return LXW_ERROR_FEATURE_NOT_SUPPORTED;
    }

    /* Swap last row/col with first row/col as necessary */
    if (first_row > last_row) {
        tmp_row = last_row;
        last_row = first_row;
        first_row = tmp_row;
    }
    if (first_col > last_col) {
        tmp_col = last_col;
        last_col = first_col;
        first_col = tmp_col;
    }

    /* Check that column number is valid and store the max value */
    err = _check_dimensions(self, last_row, last_col, LXW_TRUE, LXW_TRUE);
    if (err)
        return err;

    num_cols = last_col - first_col + 1;

    /* Check that there are sufficient data rows. */
    err = _check_table_rows(first_row, last_row, user_options);
    if (err)
        return err;

    /* Check that the the table name is valid. */
    err = _check_table_name(user_options);
    if (err)
        return err;

    /* Create a table object to copy from the user options. */
    table_obj = calloc(1, sizeof(lxw_table_obj));
    RETURN_ON_MEM_ERROR(table_obj, LXW_ERROR_MEMORY_MALLOC_FAILED);

    columns = calloc(num_cols, sizeof(lxw_table_column *));
    GOTO_LABEL_ON_MEM_ERROR(columns, error);

    table_obj->columns = columns;
    table_obj->num_cols = num_cols;
    table_obj->first_row = first_row;
    table_obj->first_col = first_col;
    table_obj->last_row = last_row;
    table_obj->last_col = last_col;

    err = _set_default_table_columns(table_obj);
    if (err)
        goto error;

    /* Create the table range. */
    lxw_rowcol_to_range(table_obj->sqref,
                        first_row, first_col, last_row, last_col);
    lxw_rowcol_to_range(table_obj->filter_sqref,
                        first_row, first_col, last_row, last_col);

    /* Validate and copy user options to an internal object. */
    if (user_options) {

        _check_and_copy_table_style(table_obj, user_options);

        table_obj->total_row = user_options->total_row;
        table_obj->last_column = user_options->last_column;
        table_obj->first_column = user_options->first_column;
        table_obj->no_autofilter = user_options->no_autofilter;
        table_obj->no_header_row = user_options->no_header_row;
        table_obj->no_banded_rows = user_options->no_banded_rows;
        table_obj->banded_columns = user_options->banded_columns;

        if (user_options->no_header_row)
            table_obj->no_autofilter = LXW_TRUE;

        if (user_options->columns) {
            err = _set_custom_table_columns(table_obj, user_options);
            if (err)
                goto error;
        }

        if (user_options->total_row) {
            lxw_rowcol_to_range(table_obj->filter_sqref,
                                first_row, first_col, last_row - 1, last_col);
        }

        if (user_options->name) {
            table_obj->name = lxw_strdup(user_options->name);
            if (!table_obj->name) {
                err = LXW_ERROR_MEMORY_MALLOC_FAILED;
                goto error;
            }
        }
    }

    _write_table_column_data(self, table_obj);

    STAILQ_INSERT_TAIL(self->table_objs, table_obj, list_pointers);
    self->table_count++;

    return LXW_NO_ERROR;

error:
    _free_worksheet_table(table_obj);
    return err;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpb $0x0, 0x11c(%rdi)
jne 0x3bbbb
movl %r8d, %ebx
movl %ecx, %ebp
cmpl %ecx, %esi
movl %ecx, %r15d
cmoval %esi, %r15d
cmovbl %esi, %ebp
cmpw %bx, %dx
movl %r8d, %r12d
cmoval %edx, %r12d
cmovbl %edx, %ebx
cmpl $0x100000, %r15d        # imm = 0x100000
setae %al
movzwl %r12w, %edx
cmpl $0x4000, %edx           # imm = 0x4000
setae %cl
orb %al, %cl
movl $0x17, %r14d
jne 0x3bb2f
movl %edx, 0xc(%rsp)
movq %rdi, 0x20(%rsp)
movl %ebp, %edi
movl %r15d, %esi
movq %r9, %rdx
movq %r9, %r13
callq 0xcef0
testl %eax, %eax
jne 0x3bb2c
movq %r13, %rdi
callq 0xc970
testl %eax, %eax
je 0x3bb41
movl %eax, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x10(%rsp)
movl $0x1, %edi
movl $0x1080, %esi           # imm = 0x1080
callq 0xc7f0
testq %rax, %rax
je 0x3bd09
movq %rax, %r13
movl %r12d, %r14d
subl %ebx, %r14d
incl %r14d
movzwl %r14w, %edi
movl $0x8, %esi
callq 0xc7f0
testq %rax, %rax
je 0x3bd19
movq %rax, 0x10(%r13)
movw %r14w, 0x32(%r13)
movl %ebp, 0x24(%r13)
movw %bx, 0x28(%r13)
movl %r15d, 0x2c(%r13)
movw %r12w, 0x30(%r13)
movq %r13, %rdi
callq 0xd070
movl $0x1, %r14d
testl %eax, %eax
je 0x3bbcb
movq %r13, %rdi
callq 0x2fb1e
jmp 0x3bb2f
callq 0xf7cc
movl $0xb, %r14d
jmp 0x3bb2f
leaq 0x38(%r13), %rdi
movzwl %bx, %r12d
movl %ebp, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl 0xc(%rsp), %ebx
movl %ebx, %r8d
callq 0xcd10
leaq 0x858(%r13), %rdi
movq %rdi, 0x18(%rsp)
movl %ebp, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebx, %r8d
callq 0xcd10
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x3bcbd
movq %r13, %rdi
callq 0xca80
movq 0x10(%rsp), %rsi
movb 0x10(%rsi), %al
movb %al, 0x20(%r13)
movb 0xd(%rsi), %cl
movb %cl, 0x1a(%r13)
movb 0xc(%rsi), %cl
movb %cl, 0x19(%r13)
movb 0x9(%rsi), %cl
movb %cl, 0x1b(%r13)
movb 0x8(%rsi), %cl
movb %cl, 0x1d(%r13)
movb 0xa(%rsi), %dl
movb %dl, 0x1c(%r13)
movb 0xb(%rsi), %dl
movb %dl, 0x18(%r13)
testb %cl, %cl
je 0x3bc58
movb $0x1, 0x1b(%r13)
cmpq $0x0, 0x18(%rsi)
je 0x3bc7a
movq %r13, %rdi
callq 0xd020
movq 0x10(%rsp), %rsi
movl %eax, %r14d
testl %eax, %eax
jne 0x3bbae
movb 0x10(%rsi), %al
testb %al, %al
je 0x3bc9d
decl %r15d
movq 0x18(%rsp), %rdi
movl %ebp, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl 0xc(%rsp), %r8d
callq 0xcd10
movq 0x10(%rsp), %rsi
movq (%rsi), %rdi
testq %rdi, %rdi
je 0x3bcbd
callq 0xcce0
movq %rax, (%r13)
movl $0x1, %r14d
testq %rax, %rax
je 0x3bbae
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xcc70
movq %r13, %rax
addq $0x1078, %rax           # imm = 0x1078
movq $0x0, 0x1078(%r13)
movq 0x98(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %r13, (%rcx)
movq 0x98(%rbx), %rcx
movq %rax, 0x8(%rcx)
incw 0xa0(%rbx)
xorl %r14d, %r14d
jmp 0x3bb2f
callq 0xf80c
movl $0x1, %r14d
jmp 0x3bb2f
callq 0xf7e8
xorl %r14d, %r14d
jmp 0x3bbae