// File: /workspace/github_cpp_makefile_star2_O1/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 0x1e86b(%rip), %rsi     # 0x7561f
xorl %r13d, %r13d
movl $0x4, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4ded0
leaq -0x530(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x85c0
leaq 0x1e716(%rip), %rsi     # 0x754f5
movq %r15, %rdi
callq 0x89c0
testq %rax, %rax
je 0x56e1a
xorl %r15d, %r15d
leaq 0x1e6ff(%rip), %r14     # 0x754f5
leaq 0x1(%r15), %r13
movq %rax, -0x130(%rbp,%r15,8)
xorl %edi, %edi
movq %r14, %rsi
callq 0x89c0
testq %rax, %rax
je 0x56e1a
cmpq $0x1f, %r15
movq %r13, %r15
jb 0x56df6
movw $0xa1a0, (%rbx)         # imm = 0xA1A0
movq -0x130(%rbp), %r14
leaq 0x1e803(%rip), %rsi     # 0x75630
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x56ed8
leaq 0x1e7f4(%rip), %rsi     # 0x75638
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x56ef6
leaq 0x1e7e6(%rip), %rsi     # 0x75641
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x56f4e
leaq 0x1e7d7(%rip), %rsi     # 0x75649
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x56f8e
leaq 0x1e7c9(%rip), %rsi     # 0x75652
movq %r14, %rdi
callq 0x8890
testl %eax, %eax
je 0x56ff5
leaq 0x1e7ba(%rip), %rsi     # 0x7565a
movq %r14, %rdi
callq 0x8890
xorl %r14d, %r14d
testl %eax, %eax
jne 0x57160
movw $0x200, 0x2(%rbx)       # imm = 0x200
movb $0x5b, 0x4(%rbx)
cmpl $0x2, %r13d
jb 0x57062
movq -0x128(%rbp), %rdi
callq 0x89b0
jmp 0x57064
movw $0xf00, 0x2(%rbx)       # imm = 0xF00
movb $0x1, 0x4(%rbx)
cmpl $0x3, %r13d
jb 0x56f36
movq -0x128(%rbp), %rdi
callq 0x89b0
jmp 0x56f38
movw $0x400, 0x2(%rbx)       # imm = 0x400
leaq 0x5(%rbx), %r15
movb $0x5, 0x4(%rbx)
movl %r13d, %r12d
xorl %r14d, %r14d
leaq 0x2(%r14), %rax
cmpq %r12, %rax
jae 0x56f22
movq -0x128(%rbp,%r14,8), %rdi
callq 0x89b0
jmp 0x56f24
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x3, %r14
jne 0x56f0a
jmp 0x57106
xorl %eax, %eax
movb %al, 0x5(%rbx)
xorl %eax, %eax
movq %rax, 0x6(%rbx)
movq %rax, 0xc(%rbx)
leaq 0x14(%rbx), %r15
jmp 0x57109
movw $0x300, 0x2(%rbx)       # imm = 0x300
leaq 0x5(%rbx), %r15
movb $0x9, 0x4(%rbx)
movl %r13d, %r12d
xorl %r14d, %r14d
leaq 0x2(%r14), %rax
cmpq %r12, %rax
jae 0x56f7a
movq -0x128(%rbp,%r14,8), %rdi
callq 0x89b0
jmp 0x56f7c
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x2, %r14
jne 0x56f62
jmp 0x57106
movw $0x800, 0x2(%rbx)       # imm = 0x800
movb $0x12, 0x4(%rbx)
cmpl $0x3, %r13d
jb 0x57058
movq -0x128(%rbp), %r15
leaq 0x1e655(%rip), %rsi     # 0x75605
movq %r15, %rdi
callq 0x8890
xorl %r14d, %r14d
testl %eax, %eax
je 0x57070
cmpq $0x5, %r14
je 0x57076
leaq 0x3695c(%rip), %rax     # 0x8d930
movq 0x8(%rax,%r14,8), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x8890
incq %r14
testl %eax, %eax
jne 0x56fc3
cmpb $0x0, (%r12)
sete %al
jmp 0x57072
movw $0x900, 0x2(%rbx)       # imm = 0x900
movb $0x1e, 0x4(%rbx)
cmpl $0x3, %r13d
jb 0x5705d
movq -0x128(%rbp), %r15
leaq 0x1e5f2(%rip), %rsi     # 0x75605
movq %r15, %rdi
callq 0x8890
xorl %r14d, %r14d
testl %eax, %eax
je 0x570bc
cmpq $0x5, %r14
je 0x570c2
leaq 0x368f9(%rip), %rax     # 0x8d930
movq 0x8(%rax,%r14,8), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x8890
incq %r14
testl %eax, %eax
jne 0x57026
cmpb $0x0, (%r12)
sete %al
jmp 0x570be
xorl %r14d, %r14d
jmp 0x57085
xorl %r14d, %r14d
jmp 0x570d1
xorl %eax, %eax
leaq 0x6(%rbx), %r15
movb %al, 0x5(%rbx)
jmp 0x57109
xorl %eax, %eax
testb %al, %al
je 0x57085
movq -0x128(%rbp), %rdi
callq 0x89b0
movl %eax, %r14d
movb %r14b, 0x5(%rbx)
leaq 0x6(%rbx), %r15
movl %r13d, %r12d
xorl %r14d, %r14d
leaq 0x3(%r14), %rax
cmpq %r12, %rax
jae 0x570ab
movq -0x120(%rbp,%r14,8), %rdi
callq 0x89b0
jmp 0x570ad
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x6, %r14
jne 0x57093
jmp 0x57106
xorl %eax, %eax
testb %al, %al
je 0x570d1
movq -0x128(%rbp), %rdi
callq 0x89b0
movl %eax, %r14d
movb %r14b, 0x5(%rbx)
leaq 0x6(%rbx), %r15
movl %r13d, %r12d
xorl %r14d, %r14d
leaq 0x3(%r14), %rax
cmpq %r12, %rax
jae 0x570f7
movq -0x120(%rbp,%r14,8), %rdi
callq 0x89b0
jmp 0x570f9
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x7, %r14
jne 0x570df
addq %r14, %r15
movq %r15, %rax
subq %rbx, %rax
leal 0x3(%rax), %r14d
cmpl $0x5, %eax
jl 0x57131
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x4, %edx
xorl %ecx, %ecx
xorb (%rbx,%rdx), %cl
incq %rdx
cmpq %rdx, %rax
jne 0x57124
jmp 0x57133
xorl %ecx, %ecx
movb %cl, (%r15)
movw $0xa0d, 0x1(%r15)       # imm = 0xA0D
leaq 0x1e521(%rip), %rsi     # 0x75665
movl $0x4, %edi
xorl %eax, %eax
callq 0x4ded0
movl $0x4, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x53eee
movl %r14d, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq