// File: /workspace/github_c_makefile_star2_O3/mruby-zest[P]osc-bridge/rtosc/rtosc.c
// Function: rtosc_message_ring_length
size_t rtosc_message_ring_length(ring_t *ring)
{
    //Check if the message is a bundle
    if(deref(0,ring) == '#' &&
            deref(1,ring) == 'b' &&
            deref(2,ring) == 'u' &&
            deref(3,ring) == 'n' &&
            deref(4,ring) == 'd' &&
            deref(5,ring) == 'l' &&
            deref(6,ring) == 'e' &&
            deref(7,ring) == '\0')
        return bundle_ring_length(ring);

    //Proceed for normal messages
    //Consume path
    unsigned pos = 0;
    while(deref(pos++,ring));
    pos--;

    //Travel through the null word end [1..4] bytes
    for(int i=0; i<4; ++i)
        if(deref(++pos, ring))
            break;

    if(deref(pos, ring) != ',')
        return 0;

    unsigned aligned_pos = pos;
    int arguments = pos+1;
    while(deref(++pos,ring));
    pos += 4-(pos-aligned_pos)%4;

    unsigned toparse = 0;
    {
        int arg = arguments-1;
        while(deref(++arg,ring))
            toparse += has_reserved(deref(arg,ring));
    }

    //Take care of varargs
    while(toparse)
    {
        char arg = deref(arguments++,ring);
        assert(arg);
        uint32_t i;
        switch(arg) {
            case 'h':
            case 't':
            case 'd':
                pos += 8;
                --toparse;
                break;
            case 'm':
            case 'r':
            case 'c':
            case 'f':
            case 'i':
                pos += 4;
                --toparse;
                break;
            case 'S':
            case 's':
                while(deref(++pos,ring));
                pos += 4-(pos-aligned_pos)%4;
                --toparse;
                break;
            case 'b':
                i = 0;
                i |= (deref(pos++,ring) << 24);
                i |= (deref(pos++,ring) << 16);
                i |= (deref(pos++,ring) << 8);
                i |= (deref(pos++,ring));
                pos += i;
                if((pos-aligned_pos)%4)
                    pos += 4-(pos-aligned_pos)%4;
                --toparse;
                break;
            default:
                ;
        }
    }


    return pos <= (ring[0].len+ring[1].len) ? pos : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x8(%rdi), %rcx
testq %rcx, %rcx
je 0x72ee
movq (%rdi), %rdx
cmpb $0x23, (%rdx)
jne 0x741b
movl $0x1, %eax
cmpq $0x1, %rcx
jne 0x731d
movq 0x18(%rdi), %rdx
jmp 0x7308
movq 0x18(%rdi), %rdx
testq %rdx, %rdx
je 0x741b
movq 0x10(%rdi), %rax
cmpb $0x23, (%rax)
jne 0x741b
movl $0x1, %eax
subq %rcx, %rax
cmpq %rdx, %rax
jae 0x741b
movq 0x10(%rdi), %rdx
cmpb $0x62, (%rdx,%rax)
jne 0x741b
movl $0x2, %eax
movq %rdi, %rdx
cmpq $0x2, %rcx
ja 0x7346
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x741b
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x75, (%rdx,%rax)
jne 0x741b
movl $0x3, %eax
movq %rdi, %rdx
cmpq $0x3, %rcx
ja 0x7372
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x741b
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x6e, (%rdx,%rax)
jne 0x741b
movl $0x4, %eax
movq %rdi, %rdx
cmpq $0x4, %rcx
ja 0x739e
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x741b
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x64, (%rdx,%rax)
jne 0x741b
movl $0x5, %eax
movq %rdi, %rdx
cmpq $0x5, %rcx
ja 0x73c2
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x741b
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x6c, (%rdx,%rax)
jne 0x741b
movl $0x6, %eax
movq %rdi, %rdx
cmpq $0x6, %rcx
ja 0x73e6
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x741b
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x65, (%rdx,%rax)
jne 0x741b
movl $0x7, %eax
movq %rdi, %rdx
cmpq $0x7, %rcx
ja 0x740e
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x776f
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x0, (%rdx,%rax)
je 0x776f
leaq 0x10(%rdi), %rax
movl $0xfffffffd, %r10d      # imm = 0xFFFFFFFD
xorl %r9d, %r9d
movl %r9d, %edx
movl %r10d, %esi
leal 0x3(%rsi), %r8d
movq %r8, %r10
movq %rdi, %r9
subq %rcx, %r10
jb 0x7449
movq %rax, %r9
movq %r10, %r8
cmpq 0x18(%rdi), %r10
jae 0x745b
movq (%r9), %r11
leal 0x3(%rdx), %r9d
leal 0x1(%rsi), %r10d
cmpb $0x0, (%r11,%r8)
jne 0x7428
xorl %r8d, %r8d
leal 0x4(%rsi), %r10d
movq %r10, %r9
subq %rcx, %r9
jae 0x747c
movq (%rdi), %r9
cmpb $0x0, (%r9,%r10)
jne 0x74a4
cmpl $0x3, %r8d
jb 0x749a
jmp 0x74a4
cmpq 0x18(%rdi), %r9
jae 0x7494
movq (%rax), %r10
cmpb $0x0, (%r10,%r9)
jne 0x74ac
cmpl $0x3, %r8d
jb 0x749a
jmp 0x74ac
cmpl $0x2, %r8d
ja 0x74ac
incl %r8d
addb $0x3, %dl
incl %esi
jmp 0x745e
movq %rdi, %r8
movq %r10, %r9
jmp 0x74b9
movq %rax, %r8
cmpq 0x18(%rdi), %r9
jae 0x7578
movq (%r8), %r8
cmpb $0x2c, (%r8,%r9)
jne 0x7578
leal 0x9(%rsi), %ebx
leal 0x5(%rsi), %r10d
movb $0x1, %r15b
movl %r10d, %r9d
movl %ebx, %r8d
movl %r15d, %r11d
movl %r9d, %r9d
movq %r9, %r15
movq %rdi, %rbx
movq %r9, %r14
subq %rcx, %r15
jb 0x74f7
movq %rax, %rbx
movq %r15, %r14
cmpq 0x18(%rdi), %r15
jae 0x750c
movq (%rbx), %r12
leal 0x1(%r8), %ebx
leal 0x1(%r11), %r15d
incl %r9d
cmpb $0x0, (%r12,%r14)
jne 0x74d4
movzbl %r11b, %r9d
andl $0x3, %r9d
subl %r9d, %r8d
xorl %r9d, %r9d
movabsq $0x708d70002000, %r11   # imm = 0x708D70002000
movl $0xa04109, %ebx         # imm = 0xA04109
movl %r10d, %r10d
movq %r10, %r14
subq %rcx, %r14
jae 0x753d
movq (%rdi), %r14
movb (%r14,%r10), %r14b
jmp 0x754a
cmpq 0x18(%rdi), %r14
jae 0x757f
movq (%rax), %r15
movb (%r15,%r14), %r14b
testb %r14b, %r14b
je 0x757f
movzbl %r14b, %r15d
addl $-0x46, %r15d
cmpl $0x2e, %r15d
ja 0x756d
movl $0x1, %r14d
btq %r15, %r11
jb 0x7570
btq %r15, %rbx
xorl %r14d, %r14d
addl %r14d, %r9d
incl %r10d
jmp 0x7529
xorl %eax, %eax
jmp 0x7760
testl %r9d, %r9d
je 0x7750
leal 0x5(%rsi), %r10d
negl %esi
leaq 0x24e7(%rip), %r15      # 0x9a7c
movl %r10d, %r10d
movq %r10, %r14
movq %rdi, %r11
movq %r10, %rbx
subq %rcx, %r14
jb 0x75b6
movq %rax, %r11
movq %r14, %rbx
cmpq 0x18(%rdi), %r14
jae 0x777f
movq (%r11), %r11
movzbl (%r11,%rbx), %r11d
leal -0x62(%r11), %ebx
cmpl $0x12, %ebx
ja 0x75e3
movslq (%r15,%rbx,4), %r11
addq %r15, %r11
jmpq *%r11
addl $0x4, %r8d
jmp 0x75db
addl $0x8, %r8d
decl %r9d
jmp 0x7744
cmpl $0x53, %r11d
je 0x75f7
testl %r11d, %r11d
jne 0x7744
jmp 0x777f
leal 0x5(%r8), %r15d
leal (%rdx,%r8), %r13d
incl %r8d
movl %r15d, %ebx
movl %r13d, %r14d
movl %r8d, %r8d
movq %r8, %r11
movq %rdi, %r15
movq %r8, %r12
subq %rcx, %r11
jb 0x7625
movq %rax, %r15
movq %r11, %r12
cmpq 0x18(%rdi), %r11
jae 0x763a
movq (%r15), %r11
leal 0x1(%rbx), %r15d
leal 0x1(%r14), %r13d
incl %r8d
cmpb $0x0, (%r11,%r12)
jne 0x7602
movzbl %r14b, %r8d
andl $0x3, %r8d
subl %r8d, %ebx
decl %r9d
movl %ebx, %r8d
jmp 0x773d
movl %r8d, %r14d
movq %r14, %r11
movq %rdi, %r15
subq %rcx, %r11
jb 0x766c
xorl %ebx, %ebx
movq %rax, %r15
movq %r11, %r14
cmpq 0x18(%rdi), %r11
jae 0x7677
movq (%r15), %r11
movzbl (%r11,%r14), %ebx
shll $0x18, %ebx
movl %ebx, -0x2c(%rbp)
leal 0x1(%r8), %r11d
movl %r11d, %r15d
movq %r15, %r11
movq %rdi, %r12
subq %rcx, %r11
jb 0x769b
xorl %r14d, %r14d
movq %rax, %r12
movq %r11, %r15
cmpq 0x18(%rdi), %r11
jae 0x76a8
movq (%r12), %r11
movzbl (%r11,%r15), %r14d
shll $0x10, %r14d
leal 0x2(%r8), %r11d
movl %r11d, %r12d
movq %r12, %r11
movq %rdi, %r13
subq %rcx, %r11
jb 0x76c9
xorl %r15d, %r15d
movq %rax, %r13
movq %r11, %r12
cmpq 0x18(%rdi), %r11
jae 0x76d6
movq (%r13), %r11
movzbl (%r11,%r12), %r15d
shll $0x8, %r15d
leal 0x3(%r8), %r11d
movl %r11d, %ebx
movq %rbx, %r13
movq %rdi, %r11
subq %rcx, %r13
jb 0x76f7
xorl %r12d, %r12d
movq %rax, %r11
movq %r13, %rbx
cmpq 0x18(%rdi), %r13
jae 0x76ff
movq (%r11), %r11
movzbl (%r11,%rbx), %r12d
movl %r14d, %r11d
movl -0x2c(%rbp), %r13d
orl %r13d, %r11d
orl %r15d, %r11d
leal 0x4(%r8), %ebx
orl %r12d, %r11d
addl %ebx, %r11d
addl %r12d, %r8d
addl %r13d, %r14d
addl %r8d, %r14d
addl %esi, %r15d
addl %r14d, %r15d
andl $0x3, %r15d
movl %r11d, %r8d
subl %r15d, %r8d
addl $0x4, %r8d
testl %r15d, %r15d
cmovel %r11d, %r8d
decl %r9d
leaq 0x2338(%rip), %r15      # 0x9a7c
incl %r10d
testl %r9d, %r9d
jne 0x7595
movl %r8d, %edx
addq 0x18(%rdi), %rcx
xorl %eax, %eax
cmpq %rdx, %rcx
cmovaeq %rdx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x779e
leaq 0x23da(%rip), %rdi      # 0x9b60
leaq 0x2347(%rip), %rsi      # 0x9ad4
leaq 0x2427(%rip), %rcx      # 0x9bbb
movl $0x245, %edx            # imm = 0x245
callq 0x2130