// File: /workspace/github_c_makefile_star2_O2/neosploit[P]compiler/libfort/lib/fort.c
// Function: table_rows_and_cols_geometry
FT_INTERNAL
f_status table_rows_and_cols_geometry(const ft_table_t *table,
                                      size_t **col_width_arr_p, size_t *col_width_arr_sz,
                                      size_t **row_height_arr_p, size_t *row_height_arr_sz,
                                      enum f_geometry_type geom)
{
    if (table == NULL) {
        return FT_GEN_ERROR;
    }

    size_t max_invis_codepoints = 0;
    size_t cols = 0;
    size_t rows = 0;
    int status = get_table_sizes(table, &rows, &cols);
    if (FT_IS_ERROR(status))
        return status;

    size_t *col_width_arr = (size_t *)F_CALLOC(cols, sizeof(size_t));
    size_t *row_height_arr = (size_t *)F_CALLOC(rows, sizeof(size_t));
    if (col_width_arr == NULL || row_height_arr == NULL) {
        F_FREE(col_width_arr);
        F_FREE(row_height_arr);
        return FT_GEN_ERROR;
    }

    int combined_cells_found = 0;
    f_context_t context;
    context.table_properties = (table->properties ? table->properties : &g_table_properties);
    size_t col = 0;
    for (col = 0; col < cols; ++col) {
        col_width_arr[col] = 0;
        size_t row = 0;
        for (row = 0; row < rows; ++row) {
            const f_row_t *row_p = get_row_c(table, row);
            const f_cell_t *cell = get_cell_c(row_p, col);
            context.column = col;
            context.row = row;
            if (cell) {
                switch (get_cell_type(cell)) {
                    case COMMON_CELL:
                        col_width_arr[col] = MAX(col_width_arr[col], cell_vis_width(cell, &context));
                        break;
                    case GROUP_MASTER_CELL:
                        combined_cells_found = 1;
                        break;
                    case GROUP_SLAVE_CELL:
                        ; /* Do nothing */
                        break;
                }
                row_height_arr[row] = MAX(row_height_arr[row], hint_height_cell(cell, &context));
            } else {
                size_t cell_empty_string_height = get_cell_property_hierarchically(context.table_properties, context.row, context.column, FT_CPROP_EMPTY_STR_HEIGHT);
                if (cell_empty_string_height) {
                    size_t cell_top_padding = get_cell_property_hierarchically(context.table_properties, context.row, context.column, FT_CPROP_TOP_PADDING);
                    size_t cell_bottom_padding = get_cell_property_hierarchically(context.table_properties, context.row, context.column, FT_CPROP_BOTTOM_PADDING);
                    row_height_arr[row] = MAX(row_height_arr[row], cell_empty_string_height + cell_top_padding + cell_bottom_padding);
                }
            }
        }

        if (geom == INTERN_REPR_GEOMETRY) {
            max_invis_codepoints = 0;
            for (row = 0; row < rows; ++row) {
                const f_row_t *row_p = get_row_c(table, row);
                const f_cell_t *cell = get_cell_c(row_p, col);
                if (!cell)
                    continue;
                context.column = col;
                context.row = row;
                size_t inv_codepoints = cell_invis_codes_width(cell, &context);
                max_invis_codepoints = MAX(max_invis_codepoints, inv_codepoints);
            }
            col_width_arr[col] += max_invis_codepoints;
        }
    }

    if (combined_cells_found) {
        for (col = 0; col < cols; ++col) {
            size_t row = 0;
            for (row = 0; row < rows; ++row) {
                const f_row_t *row_p = get_row_c(table, row);
                const f_cell_t *cell = get_cell_c(row_p, col);
                context.column = col;
                context.row = row;
                if (cell) {
                    if (get_cell_type(cell) == GROUP_MASTER_CELL) {
                        size_t hint_width = cell_vis_width(cell, &context);
                        if (geom == INTERN_REPR_GEOMETRY) {
                            hint_width += cell_invis_codes_width(cell, &context);
                        }
                        size_t slave_col = col + group_cell_number(row_p, col);
                        size_t cur_adj_col = col;
                        size_t group_width = col_width_arr[col];
                        size_t i;
                        for (i = col + 1; i < slave_col; ++i)
                            group_width += col_width_arr[i] + FORT_COL_SEPARATOR_LENGTH;
                        /* adjust col. widths */
                        while (1) {
                            if (group_width >= hint_width)
                                break;
                            col_width_arr[cur_adj_col] += 1;
                            group_width++;
                            cur_adj_col++;
                            if (cur_adj_col == slave_col)
                                cur_adj_col = col;
                        }
                    }
                }
            }
        }
    }

