// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rdi, -0x48(%rbp)
movl 0x10(%rdi), %eax
testl %eax, %eax
je 0x14bbf
cmpl $0x1, %eax
je 0x14b51
cmpl $0x2, %eax
jne 0x14c22
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %eax, %eax
movq %rax, -0x38(%rbp)
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq %r13, %rsi
leaq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x14f4c
movq -0x38(%rbp), %r12
testq %r12, %r12
setne %al
movq -0x30(%rbp), %r15
testq %r15, %r15
setne %bl
andb %al, %bl
cmpb $0x1, %bl
jne 0x14b44
movq %r12, %rdi
movq %r15, %rsi
callq 0x15016
cmpq %rax, %r14
ja 0x14b3f
movq %r12, %rdi
movq %r15, %rsi
callq 0x15016
movq %rax, %r14
incq %r13
jmp 0x14b48
movq %r14, -0x40(%rbp)
testb %bl, %bl
jne 0x14ae5
jmp 0x14c2a
xorl %r15d, %r15d
leaq -0x30(%rbp), %r12
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %r15, -0x38(%rbp)
movq %r15, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq %r13, %rsi
leaq -0x38(%rbp), %rdx
movq %r12, %rcx
callq 0x14ce1
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
setne %al
movq -0x30(%rbp), %rsi
testq %rsi, %rsi
setne %bl
andb %al, %bl
cmpb $0x1, %bl
jne 0x14bb5
subq %rdi, %rsi
sarq $0x2, %rsi
callq 0x14d87
testl %eax, %eax
cmovlel %r15d, %eax
cmpq %rax, %r14
cmovbeq %rax, %r14
incq %r13
jmp 0x14bb9
movq %r14, -0x40(%rbp)
testb %bl, %bl
jne 0x14b5e
jmp 0x14c2a
xorl %r15d, %r15d
leaq -0x38(%rbp), %rbx
leaq -0x30(%rbp), %r12
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %r15, -0x38(%rbp)
movq %r15, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x14c3d
movq -0x38(%rbp), %rcx
testq %rcx, %rcx
setne %sil
movq -0x30(%rbp), %rdx
testq %rdx, %rdx
setne %al
andb %sil, %al
cmpb $0x1, %al
jne 0x14c18
subq %rcx, %rdx
cmpq %rdx, %r14
cmovbeq %rdx, %r14
incq %r13
jmp 0x14c1c
movq %r14, -0x40(%rbp)
testb %al, %al
jne 0x14bd0
jmp 0x14c2a
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq