// File: /workspace/github_c_makefile_star2_O2/neosploit[P]compiler/libfort/lib/fort.c
// Function: buffer_text_visible_width
FT_INTERNAL
size_t buffer_text_visible_width(const f_string_buffer_t *buffer)
{
    size_t max_length = 0;
    if (buffer->type == CHAR_BUF) {
        size_t n = 0;
        while (1) {
            const char *beg = NULL;
            const char *end = NULL;
            str_n_substring(buffer->str.cstr, '\n', n, &beg, &end);
            if (beg == NULL || end == NULL)
                return max_length;

            max_length = MAX(max_length, (size_t)(end - beg));
            ++n;
        }
#ifdef FT_HAVE_WCHAR
    } else if (buffer->type == W_CHAR_BUF) {
        size_t n = 0;
        while (1) {
            const wchar_t *beg = NULL;
            const wchar_t *end = NULL;
            wstr_n_substring(buffer->str.wstr, L'\n', n, &beg, &end);
            if (beg == NULL || end == NULL)
                return max_length;

            int line_width = mk_wcswidth(beg, (size_t)(end - beg));
            if (line_width < 0) /* For safety */
                line_width = 0;
            max_length = MAX(max_length, (size_t)line_width);

            ++n;
        }
#endif /* FT_HAVE_WCHAR */
#ifdef FT_HAVE_UTF8
    } else if (buffer->type == UTF8_BUF) {
        size_t n = 0;
        while (1) {
            const void *beg = NULL;
            const void *end = NULL;
            utf8_n_substring(buffer->str.u8str, '\n', n, &beg, &end);
            if (beg == NULL || end == NULL)
                return max_length;

            max_length = MAX(max_length, (size_t)utf8_width(beg, end));
            ++n;
        }
#endif /* FT_HAVE_WCHAR */
    }

    return max_length; /* shouldn't be here */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x10(%rdi), %eax
testl %eax, %eax
je 0x13840
cmpl $0x1, %eax
je 0x137e3
xorl %r14d, %r14d
cmpl $0x2, %eax
jne 0x1388a
xorl %r13d, %r13d
andq $0x0, -0x38(%rbp)
andq $0x0, -0x30(%rbp)
movq (%rbx), %rdi
movq %r13, %rsi
leaq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x13b65
movq -0x38(%rbp), %r15
testq %r15, %r15
je 0x1388a
movq -0x30(%rbp), %r12
testq %r12, %r12
je 0x1388a
movq %r15, %rdi
movq %r12, %rsi
callq 0x13c13
cmpq %rax, %r14
ja 0x137de
movq %r15, %rdi
movq %r12, %rsi
callq 0x13c13
movq %rax, %r14
incq %r13
jmp 0x13789
leaq -0x38(%rbp), %r15
leaq -0x30(%rbp), %r12
xorl %r14d, %r14d
xorl %r13d, %r13d
andq $0x0, -0x38(%rbp)
andq $0x0, -0x30(%rbp)
movq (%rbx), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x1393b
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x1388a
movq -0x30(%rbp), %rsi
testq %rsi, %rsi
je 0x1388a
subq %rdi, %rsi
sarq $0x2, %rsi
callq 0x139dd
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
cmpq %rax, %r14
cmovbeq %rax, %r14
incq %r13
jmp 0x137f1
xorl %r14d, %r14d
leaq -0x38(%rbp), %r15
leaq -0x30(%rbp), %r12
xorl %r13d, %r13d
andq $0x0, -0x38(%rbp)
andq $0x0, -0x30(%rbp)
movq (%rbx), %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x1389c
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x1388a
movq -0x30(%rbp), %rcx
testq %rcx, %rcx
je 0x1388a
subq %rax, %rcx
cmpq %rcx, %r14
cmovbeq %rcx, %r14
incq %r13
jmp 0x1384e
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq