// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq 0x8(%rdi), %rcx
movq %rdi, %rax
testq %rcx, %rcx
jne 0x736c
cmpq $0x0, 0x18(%rdi)
je 0x7498
leaq 0x10(%rdi), %rax
movq (%rax), %rax
cmpb $0x23, (%rax)
jne 0x7498
movl $0x1, %eax
movq %rdi, %rdx
cmpq $0x1, %rcx
ja 0x7397
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x7498
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x62, (%rdx,%rax)
jne 0x7498
movl $0x2, %eax
movq %rdi, %rdx
cmpq $0x2, %rcx
ja 0x73c3
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x7498
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x75, (%rdx,%rax)
jne 0x7498
movl $0x3, %eax
movq %rdi, %rdx
cmpq $0x3, %rcx
ja 0x73ef
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x7498
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x6e, (%rdx,%rax)
jne 0x7498
movl $0x4, %eax
movq %rdi, %rdx
cmpq $0x4, %rcx
ja 0x741b
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x7498
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x64, (%rdx,%rax)
jne 0x7498
movl $0x5, %eax
movq %rdi, %rdx
cmpq $0x5, %rcx
ja 0x743f
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x7498
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x6c, (%rdx,%rax)
jne 0x7498
movl $0x6, %eax
movq %rdi, %rdx
cmpq $0x6, %rcx
ja 0x7463
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x7498
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x65, (%rdx,%rax)
jne 0x7498
movl $0x7, %eax
movq %rdi, %rdx
cmpq $0x7, %rcx
ja 0x748b
subq %rcx, %rax
cmpq 0x18(%rdi), %rax
jae 0x7802
leaq 0x10(%rdi), %rdx
movq (%rdx), %rdx
cmpb $0x0, (%rdx,%rax)
je 0x7802
leaq 0x10(%rdi), %rax
movl $0x3, %edx
leal -0x3(%rdx), %esi
movq %rsi, %r10
movq %rdi, %r8
subq %rcx, %r10
jb 0x74be
movb $0x1, %r9b
movq %rax, %r8
movq %r10, %rsi
cmpq 0x18(%rdi), %r10
jae 0x74ca
movq (%r8), %r8
cmpb $0x0, (%r8,%rsi)
sete %r9b
incl %edx
testb %r9b, %r9b
je 0x74a1
leaq 0x10(%rdi), %rsi
leal -0x1(%rdx), %r8d
leal -0x4(%rdx), %r10d
movl $0x4, %r9d
movl %r10d, %eax
leal 0x1(%rax), %r10d
movq %r10, %r14
movq %rdi, %r11
movq %r10, %rbx
subq %rcx, %r14
jb 0x7504
movq %rsi, %r11
movq %r14, %rbx
cmpq 0x18(%rdi), %r14
jae 0x750e
movq (%r11), %r11
cmpb $0x0, (%r11,%rbx)
jne 0x7518
decl %r9d
jne 0x74e3
movl %r8d, %eax
jmp 0x751b
leal 0x1(%rax), %edx
movl %edx, %r8d
movq %r8, %rdx
movq %rdi, %rsi
movq %r8, -0x30(%rbp)
subq %rcx, %rdx
jb 0x753e
cmpq 0x18(%rdi), %rdx
jae 0x762b
leaq 0x10(%rdi), %rsi
movq %rdx, %r8
movq (%rsi), %rdx
cmpb $0x2c, (%rdx,%r8)
jne 0x762b
leaq 0x10(%rdi), %r8
movq -0x30(%rbp), %rdx
leal 0x5(%rdx), %r11d
movl %edx, %r14d
subb %al, %r14b
leal 0x1(%rdx), %r10d
movl %r11d, %esi
movl %r14d, %r9d
movl %r10d, %r10d
movq %r10, %rdx
movq %rdi, %r11
movq %r10, %rbx
subq %rcx, %rdx
jb 0x7585
movq %r8, %r11
movq %rdx, %rbx
cmpq 0x18(%rdi), %rdx
jae 0x7599
movq (%r11), %rdx
leal 0x1(%rsi), %r11d
leal 0x1(%r9), %r14d
incl %r10d
cmpb $0x0, (%rdx,%rbx)
jne 0x7562
leaq 0x10(%rdi), %r10
movq -0x30(%rbp), %rdx
leal 0x1(%rdx), %r11d
xorl %r8d, %r8d
movabsq $0x708d70002000, %rbx   # imm = 0x708D70002000
movl $0xa04109, %r14d        # imm = 0xA04109
movl %r11d, %r11d
movq %r11, %r12
movq %rdi, %rdx
movq %r11, %r15
subq %rcx, %r12
jb 0x75d5
movq %r10, %rdx
movq %r12, %r15
cmpq 0x18(%rdi), %r12
jae 0x7632
movq (%rdx), %rdx
cmpb $0x0, (%rdx,%r15)
je 0x7632
movq %r11, %r15
movq %rdi, %rdx
movq %r11, %r12
subq %rcx, %r15
jb 0x75f9
movq %r10, %rdx
movq %r15, %r12
cmpq 0x18(%rdi), %r15
jae 0x7602
movq (%rdx), %rdx
movb (%rdx,%r12), %dl
jmp 0x7604
xorl %edx, %edx
movzbl %dl, %r15d
addl $-0x46, %r15d
cmpl $0x2e, %r15d
ja 0x7621
movl $0x1, %edx
btq %r15, %rbx
jb 0x7623
btq %r15, %r14
xorl %edx, %edx
addl %edx, %r8d
incl %r11d
jmp 0x75b8
xorl %eax, %eax
jmp 0x77f3
movzbl %r9b, %edx
andl $0x3, %edx
subl %edx, %esi
testl %r8d, %r8d
je 0x77e4
leal 0x2(%rax), %r9d
leaq 0x10(%rdi), %r10
negb %al
leaq 0x2427(%rip), %r11      # 0x9a7c
movl %r9d, %r9d
movq %r9, %rbx
movq %rdi, %rdx
movq %r9, %r14
subq %rcx, %rbx
jb 0x7672
movq %r10, %rdx
movq %rbx, %r14
cmpq 0x18(%rdi), %rbx
jae 0x767b
movq (%rdx), %rdx
movb (%rdx,%r14), %dl
jmp 0x767d
xorl %edx, %edx
movzbl %dl, %edx
leal -0x62(%rdx), %ebx
cmpl $0x12, %ebx
ja 0x76a1
movslq (%r11,%rbx,4), %rdx
addq %r11, %rdx
jmpq *%rdx
addl $0x4, %esi
jmp 0x77d5
addl $0x8, %esi
jmp 0x77d5
cmpl $0x53, %edx
je 0x76b3
testl %edx, %edx
jne 0x77d8
jmp 0x7812
leal 0x5(%rsi), %r15d
leal (%rax,%rsi), %r13d
incl %esi
movl %r15d, %ebx
movl %r13d, %r14d
movl %esi, %esi
movq %rsi, %rdx
movq %rdi, %r15
movq %rsi, %r12
subq %rcx, %rdx
jb 0x76df
movq %r10, %r15
movq %rdx, %r12
cmpq 0x18(%rdi), %rdx
jae 0x76f3
movq (%r15), %rdx
leal 0x1(%rbx), %r15d
leal 0x1(%r14), %r13d
incl %esi
cmpb $0x0, (%rdx,%r12)
jne 0x76bd
movzbl %r14b, %edx
andl $0x3, %edx
subl %edx, %ebx
decl %r8d
movl %ebx, %esi
jmp 0x77d8
movl %esi, %r14d
movq %r14, %rdx
movq %rdi, %r15
subq %rcx, %rdx
jb 0x7722
xorl %ebx, %ebx
movq %r10, %r15
movq %rdx, %r14
cmpq 0x18(%rdi), %rdx
jae 0x772d
movq (%r15), %rdx
movzbl (%rdx,%r14), %ebx
shll $0x18, %ebx
leal 0x1(%rsi), %edx
movl %edx, %r15d
movq %r15, %rdx
movq %rdi, %r12
subq %rcx, %rdx
jb 0x774d
xorl %r14d, %r14d
movq %r10, %r12
movq %rdx, %r15
cmpq 0x18(%rdi), %rdx
jae 0x775a
movq (%r12), %rdx
movzbl (%rdx,%r15), %r14d
shll $0x10, %r14d
movl %ebx, -0x34(%rbp)
leal 0x2(%rsi), %edx
movl %edx, %r12d
movq %r12, %rdx
movq %rdi, %r13
subq %rcx, %rdx
jb 0x777d
xorl %r15d, %r15d
movq %r10, %r13
movq %rdx, %r12
cmpq 0x18(%rdi), %rdx
jae 0x778a
movq (%r13), %rdx
movzbl (%rdx,%r12), %r15d
shll $0x8, %r15d
leal 0x3(%rsi), %edx
movl %edx, %ebx
movq %rbx, %r13
movq %rdi, %rdx
subq %rcx, %r13
jb 0x77a9
xorl %r12d, %r12d
movq %r10, %rdx
movq %r13, %rbx
cmpq 0x18(%rdi), %r13
jae 0x77b1
movq (%rdx), %rdx
movzbl (%rdx,%rbx), %r12d
addl -0x34(%rbp), %esi
addl %r15d, %r14d
addl %esi, %r14d
leal (%r12,%r14), %edx
addl $0x4, %edx
movl %edx, %ebx
subl -0x30(%rbp), %ebx
andl $0x3, %ebx
movl %edx, %esi
subl %ebx, %esi
addl $0x4, %esi
testl %ebx, %ebx
cmovel %edx, %esi
decl %r8d
incl %r9d
testl %r8d, %r8d
jne 0x7655
movl %esi, %edx
addq 0x18(%rdi), %rcx
xorl %eax, %eax
cmpq %rdx, %rcx
cmovaeq %rdx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7831
leaq 0x2347(%rip), %rdi      # 0x9b60
leaq 0x22b4(%rip), %rsi      # 0x9ad4
leaq 0x2394(%rip), %rcx      # 0x9bbb
movl $0x245, %edx            # imm = 0x245
callq 0x2130