// File: /workspace/github_cpp_makefile_star2_O3/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 0x1f2e8(%rip), %rsi     # 0x755d7
xorl %r13d, %r13d
movl $0x4, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4d55d
leaq -0x530(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x85c0
leaq 0x1f1b5(%rip), %r14     # 0x754cf
movq %r15, %rdi
movq %r14, %rsi
callq 0x89b0
leaq 0x1(%r13), %r12
movq %rax, -0x130(%rbp,%r13,8)
xorl %edi, %edi
movq %r14, %rsi
callq 0x89b0
testq %rax, %rax
je 0x56349
cmpq $0x1f, %r13
movq %r12, %r13
jb 0x56325
movq -0x130(%rbp), %r14
movw $0xa1a0, (%rbx)         # imm = 0xA1A0
leaq 0x1f28c(%rip), %rsi     # 0x755e8
movq %r14, %rdi
callq 0x8880
leaq -0x1(%r12), %r15
testl %eax, %eax
je 0x56402
leaq 0x1f278(%rip), %rsi     # 0x755f0
movq %r14, %rdi
callq 0x8880
testl %eax, %eax
je 0x56420
leaq 0x1f26a(%rip), %rsi     # 0x755f9
movq %r14, %rdi
callq 0x8880
testl %eax, %eax
je 0x56475
leaq 0x1f25b(%rip), %rsi     # 0x75601
movq %r14, %rdi
callq 0x8880
testl %eax, %eax
je 0x564b2
leaq 0x1f24d(%rip), %rsi     # 0x7560a
movq %r14, %rdi
callq 0x8880
testl %eax, %eax
je 0x56505
leaq 0x1f23e(%rip), %rsi     # 0x75612
movq %r14, %rdi
callq 0x8880
xorl %r14d, %r14d
testl %eax, %eax
jne 0x5661a
movw $0x200, 0x2(%rbx)       # imm = 0x200
movb $0x5b, 0x4(%rbx)
cmpq $0x1, %r12
jne 0x5662f
xorl %eax, %eax
jmp 0x5663b
movw $0xf00, 0x2(%rbx)       # imm = 0xF00
movb $0x1, 0x4(%rbx)
cmpq $0x2, %r15
jb 0x5645d
movq -0x128(%rbp), %rdi
callq 0x89a0
jmp 0x5645f
movw $0x400, 0x2(%rbx)       # imm = 0x400
leaq 0x5(%rbx), %r15
movb $0x5, 0x4(%rbx)
xorl %r14d, %r14d
leaq 0x2(%r14), %rax
cmpq %r12, %rax
jae 0x56449
movq -0x128(%rbp,%r14,8), %rdi
callq 0x89a0
jmp 0x5644b
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x3, %r14
jne 0x56431
jmp 0x565c0
xorl %eax, %eax
movb %al, 0x5(%rbx)
xorl %eax, %eax
movq %rax, 0x6(%rbx)
movq %rax, 0xc(%rbx)
leaq 0x14(%rbx), %r15
jmp 0x565c3
movw $0x300, 0x2(%rbx)       # imm = 0x300
leaq 0x5(%rbx), %r15
movb $0x9, 0x4(%rbx)
xorl %r14d, %r14d
leaq 0x2(%r14), %rax
cmpq %r12, %rax
jae 0x5649e
movq -0x128(%rbp,%r14,8), %rdi
callq 0x89a0
jmp 0x564a0
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x2, %r14
jne 0x56486
jmp 0x565c0
movw $0x800, 0x2(%rbx)       # imm = 0x800
movb $0x12, 0x4(%rbx)
cmpq $0x2, %r15
jb 0x56554
leaq 0x1f0f0(%rip), %rsi     # 0x755bd
movq -0x128(%rbp), %r15
xorl %r14d, %r14d
leaq 0x375f2(%rip), %r13     # 0x8dad0
movq %r15, %rdi
callq 0x8880
testl %eax, %eax
je 0x56557
movq 0x8(%r13,%r14,8), %rsi
incq %r14
cmpq $0x6, %r14
jne 0x564de
movq %r15, %rdi
callq 0x89a0
movl %eax, %r14d
jmp 0x56557
movw $0x900, 0x2(%rbx)       # imm = 0x900
movb $0x1e, 0x4(%rbx)
cmpq $0x2, %r15
jb 0x5658b
leaq 0x1f0a1(%rip), %rsi     # 0x755bd
movq -0x128(%rbp), %r15
xorl %r14d, %r14d
leaq 0x375a3(%rip), %r13     # 0x8dad0
movq %r15, %rdi
callq 0x8880
testl %eax, %eax
je 0x5658e
movq 0x8(%r13,%r14,8), %rsi
incq %r14
cmpq $0x6, %r14
jne 0x5652d
movq %r15, %rdi
callq 0x89a0
movl %eax, %r14d
jmp 0x5658e
xorl %r14d, %r14d
movb %r14b, 0x5(%rbx)
leaq 0x6(%rbx), %r15
xorl %r14d, %r14d
leaq 0x3(%r14), %rax
cmpq %r12, %rax
jae 0x5657a
movq -0x120(%rbp,%r14,8), %rdi
callq 0x89a0
jmp 0x5657c
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x6, %r14
jne 0x56562
jmp 0x565c0
xorl %r14d, %r14d
movb %r14b, 0x5(%rbx)
leaq 0x6(%rbx), %r15
xorl %r14d, %r14d
leaq 0x3(%r14), %rax
cmpq %r12, %rax
jae 0x565b1
movq -0x120(%rbp,%r14,8), %rdi
callq 0x89a0
jmp 0x565b3
xorl %eax, %eax
movb %al, (%r15,%r14)
incq %r14
cmpq $0x7, %r14
jne 0x56599
addq %r14, %r15
movq %r15, %rax
subq %rbx, %rax
leal 0x3(%rax), %r14d
cmpl $0x5, %eax
jl 0x565eb
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x4, %edx
xorl %ecx, %ecx
xorb (%rbx,%rdx), %cl
incq %rdx
cmpq %rdx, %rax
jne 0x565de
jmp 0x565ed
xorl %ecx, %ecx
movb %cl, (%r15)
movw $0xa0d, 0x1(%r15)       # imm = 0xA0D
leaq 0x1f01f(%rip), %rsi     # 0x7561d
movl $0x4, %edi
xorl %eax, %eax
callq 0x4d55d
movl $0x4, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x53456
movl %r14d, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x128(%rbp), %rdi
callq 0x89a0
leaq 0x6(%rbx), %r15
movb %al, 0x5(%rbx)
jmp 0x565c3