// File: /workspace/github_c_makefile_star2_O1/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 0x369b
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, -0x40(%rbp)
movq %rcx, -0x38(%rbp)
callq 0x36d9
movslq 0x120(%r12), %r13
testq %r13, %r13
setne %r14b
je 0x3575
movq 0x100(%r12), %rbx
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x21a0
testl %eax, %eax
je 0x3575
addq $0x30, %rbx
movl $0x1, %ecx
movq %rcx, %r14
cmpq %rcx, %r13
je 0x356e
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x21a0
leaq 0x1(%r14), %rcx
addq $0x30, %rbx
testl %eax, %eax
jne 0x354f
cmpq %r13, %r14
setb %r14b
testb %r14b, %r14b
je 0x35a6
movq %r12, %rdi
movq %r15, %rsi
callq 0x3175
movq %rax, %r15
movb 0x8(%rax), %al
notb %al
testb $0x5, %al
jne 0x35c2
movb 0x9(%r15), %al
cmpb $0x76, %al
jne 0x35de
movq (%r15), %rdx
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
jmp 0x35ef
movq %r12, %rdi
movq %r15, %rsi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3759
movq %r12, %rdi
movq %r15, %rsi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x37e3
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 0x6b54
testl %eax, %eax
jne 0x367b
movq (%r15), %rsi
leaq 0x5bbd(%rip), %rdi      # 0x91cb
movl $0x2c7, %edx            # imm = 0x2C7
xorl %eax, %eax
callq 0x20f0
movzbl 0x9(%r15), %eax
cmpl $0x76, %eax
jne 0x3635
movq (%r15), %rdx
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
xorl %edi, %edi
xorl %esi, %esi
jmp 0x3666
movb %al, -0x2a(%rbp)
movb $0x0, -0x29(%rbp)
addl $-0x46, %eax
cmpl $0x2e, %eax
ja 0x36ba
movabsq $0x708d70006109, %rcx   # imm = 0x708D70006109
btq %rax, %rcx
jae 0x36ba
movq (%r15), %rdx
addq $0x20, %r15
leaq -0x2a(%rbp), %rcx
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %r8
callq 0x6b54
leaq 0x5ba1(%rip), %rdi      # 0x9213
movl %eax, %esi
xorl %eax, %eax
callq 0x20f0
leaq -0x4040(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq *-0x40(%rbp)
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5ae9(%rip), %rdi      # 0x918b
leaq 0x5ad3(%rip), %rsi      # 0x917c
leaq 0x5ade(%rip), %rcx      # 0x918e
movl $0x2af, %edx            # imm = 0x2AF
callq 0x2130
leaq 0x5b3d(%rip), %rdi      # 0x91fe
leaq 0x5ab4(%rip), %rsi      # 0x917c
leaq 0x5abf(%rip), %rcx      # 0x918e
movl $0x2ca, %edx            # imm = 0x2CA
callq 0x2130