// File: DoubleString[P]RtConverter/src/Rtklib/skytraq.cpp
// Function: bamboo::gen_stq(char const*, unsigned char*)
extern int gen_stq(const char *msg, unsigned char *buff)
{
    const char *hz[]={"1Hz","2Hz","4Hz","5Hz","10Hz","20Hz",""};
    unsigned char *q=buff;
    char mbuff[1024],*args[32],*p;
    int i,n,narg=0;
    
    trace(4,"gen_stq: msg=%s\n",msg);
    
    strcpy(mbuff,msg);
    for (p=strtok(mbuff," ");p&&narg<32;p=strtok(NULL," ")) {
        args[narg++]=p;
    }
    *q++=STQSYNC1;
    *q++=STQSYNC2;
    if (!strcmp(args[0],"RESTART")) {
        *q++=0;
        *q++=15;
        *q++=ID_RESTART;
        *q++=narg>2?(unsigned char)atoi(args[1]):0;
        for (i=1;i<15;i++) *q++=0; /* set all 0 */
    }
    else if (!strcmp(args[0],"CFG-SERI")) {
        *q++=0;
        *q++=4;
        *q++=ID_CFGSERI;
        for (i=1;i<4;i++) *q++=narg>i+1?(unsigned char)atoi(args[i]):0;
    }
    else if (!strcmp(args[0],"CFG-FMT")) {
        *q++=0;
        *q++=3;
        *q++=ID_CFGFMT;
        for (i=1;i<3;i++) *q++=narg>i+1?(unsigned char)atoi(args[i]):0;
    }
    else if (!strcmp(args[0],"CFG-RATE")) {
        *q++=0;
        *q++=8;
        *q++=ID_CFGRATE;
        if (narg>2) {
            for (i=0;*hz[i];i++) if (!strcmp(args[1],hz[i])) break;
            if (*hz[i]) *q++=i; else *q++=(unsigned char)atoi(args[1]);
        }
        else *q++=0;
        for (i=2;i<8;i++) *q++=narg>i+1?(unsigned char)atoi(args[i]):0;
    }
    else if (!strcmp(args[0],"CFG-BIN")) {
        *q++=0;
        *q++=9; /* F/W 1.4.32 */
        *q++=ID_CFGBIN;
        if (narg>2) {
            for (i=0;*hz[i];i++) if (!strcmp(args[1],hz[i])) break;
            if (*hz[i]) *q++=i; else *q++=(unsigned char)atoi(args[1]);
        }
        else *q++=0;
        for (i=2;i<9;i++) *q++=narg>i+1?(unsigned char)atoi(args[i]):0;
    }
    else if (!strcmp(args[0],"GET-GLOEPH")) {
        *q++=0;
        *q++=2;
        *q++=ID_GETGLOEPH;
        *q++=narg>=2?(unsigned char)atoi(args[1]):0;
    }
    else return 0;
    
    n=(int)(q-buff);
    *q++=checksum(buff,n+3);
    *q++=0x0D;
    *q=0x0A;
    
    trace(4,"gen_stq: buff=\n"); traceb(4,buff,n+3);
    return n+3;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x590, %rsp            # imm = 0x590
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x50(%rbp), %rdi
leaq 0x5c652(%rip), %rsi     # 0xf6930
movl $0x38, %edx
callq 0x9610
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x574(%rbp)
movq -0x10(%rbp), %rdx
movl $0x4, %edi
leaq 0x2e075(%rip), %rsi     # 0xc837f
movb $0x0, %al
callq 0x8b980
leaq -0x460(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x96f0
leaq -0x460(%rbp), %rdi
leaq 0x2de54(%rip), %rsi     # 0xc8183
callq 0x9b70
movq %rax, -0x568(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x568(%rbp)
movb %al, -0x575(%rbp)
je 0x9a35d
cmpl $0x20, -0x574(%rbp)
setl %al
movb %al, -0x575(%rbp)
movb -0x575(%rbp), %al
testb $0x1, %al
jne 0x9a369
jmp 0x9a3a4
movq -0x568(%rbp), %rcx
movl -0x574(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x574(%rbp)
cltq
movq %rcx, -0x560(%rbp,%rax,8)
xorl %eax, %eax
movl %eax, %edi
leaq 0x2dded(%rip), %rsi     # 0xc8183
callq 0x9b70
movq %rax, -0x568(%rbp)
jmp 0x9a33b
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $-0x60, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $-0x5f, (%rax)
movq -0x560(%rbp), %rdi
leaq 0x2dfba(%rip), %rsi     # 0xc8390
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a498
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0xf, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x1, (%rax)
cmpl $0x2, -0x574(%rbp)
jle 0x9a43a
movq -0x558(%rbp), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x57c(%rbp)
jmp 0x9a444
xorl %eax, %eax
movl %eax, -0x57c(%rbp)
jmp 0x9a444
movl -0x57c(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movl $0x1, -0x56c(%rbp)
cmpl $0xf, -0x56c(%rbp)
jge 0x9a493
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x9a467
jmp 0x9a9f3
movq -0x560(%rbp), %rdi
leaq 0x2def2(%rip), %rsi     # 0xc8398
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a568
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x4, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x5, (%rax)
movl $0x1, -0x56c(%rbp)
cmpl $0x4, -0x56c(%rbp)
jge 0x9a563
movl -0x574(%rbp), %eax
movl -0x56c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x9a52f
movslq -0x56c(%rbp), %rax
movq -0x560(%rbp,%rax,8), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x580(%rbp)
jmp 0x9a539
xorl %eax, %eax
movl %eax, -0x580(%rbp)
jmp 0x9a539
movl -0x580(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x9a4f4
jmp 0x9a9f1
movq -0x560(%rbp), %rdi
leaq 0x2de2b(%rip), %rsi     # 0xc83a1
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a638
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x3, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x9, (%rax)
movl $0x1, -0x56c(%rbp)
cmpl $0x3, -0x56c(%rbp)
jge 0x9a633
movl -0x574(%rbp), %eax
movl -0x56c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x9a5ff
movslq -0x56c(%rbp), %rax
movq -0x560(%rbp,%rax,8), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x584(%rbp)
jmp 0x9a609
xorl %eax, %eax
movl %eax, -0x584(%rbp)
jmp 0x9a609
movl -0x584(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x9a5c4
jmp 0x9a9ef
movq -0x560(%rbp), %rdi
leaq 0x2dd63(%rip), %rsi     # 0xc83a9
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a7c1
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x8, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x12, (%rax)
cmpl $0x2, -0x574(%rbp)
jle 0x9a731
movl $0x0, -0x56c(%rbp)
movslq -0x56c(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rax
cmpb $0x0, (%rax)
je 0x9a6e4
movq -0x558(%rbp), %rdi
movslq -0x56c(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rsi
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a6d1
jmp 0x9a6e4
jmp 0x9a6d3
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x9a6a1
movslq -0x56c(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rax
cmpb $0x0, (%rax)
je 0x9a710
movl -0x56c(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
jmp 0x9a72f
movq -0x558(%rbp), %rdi
callq 0x9b60
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
jmp 0x9a743
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movl $0x2, -0x56c(%rbp)
cmpl $0x8, -0x56c(%rbp)
jge 0x9a7bc
movl -0x574(%rbp), %eax
movl -0x56c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x9a788
movslq -0x56c(%rbp), %rax
movq -0x560(%rbp,%rax,8), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x588(%rbp)
jmp 0x9a792
xorl %eax, %eax
movl %eax, -0x588(%rbp)
jmp 0x9a792
movl -0x588(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x9a74d
jmp 0x9a9ed
movq -0x560(%rbp), %rdi
leaq 0x2dbe3(%rip), %rsi     # 0xc83b2
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a94a
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x9, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x1e, (%rax)
cmpl $0x2, -0x574(%rbp)
jle 0x9a8ba
movl $0x0, -0x56c(%rbp)
movslq -0x56c(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rax
cmpb $0x0, (%rax)
je 0x9a86d
movq -0x558(%rbp), %rdi
movslq -0x56c(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rsi
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a85a
jmp 0x9a86d
jmp 0x9a85c
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x9a82a
movslq -0x56c(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rax
cmpb $0x0, (%rax)
je 0x9a899
movl -0x56c(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
jmp 0x9a8b8
movq -0x558(%rbp), %rdi
callq 0x9b60
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
jmp 0x9a8cc
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movl $0x2, -0x56c(%rbp)
cmpl $0x9, -0x56c(%rbp)
jge 0x9a945
movl -0x574(%rbp), %eax
movl -0x56c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x9a911
movslq -0x56c(%rbp), %rax
movq -0x560(%rbp,%rax,8), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x58c(%rbp)
jmp 0x9a91b
xorl %eax, %eax
movl %eax, -0x58c(%rbp)
jmp 0x9a91b
movl -0x58c(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movl -0x56c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x56c(%rbp)
jmp 0x9a8d6
jmp 0x9a9eb
movq -0x560(%rbp), %rdi
leaq 0x2da62(%rip), %rsi     # 0xc83ba
callq 0x9a60
cmpl $0x0, %eax
jne 0x9a9dd
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x2, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x5b, (%rax)
cmpl $0x2, -0x574(%rbp)
jl 0x9a9b8
movq -0x558(%rbp), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x590(%rbp)
jmp 0x9a9c2
xorl %eax, %eax
movl %eax, -0x590(%rbp)
jmp 0x9a9c2
movl -0x590(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
jmp 0x9a9e9
movl $0x0, -0x4(%rbp)
jmp 0x9aa78
jmp 0x9a9eb
jmp 0x9a9ed
jmp 0x9a9ef
jmp 0x9a9f1
jmp 0x9a9f3
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x570(%rbp)
movq -0x18(%rbp), %rdi
movl -0x570(%rbp), %esi
addl $0x3, %esi
callq 0x9aa90
movb %al, %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0xd, (%rax)
movq -0x58(%rbp), %rax
movb $0xa, (%rax)
movl $0x4, %edi
leaq 0x2d977(%rip), %rsi     # 0xc83c5
movb $0x0, %al
callq 0x8b980
movq -0x18(%rbp), %rsi
movl -0x570(%rbp), %edx
addl $0x3, %edx
movl $0x4, %edi
callq 0x95900
movl -0x570(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x590, %rsp            # imm = 0x590
popq %rbp
retq
nopw %cs:(%rax,%rax)