// File: /workspace/github_c_makefile_star2_O0/doy[P]libvt100/src/screen.c
// Function: vt100_screen_show_string_utf8
void vt100_screen_show_string_utf8(VT100Screen *vt, char *buf, size_t len)
{
    char *c = buf, *next;

    if (len) {
        vt->dirty = 1;

        if (vt->grid->cur.col > 0) {
            struct vt100_cell *cell;

            cell = vt100_screen_cell_at(
                vt, vt->grid->cur.row, vt->grid->cur.col - 1);
            if (cell->is_wide) {
                cell->len = 0;
            }
        }
    }

    while ((next = g_utf8_next_char(c))) {
        gunichar uc;
        struct vt100_cell *cell = NULL;
        int width;

        uc = g_utf8_get_char(c);
        width = vt100_char_width(uc);

        if (width == 0) {
            if (vt->grid->cur.col > 0) {
                cell = vt100_screen_cell_at(
                    vt, vt->grid->cur.row, vt->grid->cur.col - 1);
            }
            else if (vt->grid->cur.row > 0 && vt100_screen_row_at(vt, vt->grid->cur.row - 1)->wrapped) {
                cell = vt100_screen_cell_at(
                    vt, vt->grid->cur.row - 1, vt->grid->max.col - 1);
            }

            if (cell) {
                char *normal;

                memcpy(cell->contents + cell->len, c, next - c);
                cell->len += next - c;
                /* some fonts have combined characters but can't handle
                 * combining characters, so try to fix that here */
                /* XXX it'd be nice if there was a way to do this that didn't
                 * require an allocation */
                normal = g_utf8_normalize(
                    cell->contents, cell->len, G_NORMALIZE_NFC);
                cell->len = strlen(normal);
                memcpy(cell->contents, normal, cell->len);
                free(normal);
            }
        }
        else {
            vt100_screen_check_wrap(vt, width);
            cell = vt100_screen_cell_at(
                vt, vt->grid->cur.row, vt->grid->cur.col);

            cell->len = next - c;
            memcpy(cell->contents, c, cell->len);
            cell->attrs = vt->attrs;
            cell->is_wide = width == 2;

            vt->grid->cur.col += width;
        }

        c = next;
        if ((size_t)(c - buf) >= len) {
            break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x882a
movq -0x8(%rbp), %rax
movw 0x49(%rax), %cx
andw $0xdfff, %cx            # imm = 0xDFFF
orw $0x2000, %cx            # imm = 0x2000
movw %cx, 0x49(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x4(%rax)
jle 0x8828
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl (%rax), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %edx
subl $0x1, %edx
callq 0x3180
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x8826
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x8828
jmp 0x882a
jmp 0x882c
movq -0x20(%rbp), %rax
movq 0x77b1(%rip), %rcx      # 0xffe8
movq (%rcx), %rcx
movq -0x20(%rbp), %rdx
movzbl (%rdx), %edx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x8a57
movq $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3340
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %edi
callq 0x30b0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x899d
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x4(%rax)
jle 0x88b4
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl (%rax), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %edx
subl $0x1, %edx
callq 0x3180
movq %rax, -0x40(%rbp)
jmp 0x890a
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, (%rax)
jle 0x8908
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl (%rax), %esi
subl $0x1, %esi
callq 0x8a60
movb 0x8(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x8908
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl (%rax), %esi
subl $0x1, %esi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %edx
subl $0x1, %edx
callq 0x3180
movq %rax, -0x40(%rbp)
jmp 0x890a
cmpq $0x0, -0x40(%rbp)
je 0x8998
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
addq 0x8(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rax
subq %rax, %rdx
callq 0x3470
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rax, %rcx
movq -0x40(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
movl $0x1, %edx
callq 0x3110
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x3210
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x3470
movq -0x50(%rbp), %rdi
callq 0x3050
jmp 0x8a37
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x8730
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl (%rax), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %edx
callq 0x3180
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x3470
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x3c(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x44(%rcx), %ecx
movl %ecx, 0x18(%rax)
cmpl $0x2, -0x44(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x40(%rbp), %rax
movb %cl, %dl
movb 0x1c(%rax), %cl
andb $0x1, %dl
andb $-0x2, %cl
orb %dl, %cl
movb %cl, 0x1c(%rax)
movl -0x44(%rbp), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
cmpq -0x18(%rbp), %rax
jb 0x8a52
jmp 0x8a57
jmp 0x882c
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)