    /* todo: Maybe it is better to move min width checking to a particular cell
     * width checking. At the moment min width includes paddings. Maybe it is
     * better that min width weren't include paddings but be min width of the
     * cell content without padding
     */
    /*
    if (table->properties) {
        for (size_t i = 0; i < cols; ++i) {
            col_width_arr[i] = MAX((int)col_width_arr[i], fort_props_column_width(table->properties, i));
        }
    }
    */

    *col_width_arr_p = col_width_arr;
    *col_width_arr_sz = cols;
    *row_height_arr_p = row_height_arr;
    *row_height_arr_sz = rows;
    return FT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, -0x58(%rbp)
movq %rdi, -0x60(%rbp)
movq (%rdi), %rax
testq %rax, %rax
movq %r8, -0x90(%rbp)
movq %rcx, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
movq %rsi, -0x78(%rbp)
je 0x1279d
movq (%rax), %r15
xorl %r14d, %r14d
xorl %edi, %edi
cmpq %rdi, %r15
je 0x127a3
movq 0x8(%rax), %r9
movq 0x18(%rax), %r10
imulq %rdi, %r10
movq (%r9,%r10), %r9
testq %r9, %r9
je 0x12798
movq (%r9), %r9
testq %r9, %r9
je 0x12798
movq (%r9), %r9
cmpq %r14, %r9
cmovaq %r9, %r14
incq %rdi
jmp 0x1276c
xorl %r14d, %r14d
xorl %r15d, %r15d
pushq $0x8
popq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq *0xda7e(%rip)           # 0x20230
movq %rax, %r13
movq %r15, -0x50(%rbp)
movq %r15, %rdi
movq %rbx, %rsi
callq *0xda6b(%rip)           # 0x20230
movq %rax, %rbx
testq %r13, %r13
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x127f5
movq %r13, %rdi
callq *0xda54(%rip)           # 0x20238
movq %rbx, %rdi
callq *0xda4b(%rip)           # 0x20238
pushq $-0x4
popq %rax
jmp 0x12ad8
movq %rbx, -0x70(%rbp)
movq %r14, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
leaq 0xda39(%rip), %rcx      # 0x20248
cmovneq %rax, %rcx
leaq -0x48(%rbp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
movl $0x0, -0x54(%rbp)
movq -0x50(%rbp), %r14
cmpq -0x68(%rbp), %rax
je 0x129d2
movq %rax, -0x30(%rbp)
andq $0x0, (%r13,%rax,8)
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x12970
movq -0x60(%rbp), %rdi
movq %rbx, %rsi
callq 0x1325b
movq %rax, %rdi
movq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x1326a
movq %r15, -0x38(%rbp)
movq %rbx, -0x40(%rbp)
testq %rax, %rax
je 0x128b4
movq %rax, %r12
movl 0x8(%rax), %eax
cmpl $0x1, %eax
je 0x1291d
testl %eax, %eax
jne 0x12935
movq -0x30(%rbp), %r15
movq (%r13,%r15,8), %rax
movq %rax, -0x98(%rbp)
movq %r12, %rdi
leaq -0x48(%rbp), %r14
movq %r14, %rsi
callq 0x13279
cmpq %rax, -0x98(%rbp)
jbe 0x12925
movq (%r13,%r15,8), %rax
jmp 0x12930
movq -0x48(%rbp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
pushq $0x40
popq %rcx
callq 0x133f4
testl %eax, %eax
je 0x12968
movslq %eax, %r14
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
pushq $0x4
popq %rcx
callq 0x133f4
movslq %eax, %r12
addq %r14, %r12
movq -0x50(%rbp), %r14
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
pushq $0x8
popq %rcx
callq 0x133f4
cltq
addq %r12, %rax
movq -0x70(%rbp), %rdx
movq (%rdx,%rbx,8), %rcx
cmpq %rax, %rcx
cmovaq %rcx, %rax
movq %rax, (%rdx,%rbx,8)
jmp 0x12968
pushq $0x1
popq %rax
movl %eax, -0x54(%rbp)
jmp 0x12935
movq %r12, %rdi
movq %r14, %rsi
callq 0x13279
movq %rax, (%r13,%r15,8)
movq -0x70(%rbp), %r15
movq (%r15,%rbx,8), %r14
movq %r12, %rdi
leaq -0x48(%rbp), %rsi
callq 0x13341
cmpq %rax, %r14
jbe 0x12954
movq (%r15,%rbx,8), %rax
jmp 0x12960
movq %r12, %rdi
leaq -0x48(%rbp), %rsi
callq 0x13341
movq -0x50(%rbp), %r14
movq %rax, (%r15,%rbx,8)
incq %rbx
jmp 0x1283d
cmpl $0x1, -0x58(%rbp)
jne 0x129c6
xorl %ebx, %ebx
xorl %r12d, %r12d
cmpq %rbx, %r14
je 0x129bd
movq -0x60(%rbp), %rdi
movq %rbx, %rsi
callq 0x1325b
movq %rax, %rdi
movq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x1326a
testq %rax, %rax
je 0x129b8
movq %r15, -0x38(%rbp)
movq %rbx, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x13555
cmpq %rax, %r12
cmovbeq %rax, %r12
incq %rbx
jmp 0x1297b
movq -0x30(%rbp), %rax
addq %r12, (%r13,%rax,8)
movq -0x30(%rbp), %rax
incq %rax
jmp 0x12827
cmpl $0x0, -0x54(%rbp)
movq -0x68(%rbp), %rcx
je 0x12ab0
pushq $0x1
popq %rax
movq %rax, -0x30(%rbp)
xorl %ebx, %ebx
cmpq %rcx, %rbx
je 0x12ab0
xorl %r15d, %r15d
cmpq %r14, %r15
je 0x12aa0
movq -0x60(%rbp), %rdi
movq %r15, %rsi
callq 0x1325b
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1326a
movq %rbx, -0x38(%rbp)
movq %r15, -0x40(%rbp)
testq %rax, %rax
je 0x12a94
cmpl $0x1, 0x8(%rax)
jne 0x12a94
movq %rax, %rdi
leaq -0x48(%rbp), %rsi
callq 0x13279
movq %rax, %r12
cmpl $0x1, -0x58(%rbp)
jne 0x12a4c
leaq -0x48(%rbp), %rdi
callq 0x13555
addq %rax, %r12
movq %r14, %rdi
movq %rbx, %rsi
callq 0x13640
addq %rbx, %rax
movq (%r13,%rbx,8), %rcx
movq -0x30(%rbp), %rdx
cmpq %rax, %rdx
jae 0x12a78
movq (%r13,%rdx,8), %rsi
addq %rsi, %rcx
incq %rcx
incq %rdx
jmp 0x12a63
movq %rbx, %rdx
cmpq %r12, %rcx
jae 0x12a94
incq (%r13,%rdx,8)
incq %rcx
incq %rdx
cmpq %rax, %rdx
cmoveq %rbx, %rdx
jmp 0x12a7b
incq %r15
movq -0x50(%rbp), %r14
jmp 0x129f5
incq %rbx
incq -0x30(%rbp)
movq -0x68(%rbp), %rcx
jmp 0x129e9
movq -0x78(%rbp), %rax
movq %r13, (%rax)
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
movq -0x88(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, (%rax)
movq -0x90(%rbp), %rax
movq %r14, (%rax)
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq