// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdi, %r15
xorl %edi, %edi
movq %r15, %rsi
callq 0x6fa3
cmpb $0x23, %al
jne 0x6cd6
pushq $0x1
popq %rdi
movq %r15, %rsi
callq 0x6fa3
cmpb $0x62, %al
jne 0x6cd6
pushq $0x2
popq %rdi
movq %r15, %rsi
callq 0x6fa3
cmpb $0x75, %al
jne 0x6cd6
pushq $0x3
popq %rdi
movq %r15, %rsi
callq 0x6fa3
cmpb $0x6e, %al
jne 0x6cd6
pushq $0x4
popq %rdi
movq %r15, %rsi
callq 0x6fa3
cmpb $0x64, %al
jne 0x6cd6
pushq $0x5
popq %rdi
movq %r15, %rsi
callq 0x6fa3
cmpb $0x6c, %al
jne 0x6cd6
pushq $0x6
popq %rdi
movq %r15, %rsi
callq 0x6fa3
cmpb $0x65, %al
jne 0x6cd6
pushq $0x7
popq %rdi
movq %r15, %rsi
callq 0x6fa3
testb %al, %al
je 0x6f1b
pushq $0x3
popq %rbx
leal -0x3(%rbx), %edi
movq %r15, %rsi
callq 0x6fa3
incl %ebx
testb %al, %al
jne 0x6cd9
leal -0x4(%rbx), %r12d
pushq $0x4
popq %r14
subl $0x1, %r14d
jb 0x6d0c
incl %r12d
movl %r12d, %edi
movq %r15, %rsi
callq 0x6fa3
testb %al, %al
je 0x6cf2
jmp 0x6d0f
movl %ebx, %r12d
movl %r12d, %edi
movq %r15, %rsi
callq 0x6fa3
xorl %r14d, %r14d
cmpb $0x2c, %al
jne 0x6f09
leal 0x4(%r12), %ebx
movq %r12, -0x50(%rbp)
leal 0x1(%r12), %r13d
leal (%r14,%r13), %edi
movq %r15, %rsi
callq 0x6fa3
incl %ebx
incl %r14d
testb %al, %al
jne 0x6d33
movq %r14, -0x30(%rbp)
movq %rbx, -0x38(%rbp)
movq %r15, %r12
xorl %r15d, %r15d
pushq $0x1
popq %r14
movabsq $0x708d70002000, %rbx   # imm = 0x708D70002000
movl %r13d, %edi
movq %r12, %rsi
callq 0x6fa3
movzbl %al, %eax
leal -0x46(%rax), %ecx
cmpl $0x2e, %ecx
ja 0x6d98
btq %rcx, %rbx
movl %r14d, %edx
jb 0x6d90
movl $0xa04109, %edx         # imm = 0xA04109
btq %rcx, %rdx
jae 0x6d98
xorl %edx, %edx
addl %edx, %r15d
incl %r13d
jmp 0x6d64
testl %eax, %eax
jne 0x6d8e
movzbl -0x30(%rbp), %eax
andl $0x3, %eax
movq -0x38(%rbp), %rbx
subl %eax, %ebx
movq -0x50(%rbp), %rax
movl %eax, %ecx
negb %cl
movq %rcx, -0x58(%rbp)
leaq 0x1c78(%rip), %r14      # 0x8a34
movl %eax, %r13d
movq %r12, -0x60(%rbp)
testl %r15d, %r15d
je 0x6ef2
incl %r13d
movl %r13d, %edi
movq %r12, %rsi
callq 0x6fa3
movzbl %al, %eax
leal -0x62(%rax), %ecx
cmpl $0x12, %ecx
ja 0x6df6
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
addl $0x4, %ebx
jmp 0x6eea
cmpl $0x53, %eax
je 0x6e0c
testl %eax, %eax
jne 0x6dc3
jmp 0x6f84
addl $0x8, %ebx
jmp 0x6eea
movl %r13d, -0x30(%rbp)
leal 0x4(%rbx), %r13d
movq -0x58(%rbp), %rax
leal (%rax,%rbx), %r14d
incl %ebx
movl %ebx, %edi
movq -0x60(%rbp), %rsi
callq 0x6fa3
incl %r13d
incb %r14b
incl %ebx
testb %al, %al
jne 0x6e1e
movzbl %r14b, %eax
andl $0x3, %eax
subl %eax, %r13d
movl %r13d, %ebx
leaq 0x1beb(%rip), %r14      # 0x8a34
movl -0x30(%rbp), %r13d
jmp 0x6eea
leal 0x1(%rbx), %eax
movl %eax, -0x30(%rbp)
movl %ebx, %edi
movq %r12, %rsi
callq 0x6fa3
movq %rbx, %rcx
movq %rbx, -0x38(%rbp)
movzbl %al, %ebx
shll $0x18, %ebx
leal 0x2(%rcx), %eax
movl %eax, -0x40(%rbp)
movl -0x30(%rbp), %edi
movq %r12, %rsi
callq 0x6fa3
movzbl %al, %eax
shll $0x10, %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
addl $0x3, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %edi
movq %r12, %rsi
callq 0x6fa3
movl %r13d, -0x30(%rbp)
movzbl %al, %r13d
shll $0x8, %r13d
movl -0x3c(%rbp), %edi
movq %r12, %rsi
leaq 0x1b7d(%rip), %r14      # 0x8a34
callq 0x6fa3
movzbl %al, %eax
addl -0x38(%rbp), %ebx
addl -0x44(%rbp), %ebx
movl %ebx, %ecx
addl %eax, %ecx
addl %ebx, %eax
addl $0x4, %eax
addl %r13d, %ecx
addl $0x4, %ecx
movl -0x30(%rbp), %r13d
subl -0x50(%rbp), %eax
andl $0x3, %eax
movl %ecx, %ebx
subl %eax, %ebx
addl $0x4, %ebx
testl %eax, %eax
cmovel %ecx, %ebx
decl %r15d
jmp 0x6dc3
movq %r12, %r15
movl %ebx, %eax
movq 0x18(%r15), %rcx
addq 0x8(%r15), %rcx
xorl %r14d, %r14d
cmpq %rax, %rcx
cmovaeq %rax, %r14
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rax
movl %eax, %r12d
movl %eax, %edi
movq %r15, %rsi
callq 0x6fa3
movzbl %al, %ebx
shll $0x18, %ebx
leal 0x1(%r12), %edi
movq %r15, %rsi
callq 0x6fa3
movzbl %al, %r14d
shll $0x10, %r14d
orl %ebx, %r14d
leal 0x2(%r12), %edi
movq %r15, %rsi
callq 0x6fa3
movzbl %al, %ebx
shll $0x8, %ebx
orl %r14d, %ebx
leal 0x3(%r12), %edi
movq %r15, %rsi
callq 0x6fa3
movzbl %al, %ecx
orl %ebx, %ecx
movq %r12, %rbx
leal (%r12,%rcx), %eax
addl $0x4, %eax
testl %ecx, %ecx
jne 0x6f1e
jmp 0x6ef5
leaq 0x1b8d(%rip), %rdi      # 0x8b18
leaq 0x1afa(%rip), %rsi      # 0x8a8c
leaq 0x1bda(%rip), %rcx      # 0x8b73
movl $0x245, %edx            # imm = 0x245
callq 0x2130