// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rsi
xorl %edi, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x23, %eax
jne 0xa0e7
movq -0x10(%rbp), %rsi
movl $0x1, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x62, %eax
jne 0xa0e7
movq -0x10(%rbp), %rsi
movl $0x2, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x75, %eax
jne 0xa0e7
movq -0x10(%rbp), %rsi
movl $0x3, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x6e, %eax
jne 0xa0e7
movq -0x10(%rbp), %rsi
movl $0x4, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x64, %eax
jne 0xa0e7
movq -0x10(%rbp), %rsi
movl $0x5, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x6c, %eax
jne 0xa0e7
movq -0x10(%rbp), %rsi
movl $0x6, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x65, %eax
jne 0xa0e7
movq -0x10(%rbp), %rsi
movl $0x7, %edi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xa0e7
movq -0x10(%rbp), %rdi
callq 0xa430
movq %rax, -0x8(%rbp)
jmp 0xa3b6
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %edi
movl %edi, %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
cmpb $0x0, %al
je 0xa108
jmp 0xa0ee
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x18(%rbp)
jge 0xa143
movl -0x14(%rbp), %edi
addl $0x1, %edi
movl %edi, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
cmpb $0x0, %al
je 0xa136
jmp 0xa143
jmp 0xa138
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xa118
movl -0x14(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0xa3c0
movzbl %al, %eax
cmpl $0x2c, %eax
je 0xa164
movq $0x0, -0x8(%rbp)
jmp 0xa3b6
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x14(%rbp), %edi
addl $0x1, %edi
movl %edi, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
cmpb $0x0, %al
je 0xa18b
jmp 0xa173
movl -0x14(%rbp), %ecx
subl -0x1c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %edi
addl $0x1, %edi
movl %edi, -0x28(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
cmpb $0x0, %al
je 0xa1e3
movl -0x28(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0xa3c0
movsbl %al, %edi
callq 0xa510
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0xa1b1
jmp 0xa1e5
cmpl $0x0, -0x24(%rbp)
je 0xa386
movl -0x20(%rbp), %edi
movl %edi, %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
movb %al, -0x29(%rbp)
cmpb $0x0, -0x29(%rbp)
je 0xa20e
jmp 0xa22d
leaq 0x2b03(%rip), %rdi      # 0xcd18
leaq 0x2a70(%rip), %rsi      # 0xcc8c
movl $0x245, %edx            # imm = 0x245
leaq 0x2b4b(%rip), %rcx      # 0xcd73
callq 0x2120
movsbl -0x29(%rbp), %eax
addl $-0x53, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x21, %eax
ja 0xa37f
movq -0x38(%rbp), %rax
leaq 0x2992(%rip), %rcx      # 0xcbe0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x14(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa381
movl -0x14(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa381
jmp 0xa287
movl -0x14(%rbp), %edi
addl $0x1, %edi
movl %edi, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
cmpb $0x0, %al
je 0xa29f
jmp 0xa287
movl -0x14(%rbp), %ecx
subl -0x1c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa381
movl $0x0, -0x30(%rbp)
movl -0x14(%rbp), %edi
movl %edi, %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
movzbl %al, %eax
shll $0x18, %eax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x14(%rbp), %edi
movl %edi, %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
movzbl %al, %eax
shll $0x10, %eax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x14(%rbp), %edi
movl %edi, %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
movzbl %al, %eax
shll $0x8, %eax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x14(%rbp), %edi
movl %edi, %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rsi
callq 0xa3c0
movzbl %al, %eax
orl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
subl -0x1c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0xa374
movl -0x14(%rbp), %ecx
subl -0x1c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa381
jmp 0xa381
jmp 0xa1e5
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
addq 0x18(%rdx), %rcx
cmpq %rcx, %rax
ja 0xa3a6
movl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0xa3ad
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa3ad
movl -0x3c(%rbp), %eax
movl %eax, %eax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq