// File: /workspace/github_c_makefile_star2_O0/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
subq $0x4040, %rsp           # imm = 0x4040
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x3a04
jmp 0x3a23
leaq 0x8877(%rip), %rdi      # 0xc282
leaq 0x87fd(%rip), %rsi      # 0xc20f
movl $0x2af, %edx            # imm = 0x2AF
leaq 0x8867(%rip), %rcx      # 0xc285
callq 0x2120
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x3c40
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rdi
movq -0x8(%rbp), %rax
movslq 0x120(%rax), %rsi
movq -0x10(%rbp), %rdx
callq 0x3cf0
cmpl $0x0, %eax
jne 0x3a6e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3d60
jmp 0x3c2e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3580
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb 0x8(%rax), %al
shlb $0x7, %al
sarb $0x7, %al
cmpb $0x0, %al
je 0x3aa1
movq -0x28(%rbp), %rax
movb 0x8(%rax), %al
shlb $0x5, %al
sarb $0x7, %al
cmpb $0x0, %al
jne 0x3ab3
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3e40
jmp 0x3c2e
movl $0x0, -0x4034(%rbp)
movq -0x28(%rbp), %rax
movsbl 0x9(%rax), %eax
cmpl $0x76, %eax
je 0x3b0d
movq -0x28(%rbp), %rax
movb 0x9(%rax), %al
movb %al, -0x4036(%rbp)
movb $0x0, -0x4035(%rbp)
leaq -0x4030(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
leaq -0x4036(%rbp), %rcx
movq -0x28(%rbp), %r8
addq $0x20, %r8
movl $0x4000, %esi           # imm = 0x4000
callq 0x8f70
movl %eax, -0x4034(%rbp)
jmp 0x3b3b
leaq -0x4030(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %r8
movl $0x4000, %esi           # imm = 0x4000
callq 0x8f70
movl %eax, -0x4034(%rbp)
cmpl $0x0, -0x4034(%rbp)
jne 0x3c1d
movq -0x28(%rbp), %rax
movq (%rax), %rsi
leaq 0x876c(%rip), %rdi      # 0xc2c2
movl $0x2c7, %edx            # imm = 0x2C7
movb $0x0, %al
callq 0x20e0
movq -0x28(%rbp), %rax
movsbl 0x9(%rax), %eax
cmpl $0x76, %eax
je 0x3be0
movq -0x28(%rbp), %rax
movb 0x9(%rax), %al
movb %al, -0x4038(%rbp)
movb $0x0, -0x4037(%rbp)
movq -0x28(%rbp), %rax
movsbl 0x9(%rax), %edi
callq 0x3fa0
cmpl $0x0, %eax
je 0x3b97
jmp 0x3bb6
leaq 0x8757(%rip), %rdi      # 0xc2f5
leaq 0x866a(%rip), %rsi      # 0xc20f
movl $0x2ca, %edx            # imm = 0x2CA
leaq 0x86d4(%rip), %rcx      # 0xc285
callq 0x2120
movq -0x28(%rbp), %rax
movq (%rax), %rdx
leaq -0x4038(%rbp), %rcx
movq -0x28(%rbp), %r8
addq $0x20, %r8
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x8f70
movl %eax, -0x4034(%rbp)
jmp 0x3c09
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %r8
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x8f70
movl %eax, -0x4034(%rbp)
movl -0x4034(%rbp), %esi
leaq 0x86f4(%rip), %rdi      # 0xc30a
movb $0x0, %al
callq 0x20e0
movq -0x18(%rbp), %rax
leaq -0x4030(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq *%rax
addq $0x4040, %rsp           # imm = 0x4040
popq %rbp
retq
nopw (%rax,%rax)