// File: /workspace/github_c_makefile_star2_O2/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 0x3570
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, -0x40(%rbp)
movq %rcx, -0x38(%rbp)
callq 0x35ae
movq 0x100(%r12), %r14
movslq 0x120(%r12), %r13
pushq $0x1
popq %rbx
leaq (%rbx,%r13), %rax
cmpq $0x1, %rax
je 0x347b
movq (%r14), %rdi
movq %r15, %rsi
callq 0x21a0
decq %rbx
addq $0x30, %r14
testl %eax, %eax
jne 0x3427
negq %rbx
cmpq %r13, %rbx
jae 0x347b
movq %r12, %rdi
movq %r15, %rsi
callq 0x30ae
movq %rax, %r15
movb 0x8(%rax), %al
notb %al
testb $0x5, %al
jne 0x3497
movb 0x9(%r15), %al
cmpb $0x76, %al
jne 0x34b3
movq (%r15), %rdx
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
jmp 0x34c4
movq %r12, %rdi
movq %r15, %rsi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3625
movq %r12, %rdi
movq %r15, %rsi
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36a4
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 0x64d1
testl %eax, %eax
jne 0x3550
movq (%r15), %rsi
leaq 0x4ce8(%rip), %rdi      # 0x81cb
movl $0x2c7, %edx            # imm = 0x2C7
xorl %eax, %eax
callq 0x20f0
movzbl 0x9(%r15), %eax
cmpl $0x76, %eax
jne 0x350a
movq (%r15), %rdx
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
xorl %edi, %edi
xorl %esi, %esi
jmp 0x353b
movb %al, -0x2a(%rbp)
movb $0x0, -0x29(%rbp)
addl $-0x46, %eax
cmpl $0x2e, %eax
ja 0x358f
movabsq $0x708d70006109, %rcx   # imm = 0x708D70006109
btq %rax, %rcx
jae 0x358f
movq (%r15), %rdx
addq $0x20, %r15
leaq -0x2a(%rbp), %rcx
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %r8
callq 0x64d1
leaq 0x4ccc(%rip), %rdi      # 0x8213
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 0x4c14(%rip), %rdi      # 0x818b
leaq 0x4bfe(%rip), %rsi      # 0x817c
leaq 0x4c09(%rip), %rcx      # 0x818e
movl $0x2af, %edx            # imm = 0x2AF
callq 0x2130
leaq 0x4c68(%rip), %rdi      # 0x81fe
leaq 0x4bdf(%rip), %rsi      # 0x817c
leaq 0x4bea(%rip), %rcx      # 0x818e
movl $0x2ca, %edx            # imm = 0x2CA
callq 0x2130