// File: /workspace/github_c_makefile_star2_O3/mruby-zest[P]osc-bridge/src/bridge.c
// Function: br_add_callback
void br_add_callback(bridge_t *br, uri_t uri, bridge_cb_t callback, void *data)
{
    assert(br);
    callback_push(br, uri, callback, data);
    if(!cache_has(br->cache, br->cache_len, uri)) {
        cache_push(br, uri);
    } else {
        //instantly respond when possible
        param_cache_t *ch = cache_get(br, uri);
        if(!ch->valid || !ch->usable) {
            cache_update(br, ch);
            return;
        }
        char buffer[1024*16];
        int len = 0;

        if(ch->type != 'v') {
            char typestr[2] = {ch->type,0};
            len = rtosc_amessage(buffer, sizeof(buffer), ch->path,
                    typestr, &ch->val);
        } else {
            len = rtosc_amessage(buffer, sizeof(buffer), ch->path, ch->vec_type,
                    ch->vec_value);
        }
        if(len == 0) {
            //TODO USE DYNAMIC ALLOCATION...
            printf("[ERROR] Message Too long for cache line <%s> @ %d\n", ch->path, __LINE__);
            if(ch->type != 'v') {
                char args[2] = {ch->type, 0};
                assert(valid_type(ch->type));
                len = rtosc_amessage(0, 0, ch->path, args, &ch->val);
            } else {
                len = rtosc_amessage(0, 0, ch->path, ch->vec_type,
                        ch->vec_value);
            }
            printf("[ERROR] Needs %d bytes of space...\n", len);
        }

        callback(buffer, data);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4018, %rsp           # imm = 0x4018
testq %rdi, %rdi
je 0x3650
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq %rcx, -0x40(%rbp)
callq 0x368e
movslq 0x120(%r12), %r13
testq %r13, %r13
je 0x355b
movq 0x100(%r12), %rbx
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x21a0
testl %eax, %eax
je 0x352f
movq %r14, -0x38(%rbp)
addq $0x30, %rbx
movl $0x1, %ecx
movq %rcx, %r14
cmpq %rcx, %r13
je 0x3526
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x21a0
leaq 0x1(%r14), %rcx
addq $0x30, %rbx
testl %eax, %eax
jne 0x3507
cmpq %r13, %r14
movq -0x38(%rbp), %r14
jae 0x355b
movq %r12, %rdi
movq %r15, %rsi
callq 0x3171
movq %rax, %r15
movb 0x8(%rax), %al
notb %al
testb $0x5, %al
jne 0x3577
movb 0x9(%r15), %al
cmpb $0x76, %al
jne 0x3593
movq (%r15), %rdx
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
jmp 0x35a4
movq %r12, %rdi
movq %r15, %rsi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x370e
movq %r12, %rdi
movq %r15, %rsi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x379c
leaq -0x2a(%rbp), %rcx
movb %al, (%rcx)
movb $0x0, 0x1(%rcx)
movq (%r15), %rdx
leaq 0x20(%r15), %r8
leaq -0x4040(%rbp), %rdi
movl $0x4000, %esi           # imm = 0x4000
callq 0x6acf
testl %eax, %eax
jne 0x3630
movq (%r15), %rsi
leaq 0x5c08(%rip), %rdi      # 0x91cb
movl $0x2c7, %edx            # imm = 0x2C7
xorl %eax, %eax
callq 0x20f0
movzbl 0x9(%r15), %eax
cmpl $0x76, %eax
jne 0x35ea
movq (%r15), %rdx
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
xorl %edi, %edi
xorl %esi, %esi
jmp 0x361b
movb %al, -0x2a(%rbp)
movb $0x0, -0x29(%rbp)
addl $-0x46, %eax
cmpl $0x2e, %eax
ja 0x366f
movabsq $0x708d70006109, %rcx   # imm = 0x708D70006109
btq %rax, %rcx
jae 0x366f
movq (%r15), %rdx
addq $0x20, %r15
leaq -0x2a(%rbp), %rcx
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %r8
callq 0x6acf
leaq 0x5bec(%rip), %rdi      # 0x9213
movl %eax, %esi
xorl %eax, %eax
callq 0x20f0
leaq -0x4040(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq *%r14
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5b34(%rip), %rdi      # 0x918b
leaq 0x5b1e(%rip), %rsi      # 0x917c
leaq 0x5b29(%rip), %rcx      # 0x918e
movl $0x2af, %edx            # imm = 0x2AF
callq 0x2130
leaq 0x5b88(%rip), %rdi      # 0x91fe
leaq 0x5aff(%rip), %rsi      # 0x917c
leaq 0x5b0a(%rip), %rcx      # 0x918e
movl $0x2ca, %edx            # imm = 0x2CA
callq 0x2130