// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x508, %rsp            # imm = 0x508
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1d01f(%rip), %rsi     # 0x6b60f
xorl %r12d, %r12d
pushq $0x4
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x455bc
leaq -0x530(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x85c0
leaq 0x1cecc(%rip), %r14     # 0x6b4e5
movq %r15, %rdi
movq %r14, %rsi
callq 0x89a0
testq %rax, %rax
je 0x4e63e
cmpq $0x1f, %r12
ja 0x4e63e
movq %rax, -0x130(%rbp,%r12,8)
incq %r12
xorl %edi, %edi
jmp 0x4e61c
movw $0xa1a0, (%rbx)         # imm = 0xA1A0
movq -0x130(%rbp), %r14
leaq 0x1cfcf(%rip), %rsi     # 0x6b620
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x4e6fc
leaq 0x1cfc0(%rip), %rsi     # 0x6b628
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x4e71a
leaq 0x1cfb2(%rip), %rsi     # 0x6b631
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x4e77a
leaq 0x1cfa3(%rip), %rsi     # 0x6b639
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x4e7b8
leaq 0x1cf95(%rip), %rsi     # 0x6b642
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x4e7f8
leaq 0x1cf86(%rip), %rsi     # 0x6b64a
movq %r14, %rdi
callq 0x8890
xorl %r14d, %r14d
testl %eax, %eax
jne 0x4e910
movw $0x200, 0x2(%rbx)       # imm = 0x200
movb $0x5b, 0x4(%rbx)
cmpq $0x2, %r12
jb 0x4e881
movq -0x128(%rbp), %rdi
callq 0x8990
jmp 0x4e883
movw $0xf00, 0x2(%rbx)       # imm = 0xF00
movb $0x1, 0x4(%rbx)
cmpq $0x3, %r12
jb 0x4e758
movq -0x128(%rbp), %rdi
callq 0x8990
jmp 0x4e75a
movw $0x400, 0x2(%rbx)       # imm = 0x400
leaq 0x5(%rbx), %r15
movb $0x5, 0x4(%rbx)
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0x4e8cb
leaq 0x2(%r14), %rax
cmpq %rax, %r12
jbe 0x4e74d
movq -0x128(%rbp,%r14,8), %rdi
callq 0x8990
jmp 0x4e74f
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
jmp 0x4e72b
xorl %eax, %eax
leaq 0x6(%rbx), %r15
movb %al, 0x5(%rbx)
xorl %eax, %eax
cmpl $0xe, %eax
je 0x4e772
movb $0x0, (%r15,%rax)
incq %rax
jmp 0x4e763
addq %rax, %r15
jmp 0x4e8ce
movw $0x300, 0x2(%rbx)       # imm = 0x300
leaq 0x5(%rbx), %r15
movb $0x9, 0x4(%rbx)
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0x4e8cb
leaq 0x2(%r14), %rax
cmpq %rax, %r12
jbe 0x4e7ad
movq -0x128(%rbp,%r14,8), %rdi
callq 0x8990
jmp 0x4e7af
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
jmp 0x4e78b
movw $0x800, 0x2(%rbx)       # imm = 0x800
movb $0x12, 0x4(%rbx)
cmpq $0x3, %r12
jb 0x4e838
leaq 0x37301(%rip), %r13     # 0x85ad0
movq -0x128(%rbp), %r15
xorl %r14d, %r14d
cmpq $0x6, %r14
je 0x4e842
movq (%r13), %rsi
movq %r15, %rdi
callq 0x8890
testl %eax, %eax
je 0x4e84d
incq %r14
addq $0x8, %r13
jmp 0x4e7d9
movw $0x900, 0x2(%rbx)       # imm = 0x900
movb $0x1e, 0x4(%rbx)
cmpq $0x3, %r12
jb 0x4e83d
leaq 0x372c1(%rip), %r13     # 0x85ad0
movq -0x128(%rbp), %r15
xorl %r14d, %r14d
cmpq $0x6, %r14
je 0x4e88c
movq (%r13), %rsi
movq %r15, %rdi
callq 0x8890
testl %eax, %eax
je 0x4e897
incq %r14
addq $0x8, %r13
jmp 0x4e819
xorl %r14d, %r14d
jmp 0x4e84d
xorl %r14d, %r14d
jmp 0x4e897
movq %r15, %rdi
callq 0x8990
movl %eax, %r14d
movb %r14b, 0x5(%rbx)
leaq 0x6(%rbx), %r15
xorl %r14d, %r14d
cmpq $0x6, %r14
je 0x4e8cb
leaq 0x3(%r14), %rax
cmpq %rax, %r12
jbe 0x4e876
movq -0x120(%rbp,%r14,8), %rdi
callq 0x8990
jmp 0x4e878
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
jmp 0x4e858
xorl %eax, %eax
leaq 0x6(%rbx), %r15
movb %al, 0x5(%rbx)
jmp 0x4e8ce
movq %r15, %rdi
callq 0x8990
movl %eax, %r14d
movb %r14b, 0x5(%rbx)
leaq 0x6(%rbx), %r15
xorl %r14d, %r14d
cmpq $0x7, %r14
je 0x4e8cb
leaq 0x3(%r14), %rax
cmpq %rax, %r12
jbe 0x4e8c0
movq -0x120(%rbp,%r14,8), %rdi
callq 0x8990
jmp 0x4e8c2
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
jmp 0x4e8a2
addq %r14, %r15
movl %r15d, %r14d
subl %ebx, %r14d
addl $0x3, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4e925
movb %al, (%r15)
movw $0xa0d, 0x1(%r15)       # imm = 0xA0D
leaq 0x1cd61(%rip), %rsi     # 0x6b655
pushq $0x4
popq %r15
movl %r15d, %edi
xorl %eax, %eax
callq 0x455bc
movl %r15d, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x4ad1c
movl %r14d, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq