// File: /workspace/github_c_makefile_star2_O0/termbox[P]termbox/termbox.c
// Function: wait_fill_event
static int wait_fill_event(struct tb_event *event, struct timeval *timeout) {
    // ;-)
#define ENOUGH_DATA_FOR_PARSING 64
    fd_set events;
    memset(event, 0, sizeof(struct tb_event));

    // try to extract event from input buffer, return on success
    event->type = TB_EVENT_KEY;
    if (extract_event(event, &input_buffer, inputmode))
        return event->type;

    // it looks like input buffer is incomplete, let's try the short path,
    // but first make sure there is enough space
    int n = read_up_to(ENOUGH_DATA_FOR_PARSING);
    if (n < 0)
        return -1;
    if (n > 0 && extract_event(event, &input_buffer, inputmode))
        return event->type;

    // n == 0, or not enough data, let's go to select
    while (1) {
        FD_ZERO(&events);
        FD_SET(inout, &events);
        FD_SET(winch_fds[0], &events);
        int maxfd = (winch_fds[0] > inout) ? winch_fds[0] : inout;
        int result = select(maxfd + 1, &events, 0, 0, timeout);
        if (!result)
            return 0;
        if (result < 0)
            return -1;

        if (FD_ISSET(inout, &events)) {
            event->type = TB_EVENT_KEY;
            n = read_up_to(ENOUGH_DATA_FOR_PARSING);
            if (n < 0)
                return -1;

            if (n == 0)
                continue;

            if (extract_event(event, &input_buffer, inputmode))
                return event->type;
        }
        if (FD_ISSET(winch_fds[0], &events)) {
            event->type = TB_EVENT_RESIZE;
            int zzz = 0;
            read(winch_fds[0], &zzz, sizeof(int));
            buffer_size_change_request = 1;
            get_term_size(&event->w, &event->h);
            return TB_EVENT_RESIZE;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3100
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rdi
movl 0x5714(%rip), %edx      # 0xa158
leaq 0x5f3d(%rip), %rsi      # 0xa988
callq 0x5ab0
testb $0x1, %al
jne 0x4a56
jmp 0x4a65
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x4d5c
movl $0x40, %edi
callq 0x5c90
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
jge 0x4a8a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d5c
cmpl $0x0, -0x9c(%rbp)
jle 0x4abe
movq -0x10(%rbp), %rdi
movl 0x56bb(%rip), %edx      # 0xa158
leaq 0x5ee4(%rip), %rsi      # 0xa988
callq 0x5ab0
testb $0x1, %al
jne 0x4aaf
jmp 0x4abe
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x4d5c
jmp 0x4ac0
jmp 0x4ac2
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpq $0x10, %rax
jae 0x4b0c
movq -0xa8(%rbp), %rax
movl -0xa0(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x4ada
jmp 0x4b0e
movl 0x5e2c(%rip), %eax      # 0xa940
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl 0x5e0f(%rip), %eax      # 0xa940
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x98(%rbp,%rax,8), %rcx
movq %rcx, -0x98(%rbp,%rax,8)
movl 0x5df3(%rip), %eax      # 0xa944
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl 0x5dd6(%rip), %eax      # 0xa944
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x98(%rbp,%rax,8), %rcx
movq %rcx, -0x98(%rbp,%rax,8)
movl 0x5db6(%rip), %eax      # 0xa944
cmpl 0x5dac(%rip), %eax      # 0xa940
jle 0x4ba4
movl 0x5da8(%rip), %eax      # 0xa944
movl %eax, -0xb8(%rbp)
jmp 0x4bb0
movl 0x5d96(%rip), %eax      # 0xa940
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %edi
addl $0x1, %edi
movq -0x18(%rbp), %r8
leaq -0x98(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x3190
movl %eax, -0xb0(%rbp)
cmpl $0x0, -0xb0(%rbp)
jne 0x4bf7
movl $0x0, -0x4(%rbp)
jmp 0x4d5c
cmpl $0x0, -0xb0(%rbp)
jge 0x4c0c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d5c
movl 0x5d2e(%rip), %eax      # 0xa940
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x98(%rbp,%rax,8), %rax
movq %rax, -0xc0(%rbp)
movl 0x5d0f(%rip), %eax      # 0xa940
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xc0(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x4cbd
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movl $0x40, %edi
callq 0x5c90
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
jge 0x4c82
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d5c
cmpl $0x0, -0x9c(%rbp)
jne 0x4c90
jmp 0x4ac0
movq -0x10(%rbp), %rdi
movl 0x54be(%rip), %edx      # 0xa158
leaq 0x5ce7(%rip), %rsi      # 0xa988
callq 0x5ab0
testb $0x1, %al
jne 0x4cac
jmp 0x4cbb
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x4d5c
jmp 0x4cbd
movl 0x5c81(%rip), %eax      # 0xa944
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x98(%rbp,%rax,8), %rax
movq %rax, -0xc8(%rbp)
movl 0x5c62(%rip), %eax      # 0xa944
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xc8(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x4d57
movq -0x10(%rbp), %rax
movb $0x2, (%rax)
movl $0x0, -0xb4(%rbp)
movl 0x5c26(%rip), %edi      # 0xa944
leaq -0xb4(%rbp), %rsi
movl $0x4, %edx
callq 0x3140
movl $0x1, 0x5c97(%rip)      # 0xa9d0
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
addq $0xc, %rsi
callq 0x5de0
movl $0x2, -0x4(%rbp)
jmp 0x4d5c
jmp 0x4ac0
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)