// File: /workspace/github_c_makefile_star2_O3/mruby-zest[P]osc-bridge/src/bridge.c
// Function: br_recv
void br_recv(bridge_t *br, const char *msg)
{
    //char buffer[128];
    //rtosc_message(buffer, 128, "/part0/Pvolume", "i", 74);
    if(!msg)
        return;

    //if(rtosc_narguments(msg) < 3) {
    //    //printf("BR RECEIVE %s:%s\n", msg, rtosc_argument_string(msg));
    //    //printf("MESSAGE IS %d bytes\n", rtosc_message_length(msg, -1));
    //}
    br->last_update = 1e-3*uv_now(br->loop);

    if(!strcmp("/damage", msg) && !strcmp("s", rtosc_argument_string(msg))) {
        const char *dmg = rtosc_argument(msg, 0).s;
        br_damage(br, dmg);
        return;
    }

    const int nargs = rtosc_narguments(msg);
    if(nargs == 1)
        cache_set(br, msg, rtosc_type(msg, 0), rtosc_argument(msg, 0), 0);
    else {
        //Try to handle the vector message cases
        //printf("BRIDGE RECEIVE A VECTOR MESSAGE\n");
        //TODO verify that we've got some sort of uniformity?
        rtosc_arg_itr_t  itr   = rtosc_itr_begin(msg);
        rtosc_arg_t     *args  = (rtosc_arg_t*)calloc(nargs, sizeof(rtosc_arg_t));
        char            *types = strdup(rtosc_argument_string(msg));

        int offset = 0;
        while(!rtosc_itr_end(itr))
            args[offset++] = rtosc_itr_next(&itr).val;

        cache_set_vector(br, msg, types, args);
        free(args);
        free(types);
    }
    //for(int i=0; i<br->callback_len; ++i) {
    //    printf("cb name = %s\n", br->callback[i].path);
    //    bridge_callback_t cb = br->callback[i];
    //    if(!strcmp(cb.path, msg))
    //        cb.cb(msg, cb.data);
    //}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
testq %rsi, %rsi
je 0x26a4
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x2170
movq %rax, %xmm0
punpckldq 0x6add(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x6ae5(%rip), %xmm0     # 0x9020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x6ae1(%rip), %xmm1     # 0x9030
cvttsd2si %xmm1, %rax
movq %rax, %rcx
subsd 0x6ad9(%rip), %xmm1     # 0x9038
cvttsd2si %xmm1, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
movq %rdx, 0x130(%rbx)
leaq 0x6d0a(%rip), %rdi      # 0x9286
movq %r14, %rsi
callq 0x21a0
testl %eax, %eax
jne 0x25a6
movq %r14, %rdi
callq 0x6678
movzbl (%rax), %ecx
subl $0x73, %ecx
jne 0x259c
movzbl 0x1(%rax), %ecx
negl %ecx
testl %ecx, %ecx
je 0x26b3
movq %r14, %rdi
callq 0x66bf
cmpl $0x1, %eax
jne 0x25f0
movq %r14, %rdi
xorl %esi, %esi
callq 0x66f1
movl %eax, %r15d
movq %r14, %rdi
xorl %esi, %esi
callq 0x71d6
movq %rdx, %r8
movsbl %r15b, %edx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
xorl %r9d, %r9d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x325e
movl %eax, %r15d
movq %rbx, -0x50(%rbp)
movq %r14, %rdi
callq 0x6f14
movq %rax, %r12
movq %rdx, %r13
movq %rax, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
movslq %r15d, %rdi
movl $0x10, %esi
callq 0x2180
movq %rax, -0x30(%rbp)
movq %r14, %rdi
callq 0x6678
movq %rax, %rdi
callq 0x22c0
movq %rax, -0x48(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x71bc
testl %eax, %eax
jne 0x267a
leaq -0x60(%rbp), %r15
leaq -0x68(%rbp), %r13
leaq -0x40(%rbp), %r12
movq -0x30(%rbp), %rbx
movq %r13, %rdi
movq %r12, %rsi
callq 0x6f7b
movupd (%r15), %xmm0
movupd %xmm0, (%rbx)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x71bc
addq $0x10, %rbx
testl %eax, %eax
je 0x2651
movq -0x50(%rbp), %rdi
movq %r14, %rsi
movq -0x48(%rbp), %r14
movq %r14, %rdx
movq -0x30(%rbp), %rbx
movq %rbx, %rcx
callq 0x2f04
movq %rbx, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
xorl %esi, %esi
callq 0x71d6
movq %rbx, %rdi
movq %rax, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39a0