// File: /workspace/github_c_makefile_star2_O0/mruby-zest[P]osc-bridge/src/bridge.c
// Function: br_tick
void br_tick(bridge_t *br)
{
    //Run all network events
    for(int i=0; i<200; ++i)
        uv_run(br->loop, UV_RUN_NOWAIT);

    if(br->frame_messages >= BR_RATE_LIMIT) {
        //printf("[INFO] Hit rate limit\n");
    }

    br->frame_messages = 0;
    if(br->rlimit) {
        //printf("[INFO] Reading through rate limited fields\n");
        for(int i=0; i<br->rlimit_len && i<BR_RATE_LIMIT; ++i) {
            char *msg = br->rlimit[i];
            //printf("[DEBUG] message = \"%s\"\n", msg);
            do_send(br, msg, rtosc_message_length(msg, -1));
        }
        if(br->frame_messages == br->rlimit_len) {
            //printf("[INFO] Clearing rate limit queue\n");
            br->rlimit_len = 0;
            free(br->rlimit);
            br->rlimit = 0;
        } else {
            char **base = br->rlimit;
            int N = br->frame_messages;
            int M = br->rlimit_len;
            //printf("[INFO] Shrinking rate limit queue %d=>%d\n", M, M-N);
            memmove(base, base+N, sizeof(void*)*(M-N));
            br->rlimit_len = M-N;
        }
        //wait 10ms
        //usleep(10000);
    }
    uv_update_time(br->loop);
    double now  = 1e-3*uv_now(br->loop);

    if(!br->rlimit) {
        for(int i=0; i<br->cache_len; ++i) {
            char *path   = br->cache[i].path;
            int   pend   = br->cache[i].pending;
            int   valid  = br->cache[i].valid;
            int   usable = br->cache[i].usable;
            int   fref   = br->cache[i].force_refresh;
            double uptim = br->cache[i].request_time;
            int   rq     = br->cache[i].requests;
            (void) path;
            if(usable && (pend || !valid)) {
                //printf("cache status = <%s, %d, %d, %f, %d>\n", path, pend, valid, uptim, rq);
                if(uptim < now - 300e-3) {
                    if(rq < 10)
                        cache_update(br, &br->cache[i]);
                    //else if(br->cache[i].requests++ == 10)
                    //    printf("[ERROR] Invalid parameter cannot be accessed at <%s>\n", path);
                }
            } else if(usable && fref)
                if(uptim < now - 50e-3)
                    cache_update(br, &br->cache[i]);

        }
    }

    //Attempt to disable debouncing
    if(br->debounce_len == 0)
        return;
    double delta  = 200e-3;
    double thresh = now - delta;
    for(int i=br->debounce_len-1; i >= 0; --i) {
        if(br->bounce[i].last_set < thresh) {
            run_callbacks(br, cache_get(br, br->bounce[i].path));
            debounce_pop(br, i);
        }
    }


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0xc8, -0xc(%rbp)
jge 0x467b
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl $0x2, %esi
callq 0x22f0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x4656
movq -0x8(%rbp), %rax
cmpl $0x80, 0xfc(%rax)
jl 0x468d
jmp 0x468d
movq -0x8(%rbp), %rax
movl $0x0, 0xfc(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x118(%rax)
je 0x47dd
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpl 0x12c(%rdx), %ecx
movb %al, -0x75(%rbp)
jge 0x46d5
cmpl $0x80, -0x10(%rbp)
setl %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %al
testb $0x1, %al
jne 0x46de
jmp 0x4738
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
movq $-0x1, %rsi
callq 0xa5d0
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
movl %eax, %edx
callq 0x2730
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x46b4
movq -0x8(%rbp), %rax
movl 0xfc(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x12c(%rcx), %eax
jne 0x477d
movq -0x8(%rbp), %rax
movl $0x0, 0x12c(%rax)
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x2030
movq -0x8(%rbp), %rax
movq $0x0, 0x118(%rax)
jmp 0x47db
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0xfc(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x12c(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x24(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl -0x28(%rbp), %eax
subl -0x24(%rbp), %eax
movslq %eax, %rdx
shlq $0x3, %rdx
callq 0x2240
movl -0x28(%rbp), %ecx
subl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x12c(%rax)
jmp 0x47dd
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x2280
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x2170
movq %rax, %xmm1
movaps 0x780f(%rip), %xmm0     # 0xc010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x7813(%rip), %xmm0     # 0xc020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x780c(%rip), %xmm0     # 0xc030
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x118(%rax)
jne 0x49fa
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x120(%rcx), %eax
jge 0x49f8
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movb 0x8(%rax), %al
shlb $0x6, %al
sarb $0x7, %al
movsbl %al, %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movb 0x8(%rax), %al
shlb $0x7, %al
sarb $0x7, %al
movsbl %al, %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movb 0x8(%rax), %al
shlb $0x5, %al
sarb $0x7, %al
movsbl %al, %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movb 0x8(%rax), %al
shlb $0x4, %al
sarb $0x7, %al
movsbl %al, %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x499d
cmpl $0x0, -0x44(%rbp)
jne 0x4958
cmpl $0x0, -0x48(%rbp)
jne 0x499d
movsd -0x58(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
movsd 0x76de(%rip), %xmm2     # 0xc048
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x499b
cmpl $0xa, -0x5c(%rbp)
jge 0x4999
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rsi
movslq -0x34(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rsi
callq 0x3e40
jmp 0x499b
jmp 0x49e8
cmpl $0x0, -0x4c(%rbp)
je 0x49e6
cmpl $0x0, -0x50(%rbp)
je 0x49e6
movsd -0x58(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
movsd 0x7685(%rip), %xmm2     # 0xc040
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x49e4
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rsi
movslq -0x34(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rsi
callq 0x3e40
jmp 0x49e6
jmp 0x49e8
jmp 0x49ea
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4846
jmp 0x49fa
movq -0x8(%rbp), %rax
cmpl $0x0, 0x124(%rax)
jne 0x4a0c
jmp 0x4abc
movsd 0x763c(%rip), %xmm0     # 0xc050
movsd %xmm0, -0x68(%rbp)
movsd -0x30(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x8(%rbp), %rax
movl 0x124(%rax), %eax
subl $0x1, %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
jl 0x4abc
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rax
movslq -0x74(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movsd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4aac
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rax
movslq -0x74(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x3580
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x4ad0
movq -0x8(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x4d30
jmp 0x4aae
movl -0x74(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x4a38
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)