// File: /workspace/github_c_makefile_star2_O0/neosploit[P]compiler/libfort/lib/fort.c
// Function: cell_printf
FT_INTERNAL
int cell_printf(f_cell_t *cell, size_t row, f_conv_context_t *cntx, size_t vis_width)
{
    const f_context_t *context = cntx->cntx;
    size_t buf_len = vis_width;

    if (cell == NULL || (vis_width < cell_vis_width(cell, context))) {
        return -1;
    }

    f_table_properties_t *properties = context->table_properties;
    unsigned int padding_top = get_cell_property_hierarchically(properties, context->row, context->column, FT_CPROP_TOP_PADDING);
    unsigned int padding_left = get_cell_property_hierarchically(properties, context->row, context->column, FT_CPROP_LEFT_PADDING);
    unsigned int padding_right = get_cell_property_hierarchically(properties, context->row, context->column, FT_CPROP_RIGHT_PADDING);

    size_t written = 0;
    size_t invisible_written = 0;
    int tmp = 0;

    /* todo: Dirty hack with changing buf_len! need refactoring. */
    /* Also maybe it is better to move all struff with colors to buffers? */
    char cell_style_tag[TEXT_STYLE_TAG_MAX_SIZE];
    get_style_tag_for_cell(properties, context->row, context->column, cell_style_tag, TEXT_STYLE_TAG_MAX_SIZE);
    buf_len += strlen(cell_style_tag);

    char reset_cell_style_tag[TEXT_STYLE_TAG_MAX_SIZE];
    get_reset_style_tag_for_cell(properties, context->row, context->column, reset_cell_style_tag, TEXT_STYLE_TAG_MAX_SIZE);
    buf_len += strlen(reset_cell_style_tag);

    char content_style_tag[TEXT_STYLE_TAG_MAX_SIZE];
    get_style_tag_for_content(properties, context->row, context->column, content_style_tag, TEXT_STYLE_TAG_MAX_SIZE);
    buf_len += strlen(content_style_tag);

    char reset_content_style_tag[TEXT_STYLE_TAG_MAX_SIZE];
    get_reset_style_tag_for_content(properties, context->row, context->column, reset_content_style_tag, TEXT_STYLE_TAG_MAX_SIZE);
    buf_len += strlen(reset_content_style_tag);

    /*    CELL_STYLE_T   LEFT_PADDING   CONTENT_STYLE_T  CONTENT   RESET_CONTENT_STYLE_T    RIGHT_PADDING   RESET_CELL_STYLE_T
     *  |              |              |                |         |                       |                |                    |
     *        L1                                                                                                    R1
     *                     L2                                                                   R2
     *                                     L3                               R3
     */

    size_t L2 = padding_left;

    size_t R2 = padding_right;
    size_t R3 = strlen(reset_cell_style_tag);

#define TOTAL_WRITTEN (written + invisible_written)
#define RIGHT (padding_right + extra_right)

#define WRITE_CELL_STYLE_TAG        CHCK_RSLT_ADD_TO_INVISIBLE_WRITTEN(print_n_strings(cntx, 1, cell_style_tag))
#define WRITE_RESET_CELL_STYLE_TAG  CHCK_RSLT_ADD_TO_INVISIBLE_WRITTEN(print_n_strings(cntx, 1, reset_cell_style_tag))
#define WRITE_CONTENT_STYLE_TAG        CHCK_RSLT_ADD_TO_INVISIBLE_WRITTEN(print_n_strings(cntx, 1, content_style_tag))
#define WRITE_RESET_CONTENT_STYLE_TAG  CHCK_RSLT_ADD_TO_INVISIBLE_WRITTEN(print_n_strings(cntx, 1, reset_content_style_tag))

    if (row >= hint_height_cell(cell, context)
        || row < padding_top
        || row >= (padding_top + buffer_text_visible_height(cell->str_buffer))) {
        WRITE_CELL_STYLE_TAG;
        WRITE_CONTENT_STYLE_TAG;
        WRITE_RESET_CONTENT_STYLE_TAG;
        CHCK_RSLT_ADD_TO_WRITTEN(print_n_strings(cntx, buf_len - TOTAL_WRITTEN - R3, FT_SPACE));
        WRITE_RESET_CELL_STYLE_TAG;

        return (int)TOTAL_WRITTEN;
    }

    WRITE_CELL_STYLE_TAG;
    CHCK_RSLT_ADD_TO_WRITTEN(print_n_strings(cntx, L2, FT_SPACE));
    if (cell->str_buffer) {
        CHCK_RSLT_ADD_TO_WRITTEN(buffer_printf(cell->str_buffer, row - padding_top, cntx, vis_width - L2 - R2, content_style_tag, reset_content_style_tag));
    } else {
        WRITE_CONTENT_STYLE_TAG;
        WRITE_RESET_CONTENT_STYLE_TAG;
        CHCK_RSLT_ADD_TO_WRITTEN(print_n_strings(cntx, vis_width - L2 - R2, FT_SPACE));
    }
    CHCK_RSLT_ADD_TO_WRITTEN(print_n_strings(cntx, R2, FT_SPACE));
    WRITE_RESET_CELL_STYLE_TAG;

    return (int)TOTAL_WRITTEN;

clear:
    return -1;
#undef WRITE_CELL_STYLE_TAG
#undef WRITE_RESET_CELL_STYLE_TAG
#undef WRITE_CONTENT_STYLE_TAG
#undef WRITE_RESET_CONTENT_STYLE_TAG
#undef TOTAL_WRITTEN
#undef RIGHT
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1cfdd
movq -0x28(%rbp), %rax
movq %rax, -0x290(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1a2b0
movq %rax, %rcx
movq -0x290(%rbp), %rax
cmpq %rcx, %rax
jae 0x1cfe9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1d4de
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x4, %ecx
callq 0x1a550
movl %eax, -0x44(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x10, %ecx
callq 0x1a550
movl %eax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x20, %ecx
callq 0x1a550
movl %eax, -0x4c(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
leaq -0xf0(%rbp), %rcx
movl $0x80, %r8d
callq 0x1bb40
leaq -0xf0(%rbp), %rdi
callq 0x70d0
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
leaq -0x170(%rbp), %rcx
movl $0x80, %r8d
callq 0x1bc50
leaq -0x170(%rbp), %rdi
callq 0x70d0
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
leaq -0x1f0(%rbp), %rcx
movl $0x80, %r8d
callq 0x1bd50
leaq -0x1f0(%rbp), %rdi
callq 0x70d0
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
leaq -0x270(%rbp), %rcx
movl $0x80, %r8d
callq 0x1bea0
leaq -0x270(%rbp), %rdi
callq 0x70d0
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x48(%rbp), %eax
movq %rax, -0x278(%rbp)
movl -0x4c(%rbp), %eax
movq %rax, -0x280(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x70d0
movq %rax, -0x288(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x298(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1a410
movq %rax, %rcx
movq -0x298(%rbp), %rax
cmpq %rcx, %rax
jae 0x1d1ee
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %ecx
cmpq %rcx, %rax
jb 0x1d1ee
movq -0x18(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movl -0x44(%rbp), %eax
movq %rax, -0x2a8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1b560
movq -0x2a8(%rbp), %rcx
movq %rax, %rdx
movq -0x2a0(%rbp), %rax
addq %rdx, %rcx
cmpq %rcx, %rax
jb 0x1d304
jmp 0x1d1f0
movq -0x20(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d213
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x1d221
movq -0x20(%rbp), %rdi
leaq -0x1f0(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d244
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x1d252
movq -0x20(%rbp), %rdi
leaq -0x270(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d275
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x1d283
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
subq %rax, %rsi
subq -0x288(%rbp), %rsi
leaq 0x5385(%rip), %rdx      # 0x22629
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d2b7
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x1d2c5
movq -0x20(%rbp), %rdi
leaq -0x170(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d2e8
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x1d4de
jmp 0x1d306
movq -0x20(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d329
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x1d337
movq -0x20(%rbp), %rdi
movq -0x278(%rbp), %rsi
leaq 0x52e0(%rip), %rdx      # 0x22629
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d35c
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1d3cd
jmp 0x1d374
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x44(%rbp), %eax
subq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
subq -0x278(%rbp), %rcx
subq -0x280(%rbp), %rcx
leaq -0x1f0(%rbp), %r8
leaq -0x270(%rbp), %r9
callq 0x1d4f0
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d3bc
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x1d46c
jmp 0x1d3cf
movq -0x20(%rbp), %rdi
leaq -0x1f0(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d3f2
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x1d400
movq -0x20(%rbp), %rdi
leaq -0x270(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d423
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x1d431
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
subq -0x278(%rbp), %rsi
subq -0x280(%rbp), %rsi
leaq 0x51db(%rip), %rdx      # 0x22629
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d45e
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x1d46c
jmp 0x1d46e
movq -0x20(%rbp), %rdi
movq -0x280(%rbp), %rsi
leaq 0x51a9(%rip), %rdx      # 0x22629
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d490
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x1d49e
movq -0x20(%rbp), %rdi
leaq -0x170(%rbp), %rdx
movl $0x1, %esi
callq 0x19700
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x1d4be
jmp 0x1d4d7
movslq -0x64(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x1d4de
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
nopw (%rax,%rax)