// File: /workspace/github_c_makefile_star2_O3/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 0x14611
cmpl $0x1, %eax
je 0x1456c
xorl %r14d, %r14d
cmpl $0x2, %eax
jne 0x1469f
leaq -0x38(%rbp), %r15
movq %r14, (%r15)
leaq -0x30(%rbp), %r13
movq %r14, (%r13)
movq (%rbx), %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r13, %rcx
callq 0x14974
movq (%r15), %r12
testq %r12, %r12
setne %al
movq (%r13), %r13
testq %r13, %r13
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1469f
movl $0x1, %r15d
xorl %r14d, %r14d
movq %r12, %rdi
movq %r13, %rsi
callq 0x14a3f
cmpq %rax, %r14
ja 0x14531
movq %r12, %rdi
movq %r13, %rsi
callq 0x14a3f
movq %rax, %r14
xorl %eax, %eax
movq %rax, -0x38(%rbp)
movq %rax, -0x30(%rbp)
movq (%rbx), %rdi
movq %r15, %rsi
leaq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x14974
movq -0x38(%rbp), %r12
testq %r12, %r12
je 0x1469f
incq %r15
movq -0x30(%rbp), %r13
testq %r13, %r13
jne 0x14513
jmp 0x1469f
xorl %r12d, %r12d
leaq -0x38(%rbp), %r14
movq %r12, (%r14)
leaq -0x30(%rbp), %r15
movq %r12, (%r15)
movq (%rbx), %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r15, %rcx
callq 0x1474b
movq (%r14), %rdi
testq %rdi, %rdi
setne %al
movq (%r15), %rsi
testq %rsi, %rsi
setne %cl
andb %al, %cl
movl $0x0, %r14d
cmpb $0x1, %cl
jne 0x1469f
movl $0x1, %r15d
xorl %r14d, %r14d
movq %r14, %r13
subq %rdi, %rsi
sarq $0x2, %rsi
callq 0x147e8
movl %eax, %r14d
testl %eax, %eax
cmovlel %r12d, %r14d
cmpq %r14, %r13
cmovaq %r13, %r14
movq %r12, -0x38(%rbp)
movq %r12, -0x30(%rbp)
movq (%rbx), %rdi
movq %r15, %rsi
leaq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x1474b
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x1469f
incq %r15
movq -0x30(%rbp), %rsi
testq %rsi, %rsi
jne 0x145b9
jmp 0x1469f
xorl %r14d, %r14d
leaq -0x38(%rbp), %r15
movq %r14, (%r15)
leaq -0x30(%rbp), %r12
movq %r14, (%r12)
movq (%rbx), %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x146b1
movq (%r15), %rax
testq %rax, %rax
setne %dl
movq (%r12), %rcx
testq %rcx, %rcx
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x1469f
movl $0x1, %r15d
xorl %r12d, %r12d
leaq -0x30(%rbp), %r13
xorl %r14d, %r14d
movq %r14, %rdx
subq %rax, %rcx
cmpq %rcx, %r14
movq %rcx, %r14
cmovaq %rdx, %r14
movq %r12, -0x38(%rbp)
movq %r12, -0x30(%rbp)
movq (%rbx), %rdi
movq %r15, %rsi
leaq -0x38(%rbp), %rdx
movq %r13, %rcx
callq 0x146b1
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x1469f
incq %r15
movq -0x30(%rbp), %rcx
testq %rcx, %rcx
jne 0x14660
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq