// File: /workspace/github_c_makefile_star2_O3/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, 0x1e72b(%rip)     # 0x25c8c
je 0x7746
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq $-0x1, 0x1e513(%rip) # 0x25a90
movl 0x1e6b9(%rip), %eax     # 0x25c3c
testl %eax, %eax
jle 0x771c
xorl %ebx, %ebx
movl 0x1e6a4(%rip), %r13d    # 0x25c38
testl %r13d, %r13d
jle 0x7712
xorl %ebp, %ebp
movl 0x1e682(%rip), %r12d    # 0x25c28
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
cmpl %ebp, %r12d
jle 0x7752
cmpl %ebx, 0x1e672(%rip)     # 0x25c2c
jle 0x7752
cmpl %ebx, 0x1e676(%rip)     # 0x25c3c
jle 0x7752
movq 0x1e65d(%rip), %r14     # 0x25c30
imull %ebx, %r12d
addl %ebp, %r12d
movq 0x1e65f(%rip), %r15     # 0x25c40
imull %ebx, %r13d
addl %ebp, %r13d
movl (%r14,%r12,8), %edi
callq 0x63c0
cmpl $0x2, %eax
movl $0x1, %ecx
movl %eax, 0x4(%rsp)
cmovgel %eax, %ecx
movl %ecx, (%rsp)
movl (%r14,%r12,8), %eax
movzwl 0x4(%r14,%r12,8), %ecx
cmpl (%r15,%r13,8), %eax
jne 0x762d
cmpw 0x4(%r15,%r13,8), %cx
jne 0x762d
movzwl 0x6(%r14,%r12,8), %edx
cmpw 0x6(%r15,%r13,8), %dx
je 0x76d3
movzwl 0x6(%r14,%r12,8), %esi
movl %eax, (%r15,%r13,8)
movw %cx, 0x4(%r15,%r13,8)
movw %si, 0x6(%r15,%r13,8)
movzwl 0x4(%r14,%r12,8), %edi
callq 0x7763
movl 0x4(%rsp), %r15d
cmpl $0x2, %r15d
jl 0x76c6
movl 0x1e5d9(%rip), %eax     # 0x25c38
movl %eax, %ecx
subl (%rsp), %ecx
incl %ecx
cmpl %ecx, %ebp
jge 0x76e8
movl (%r14,%r12,8), %edx
movl %ebp, %edi
movl %ebx, %esi
callq 0x7b81
movl 0x1e5bb(%rip), %eax     # 0x25c38
movl %ebp, %ecx
movl %r15d, %edx
movl %ebx, %esi
imull %eax, %esi
shlq $0x3, %rsi
addq 0x1e5ae(%rip), %rsi     # 0x25c40
incq %rcx
decq %rdx
cmpl %ecx, %eax
jle 0x774d
cmpl %ebx, 0x1e596(%rip)     # 0x25c3c
jle 0x774d
movl $0x0, (%rsi,%rcx,8)
movl 0x4(%r14,%r12,8), %edi
movl %edi, 0x4(%rsi,%rcx,8)
incq %rcx
decq %rdx
jne 0x7698
jmp 0x76d3
movl (%r14,%r12,8), %edx
movl %ebp, %edi
movl %ebx, %esi
callq 0x7b81
addl (%rsp), %ebp
movl 0x1e55b(%rip), %r13d    # 0x25c38
cmpl %r13d, %ebp
jl 0x759f
jmp 0x770c
cmpl %eax, %ebp
jge 0x76d3
movl %ebp, %r14d
movl %r14d, %edi
movl %ebx, %esi
movl $0x20, %edx
callq 0x7b81
incl %r14d
cmpl 0x1e530(%rip), %r14d    # 0x25c38
jl 0x76ef
jmp 0x76d3
movl 0x1e52a(%rip), %eax     # 0x25c3c
incl %ebx
cmpl %eax, %ebx
jl 0x7594
movl 0x1e366(%rip), %edi     # 0x25a88
movl 0x1e364(%rip), %esi     # 0x25a8c
callq 0x7bf0
movl %eax, %ecx
testl %eax, %eax
jne 0x7752
movl 0x1e337(%rip), %edi     # 0x25a70
callq 0x7cb7
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
jmp 0x7752
movl $0xfffffff8, %ecx       # imm = 0xFFFFFFF8
jmp 0x7760
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %ecx, %eax
retq