// File: /workspace/github_c_makefile_star2_O2/adsr[P]phpspy/vendor/termbox2/termbox2.h
// Function: tb_present
int tb_present(void) {
    if_not_init_return();

    int rv;

    // TODO Assert global.back.(width,height) == global.front.(width,height)

    global.last_x = -1;
    global.last_y = -1;

    int x, y, i;
    for (y = 0; y < global.front.height; y++) {
        for (x = 0; x < global.front.width;) {
            struct tb_cell *back, *front;
            if_err_return(rv, cellbuf_get(&global.back, x, y, &back));
            if_err_return(rv, cellbuf_get(&global.front, x, y, &front));

            int w;
            {
#ifdef TB_OPT_EGC
                if (back->nech > 0)
                    w = wcswidth((wchar_t *)back->ech, back->nech);
                else
#endif
                    /* wcwidth() simply returns -1 on overflow of wchar_t */
                    w = wcwidth((wchar_t)back->ch);
            }
            if (w < 1) {
                w = 1;
            }

            if (cell_cmp(back, front) != 0) {
                cell_copy(front, back);

                send_attr(back->fg, back->bg);
                if (w > 1 && x >= global.front.width - (w - 1)) {
                    for (i = x; i < global.front.width; i++) {
                        send_char(i, y, ' ');
                    }
                } else {
                    {
#ifdef TB_OPT_EGC
                        if (back->nech > 0)
                            send_cluster(x, y, back->ech, back->nech);
                        else
#endif
                            send_char(x, y, back->ch);
                    }
                    for (i = 1; i < w; i++) {
                        struct tb_cell *front_wide;
                        if_err_return(rv,
                            cellbuf_get(&global.front, x + i, y, &front_wide));
                        if_err_return(rv,
                            cell_set(front_wide, 0, 1, back->fg, back->bg));
                    }
                }
            }
            x += w;
        }
    }

    if_err_return(rv, send_cursor_if(global.cursor_x, global.cursor_y));
    if_err_return(rv, bytebuf_flush(&global.out, global.wfd));

    return TB_OK;
}

// Assembly:
cmpl $0x0, 0x1eb5e(%rip)     # 0x25c8c
je 0x728e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
orq $-0x1, 0x1e946(%rip)    # 0x25a90
xorl %ebx, %ebx
cmpl 0x1eaea(%rip), %ebx     # 0x25c3c
jge 0x7292
xorl %r14d, %r14d
cmpl 0x1ead6(%rip), %r14d    # 0x25c38
jge 0x7287
leaq 0x1eab9(%rip), %rdi     # 0x25c28
movl %r14d, %esi
movl %ebx, %edx
leaq 0x10(%rsp), %rcx
callq 0x72c9
testl %eax, %eax
jne 0x72ba
leaq 0x1eaab(%rip), %rdi     # 0x25c38
movl %r14d, %esi
movl %ebx, %edx
leaq 0x8(%rsp), %rcx
callq 0x72c9
testl %eax, %eax
jne 0x72ba
movq 0x10(%rsp), %r13
movl (%r13), %edi
callq 0x63c0
movl %eax, %r15d
cmpl $0x2, %eax
pushq $0x1
popq %rax
movl %eax, %ebp
cmovgel %r15d, %ebp
movq 0x8(%rsp), %rax
movl (%r13), %ecx
movzwl 0x4(%r13), %edx
cmpl (%rax), %ecx
jne 0x71ec
cmpw 0x4(%rax), %dx
jne 0x71ec
movzwl 0x6(%r13), %esi
cmpw 0x6(%rax), %si
jne 0x71ec
addl %ebp, %r14d
jmp 0x715b
movzwl 0x6(%r13), %esi
movl %ecx, (%rax)
movw %dx, 0x4(%rax)
movw %si, 0x6(%rax)
movzwl 0x4(%r13), %edi
callq 0x730a
cmpl $0x2, %r15d
jl 0x721c
movl 0x1ea27(%rip), %eax     # 0x25c38
movl %eax, %ecx
subl %ebp, %ecx
incl %ecx
cmpl %ecx, %r14d
jge 0x7263
movl (%r13), %edx
movl %r14d, %edi
movl %ebx, %esi
callq 0x76ad
leal -0x1(%rbp), %r12d
leal 0x1(%r14), %r15d
subl $0x1, %r12d
jb 0x71e4
leaq 0x1e9f9(%rip), %rdi     # 0x25c38
movl %r15d, %esi
movl %ebx, %edx
movq %rsp, %rcx
callq 0x72c9
testl %eax, %eax
jne 0x72ba
movq (%rsp), %rax
andl $0x0, (%rax)
movl 0x4(%r13), %ecx
movl %ecx, 0x4(%rax)
incl %r15d
jmp 0x7232
movl %r14d, %r15d
cmpl %eax, %r15d
jge 0x71e4
movl %r15d, %edi
movl %ebx, %esi
pushq $0x20
popq %rdx
callq 0x76ad
incl %r15d
movl 0x1e9b3(%rip), %eax     # 0x25c38
jmp 0x7266
incl %ebx
jmp 0x714c
pushq $-0x8
popq %rax
retq
movl 0x1e7f0(%rip), %edi     # 0x25a88
movl 0x1e7ee(%rip), %esi     # 0x25a8c
callq 0x771c
testl %eax, %eax
jne 0x72ba
movl 0x1e7c3(%rip), %edi     # 0x25a70
callq 0x77dd
movl %eax, %ecx
xorl %eax, %eax
negl %ecx
sbbl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq