// File: /workspace/github_c_makefile_star2_O0/mruby-zest[P]osc-bridge/rtosc/rtosc.c
// Function: rtosc_amessage
size_t rtosc_amessage(char              *buffer,
                      size_t             len,
                      const char        *address,
                      const char        *arguments,
                      const rtosc_arg_t *args)
{
    const size_t total_len = vsosc_null(address, arguments, args);

    if(!buffer)
        return total_len;

    //Abort if the message cannot fit
    if(total_len>len) {
        memset(buffer, 0, len);
        return 0;
    }

    memset(buffer, 0, total_len);

    unsigned pos = 0;
    while(*address)
        buffer[pos++] = *address++;

    //get 32 bit alignment
    pos += 4-pos%4;

    buffer[pos++] = ',';

    const char *arg_str = arguments;
    while(*arg_str)
        buffer[pos++] = *arg_str++;

    pos += 4-pos%4;

    unsigned toparse = nreserved(arguments);
    unsigned arg_pos = 0;
    while(toparse)
    {
        char arg = *arguments++;
        assert(arg);
        int32_t i;
        int64_t d;
        const uint8_t *m;
        const char *s;
        const unsigned char *u;
        rtosc_blob_t b;
        switch(arg) {
            case 'h':
            case 't':
            case 'd':
                d = args[arg_pos++].t;
                buffer[pos++] = ((d>>56) & 0xff);
                buffer[pos++] = ((d>>48) & 0xff);
                buffer[pos++] = ((d>>40) & 0xff);
                buffer[pos++] = ((d>>32) & 0xff);
                buffer[pos++] = ((d>>24) & 0xff);
                buffer[pos++] = ((d>>16) & 0xff);
                buffer[pos++] = ((d>>8) & 0xff);
                buffer[pos++] = (d & 0xff);
                --toparse;
                break;
            case 'r':
            case 'f':
            case 'c':
            case 'i':
                i = args[arg_pos++].i;
                buffer[pos++] = ((i>>24) & 0xff);
                buffer[pos++] = ((i>>16) & 0xff);
                buffer[pos++] = ((i>>8) & 0xff);
                buffer[pos++] = (i & 0xff);
                --toparse;
                break;
            case 'm':
                //TODO verify ordering of spec
                m = args[arg_pos++].m;
                buffer[pos++] = m[0];
                buffer[pos++] = m[1];
                buffer[pos++] = m[2];
                buffer[pos++] = m[3];
                --toparse;
                break;
            case 'S':
            case 's':
                s = args[arg_pos++].s;
                while(*s)
                    buffer[pos++] = *s++;
                pos += 4-pos%4;
                --toparse;
                break;
            case 'b':
                b = args[arg_pos++].b;
                i = b.len;
                buffer[pos++] = ((i>>24) & 0xff);
                buffer[pos++] = ((i>>16) & 0xff);
                buffer[pos++] = ((i>>8) & 0xff);
                buffer[pos++] = (i & 0xff);
                u = b.data;
                if(u) {
                    while(i--)
                        buffer[pos++] = *u++;
                }
                else
                    pos += i;
                if(pos%4)
                    pos += 4-pos%4;
                --toparse;
                break;
            default:
                ;
        }
    }

    return pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x9570
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x8fb8
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9557
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jbe 0x8fde
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
xorl %esi, %esi
callq 0x2130
movq $0x0, -0x8(%rbp)
jmp 0x9557
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rdx
xorl %esi, %esi
callq 0x2130
movl $0x0, -0x3c(%rbp)
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0x9024
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
jmp 0x8ff4
movl -0x3c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x3c(%rbp)
movl %ecx, %ecx
movb $0x2c, (%rax,%rcx)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
je 0x9084
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movb (%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
jmp 0x9054
movl -0x3c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x8f20
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x9550
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb (%rax), %al
movb %al, -0x51(%rbp)
cmpb $0x0, -0x51(%rbp)
je 0x90d0
jmp 0x90ef
leaq 0x3c41(%rip), %rdi      # 0xcd18
leaq 0x3bae(%rip), %rsi      # 0xcc8c
movl $0x14a, %edx            # imm = 0x14A
leaq 0x3c32(%rip), %rcx      # 0xcd1c
callq 0x2120
movsbl -0x51(%rbp), %eax
addl $-0x53, %eax
movl %eax, %ecx
movq %rcx, -0x90(%rbp)
subl $0x21, %eax
ja 0x9549
movq -0x90(%rbp), %rax
leaq 0x38aa(%rip), %rcx      # 0xc9c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x30(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x50(%rbp)
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
sarq $0x38, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
sarq $0x30, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
sarq $0x28, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
sarq $0x20, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
sarq $0x18, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
sarq $0x10, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
sarq $0x8, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x60(%rbp), %rax
andq $0xff, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x954b
movq -0x30(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x50(%rbp)
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
sarl $0x18, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x58(%rbp), %eax
sarl $0x10, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x58(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x58(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x954b
movq -0x30(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x50(%rbp)
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movb (%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rax
movb 0x1(%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rax
movb 0x2(%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rax
movb 0x3(%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x954b
movq -0x30(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x50(%rbp)
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpb $0x0, (%rax)
je 0x93f8
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movb (%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
jmp 0x93c8
movl -0x3c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x954b
movq -0x30(%rbp), %rax
movl -0x50(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x50(%rbp)
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
sarl $0x18, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x58(%rbp), %eax
sarl $0x10, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x58(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x58(%rbp), %eax
andl $0xff, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x9517
jmp 0x94de
movl -0x58(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x58(%rbp)
cmpl $0x0, %eax
je 0x9515
movq -0x78(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x78(%rbp)
movb (%rax), %dl
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
jmp 0x94de
jmp 0x9520
movl -0x58(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x953e
movl -0x3c(%rbp), %ecx
andl $0x3, %ecx
movl $0x4, %eax
subl %ecx, %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x954b
jmp 0x954b
jmp 0x90aa
movl -0x3c(%rbp), %eax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)