// File: /workspace/github_c_makefile_star2_O1/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, 0x1e687(%rip)     # 0x25c8c
je 0x7864
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq $-0x1, 0x1e46c(%rip) # 0x25a90
cmpl $0x0, 0x1e611(%rip)     # 0x25c3c
jle 0x7829
xorl %edx, %edx
xorl %ebp, %ebp
xorl %r14d, %r14d
movl 0x1e5f9(%rip), %r13d    # 0x25c38
cmpl %r13d, %r14d
jge 0x781b
movl %r14d, %esi
movl 0x1e5d6(%rip), %r12d    # 0x25c28
cmpl %r14d, %r12d
setg %cl
cmpl %ebp, 0x1e5ce(%rip)     # 0x25c2c
setg %al
imull %ebp, %r12d
addl %r14d, %r12d
shlq $0x3, %r12
addq 0x1e5bd(%rip), %r12     # 0x25c30
andb %cl, %al
testb %al, %al
cmoveq %rdx, %r12
je 0x77c3
cmpl %r14d, %r13d
setg %cl
cmpl %ebp, 0x1e5af(%rip)     # 0x25c3c
setg %al
imull %ebp, %r13d
addl %r14d, %r13d
shlq $0x3, %r13
addq 0x1e59e(%rip), %r13     # 0x25c40
andb %cl, %al
testb %al, %al
cmoveq %rdx, %r13
je 0x77c3
movq %rsi, 0x10(%rsp)
movl %r10d, 0xc(%rsp)
movl (%r12), %edi
callq 0x63c0
movl %eax, %r15d
cmpl $0x2, %eax
movl $0x1, %ebx
cmovgel %eax, %ebx
movl (%r12), %eax
cmpl (%r13), %eax
jne 0x76f9
movzwl 0x4(%r12), %ecx
cmpw 0x4(%r13), %cx
jne 0x76f9
movzwl 0x6(%r12), %ecx
cmpw 0x6(%r13), %cx
je 0x77fb
movl 0x4(%r12), %ecx
movl %eax, (%r13)
movl %ecx, 0x4(%r13)
movzwl 0x4(%r12), %edi
movzwl 0x6(%r12), %esi
callq 0x786e
cmpl $0x2, %r15d
jl 0x7730
movl 0x1e515(%rip), %eax     # 0x25c38
subl %ebx, %eax
incl %eax
cmpl %eax, %r14d
jge 0x77d4
movl (%r12), %edx
movl %r14d, %edi
movl %ebp, %esi
callq 0x7c78
cmpl $0x2, %r15d
jl 0x77fb
movl 0x1e4ea(%rip), %eax     # 0x25c38
movl %r15d, %ecx
movl %ebp, %edx
imull %eax, %edx
shlq $0x3, %rdx
movq 0x10(%rsp), %r11
leaq (%rdx,%r11,8), %rdx
movl $0x1, %esi
movl 0xc(%rsp), %r10d
leal (%r11,%rsi), %edi
cmpl %edi, %eax
setg %r8b
cmpl %ebp, 0x1e4bf(%rip)     # 0x25c3c
setg %dil
andb %r8b, %dil
cmpb $0x1, %dil
jne 0x77a8
movq 0x1e4af(%rip), %r8      # 0x25c40
addq %rdx, %r8
movl 0x4(%r12), %r9d
movl $0x0, (%r8,%rsi,8)
movl %r9d, 0x4(%r8,%rsi,8)
jmp 0x77b4
movzbl %dil, %r8d
leal (%r8,%r8,8), %r10d
addl $-0x9, %r10d
testb %dil, %dil
je 0x7814
incq %rsi
cmpq %rsi, %rcx
jne 0x776d
jmp 0x7800
movzbl %al, %eax
leal (%rax,%rax,8), %r10d
addl $-0x9, %r10d
xorl %eax, %eax
movl %esi, %ebx
jmp 0x7807
cmpl 0x1e45d(%rip), %r14d    # 0x25c38
jge 0x77fb
movl %r14d, %r15d
movl %r15d, %edi
movl %ebp, %esi
movl $0x20, %edx
callq 0x7c78
incl %r15d
cmpl 0x1e43f(%rip), %r15d    # 0x25c38
jl 0x77e0
movl 0xc(%rsp), %r10d
addl %r14d, %ebx
movb $0x1, %al
xorl %edx, %edx
movl %ebx, %r14d
testb %al, %al
jne 0x7638
jmp 0x7854
xorl %eax, %eax
movl %r11d, %ebx
jmp 0x7805
incl %ebp
cmpl 0x1e419(%rip), %ebp     # 0x25c3c
jl 0x7635
movl 0x1e259(%rip), %edi     # 0x25a88
movl 0x1e257(%rip), %esi     # 0x25a8c
callq 0x7cf6
movl %eax, %r10d
testl %eax, %eax
jne 0x7854
movl 0x1e229(%rip), %edi     # 0x25a70
callq 0x7dbd
xorl %r10d, %r10d
negl %eax
sbbl %r10d, %r10d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x786a
movl $0xfffffff8, %r10d      # imm = 0xFFFFFFF8
movl %r10d, %eax
retq