// File: /workspace/github_c_makefile_star2_O0/adsr[P]phpspy/vendor/termbox2/termbox2.h
// Function: update_term_size_via_esc
static int update_term_size_via_esc(void) {
#ifndef TB_RESIZE_FALLBACK_MS
#define TB_RESIZE_FALLBACK_MS 1000
#endif

    char *move_and_report = "\x1b[9999;9999H\x1b[6n";
    ssize_t write_rv =
        write(global.wfd, move_and_report, strlen(move_and_report));
    if (write_rv != (ssize_t)strlen(move_and_report)) {
        return TB_ERR_RESIZE_WRITE;
    }

    fd_set fds;
    FD_ZERO(&fds);
    FD_SET(global.rfd, &fds);

    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = TB_RESIZE_FALLBACK_MS * 1000;

    int select_rv = select(global.rfd + 1, &fds, NULL, NULL, &timeout);

    if (select_rv != 1) {
        global.last_errno = errno;
        return TB_ERR_RESIZE_POLL;
    }

    char buf[TB_OPT_READ_BUF];
    ssize_t read_rv = read(global.rfd, buf, sizeof(buf) - 1);
    if (read_rv < 1) {
        global.last_errno = errno;
        return TB_ERR_RESIZE_READ;
    }
    buf[read_rv] = '\0';

    int rw, rh;
    if (sscanf(buf, "\x1b[%d;%dR", &rh, &rw) != 2) {
        return TB_ERR_RESIZE_SSCANF;
    }

    global.width = rw;
    global.height = rh;
    return TB_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
leaq 0x27967(%rip), %rax     # 0x34859
movq %rax, -0x10(%rbp)
movl 0x2efa4(%rip), %eax     # 0x3bea0
movl %eax, -0x124(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6160
movl -0x124(%rbp), %edi
movq -0x120(%rbp), %rsi
movq %rax, %rdx
callq 0x6120
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6160
movq %rax, %rcx
movq -0x118(%rbp), %rax
cmpq %rcx, %rax
je 0xcf5e
movl $0xffffffee, -0x4(%rbp) # imm = 0xFFFFFFEE
jmp 0xd0e7
jmp 0xcf60
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpq $0x10, %rax
jae 0xcfaa
movq -0xa8(%rbp), %rax
movl -0x9c(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0xcf78
jmp 0xcfac
movl 0x2eeea(%rip), %eax     # 0x3be9c
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl 0x2eecd(%rip), %eax     # 0x3be9c
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x98(%rbp,%rax,8), %rcx
movq %rcx, -0x98(%rbp,%rax,8)
movq $0x0, -0xb8(%rbp)
movq $0xf4240, -0xb0(%rbp) # imm = 0xF4240
movl 0x2ee97(%rip), %edi     # 0x3be9c
addl $0x1, %edi
leaq -0x98(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0xb8(%rbp), %r8
movq %rcx, %rdx
callq 0x6390
movl %eax, -0xbc(%rbp)
cmpl $0x1, -0xbc(%rbp)
je 0xd04a
callq 0x6060
movl (%rax), %eax
movl %eax, 0x2f07a(%rip)     # 0x3c0b8
movl $0xffffffed, -0x4(%rbp) # imm = 0xFFFFFFED
jmp 0xd0e7
movl 0x2ee4c(%rip), %edi     # 0x3be9c
leaq -0x100(%rbp), %rsi
movl $0x3f, %edx
callq 0x62a0
movq %rax, -0x108(%rbp)
cmpq $0x1, -0x108(%rbp)
jge 0xd088
callq 0x6060
movl (%rax), %eax
movl %eax, 0x2f039(%rip)     # 0x3c0b8
movl $0xffffffec, -0x4(%rbp) # imm = 0xFFFFFFEC
jmp 0xd0e7
movq -0x108(%rbp), %rax
movb $0x0, -0x100(%rbp,%rax)
leaq -0x100(%rbp), %rdi
leaq 0x277c5(%rip), %rsi     # 0x3486a
leaq -0x110(%rbp), %rdx
leaq -0x10c(%rbp), %rcx
movb $0x0, %al
callq 0x63f0
cmpl $0x2, %eax
je 0xd0c8
movl $0xffffffeb, -0x4(%rbp) # imm = 0xFFFFFFEB
jmp 0xd0e7
movl -0x10c(%rbp), %eax
movl %eax, 0x2eddc(%rip)     # 0x3beb0
movl -0x110(%rbp), %eax
movl %eax, 0x2edd4(%rip)     # 0x3beb4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)