// File: DoubleString[P]RtConverter/src/Rtklib/ublox.cpp
// Function: bamboo::gen_ubx(char const*, unsigned char*)
extern int gen_ubx(const char *msg, unsigned char *buff)
{
    const char *cmd[]={
        "PRT","USB","MSG","NMEA","RATE","CFG","TP","NAV2","DAT","INF",
        "RST","RXM","ANT","FXN","SBAS","LIC","TM","TM2","TMODE","EKF",
        "GNSS","ITFM","LOGFILTER","NAV5","NAVX5","ODO","PM2","PWR","RINV","SMGR",
        "TMODE2","TMODE3","TPS","TXSLOT",""
    };
    const unsigned char id[]={
        0x00,0x1B,0x01,0x17,0x08,0x09,0x07,0x1A,0x06,0x02,
        0x04,0x11,0x13,0x0E,0x16,0x80,0x10,0x19,0x1D,0x12,
        0x3E,0x39,0x47,0x24,0x23,0x1E,0x3B,0x57,0x34,0x62,
        0x36,0x71,0x31,0x53
    };
    const int prm[][32]={
        {FU1,FU1,FU2,FU4,FU4,FU2,FU2,FU2,FU2},    /* PRT */
        {FU2,FU2,FU2,FU2,FU2,FU2,FS32,FS32,FS32}, /* USB */
        {FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1},        /* MSG */
        {FU1,FU1,FU1,FU1},                        /* NMEA */
        {FU2,FU2,FU2},                            /* RATE */
        {FU4,FU4,FU4,FU1},                        /* CFG */
        {FU4,FU4,FI1,FU1,FU2,FI2,FI2,FI4},        /* TP */
        {FU1,FU1,FU2,FU1,FU1,FU1,FU1,FI4,FU1,FU1,FU1,FU1,FU1,FU1,FU2,FU2,FU2,FU2,
         FU2,FU1,FU1,FU2,FU4,FU4},                /* NAV2 */
        {FR8,FR8,FR4,FR4,FR4,FR4,FR4,FR4,FR4},    /* DAT */
        {FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1}, /* INF */
        {FU2,FU1,FU1},                            /* RST */
        {FU1,FU1},                                /* RXM */
        {FU2,FU2},                                /* ANT */
        {FU4,FU4,FU4,FU4,FU4,FU4,FU4,FU4},        /* FXN */
        {FU1,FU1,FU1,FU1,FU4},                    /* SBAS */
        {FU2,FU2,FU2,FU2,FU2,FU2},                /* LIC */
        {FU4,FU4,FU4},                            /* TM */
        {FU1,FU1,FU2,FU4,FU4},                    /* TM2 */
        {FU4,FI4,FI4,FI4,FU4,FU4,FU4},            /* TMODE */
        {FU1,FU1,FU1,FU1,FU4,FU2,FU2,FU1,FU1,FU2}, /* EKF */
        {FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU4},    /* GNSS */
        {FU4,FU4},                                /* ITFM */
        {FU1,FU1,FU2,FU2,FU2,FU4},                /* LOGFILTER */
        {FU2,FU1,FU1,FI4,FU4,FI1,FU1,FU2,FU2,FU2,FU2,FU1,FU1,FU1,FU1,FU1,FU1,FU2,
         FU1,FU1,FU1,FU1,FU1,FU1},                /* NAV5 */
        {FU2,FU2,FU4,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU2,FU1,FU1,FU1,FU1,
         FU1,FU1,FU1,FU1,FU1,FU1,FU2},            /* NAVX5 */
        {FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1,FU1},    /* ODO */
        {FU1,FU1,FU1,FU1,FU4,FU4,FU4,FU4,FU2,FU2}, /* PM2 */
        {FU1,FU1,FU1,FU1,FU4},                    /* PWR */
        {FU1,FU1},                                /* RINV */
        {FU1,FU1,FU2,FU2,FU1,FU1,FU2,FU2,FU2,FU2,FU4}, /* SMGR */
        {FU1,FU1,FU2,FI4,FI4,FI4,FU4,FU4,FU4},    /* TMODE2 */
        {FU1,FU1,FU2,FI4,FI4,FI4,FU4,FU4,FU4},    /* TMODE3 */
        {FU1,FU1,FU1,FU1,FI2,FI2,FU4,FU4,FU4,FU4,FI4,FU4}, /* TPS */
        {FU1,FU1,FU1,FU1,FU4,FU4,FU4,FU4,FU4}     /* TXSLOT */
    };
    unsigned char *q=buff;
    char mbuff[1024],*args[32],*p;
    int i,j,n,narg=0;
    
    trace(4,"gen_ubxf: msg=%s\n",msg);
    
    strcpy(mbuff,msg);
    for (p=strtok(mbuff," ");p&&narg<32;p=strtok(NULL," ")) {
        args[narg++]=p;
    }
    if (narg<1||strncmp(args[0],"CFG-",4)) return 0;
    
    for (i=0;*cmd[i];i++) {
        if (!strcmp(args[0]+4,cmd[i])) break;
    }
    if (!*cmd[i]) return 0;
    
    *q++=UBXSYNC1;
    *q++=UBXSYNC2;
    *q++=UBXCFG;
    *q++=id[i];
    q+=2;
    for (j=1;prm[i][j-1]||j<narg;j++) {
        switch (prm[i][j-1]) {
            case FU1 : setU1(q,j<narg?(unsigned char )atoi(args[j]):0); q+=1; break;
            case FU2 : setU2(q,j<narg?(unsigned short)atoi(args[j]):0); q+=2; break;
            case FU4 : setU4(q,j<narg?(unsigned int  )atoi(args[j]):0); q+=4; break;
            case FI1 : setI1(q,j<narg?(signed char   )atoi(args[j]):0); q+=1; break;
            case FI2 : setI2(q,j<narg?(short         )atoi(args[j]):0); q+=2; break;
            case FI4 : setI4(q,j<narg?(int           )atoi(args[j]):0); q+=4; break;
            case FR4 : setR4(q,j<narg?(float         )atof(args[j]):0); q+=4; break;
            case FR8 : setR8(q,j<narg?(double)atof(args[j]):0); q+=8; break;
            case FS32: sprintf((char *)q,"%-32.32s",j<narg?args[j]:""); q+=32; break;
            default  : setU1(q,j<narg?(unsigned char )atoi(args[j]):0); q+=1; break;
        }
    }
    n=(int)(q-buff)+2;
    setU2(buff+4,(unsigned short)(n-8));
    setcs(buff,n);
    
    trace(5,"gen_ubx: buff=\n"); traceb(5,buff,n);
    return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1840, %rsp           # imm = 0x1840
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x130(%rbp), %rdi
leaq 0x4dc6f(%rip), %rsi     # 0xf6970
movl $0x118, %edx            # imm = 0x118
callq 0x9610
leaq -0x160(%rbp), %rdi
leaq 0x21857(%rip), %rsi     # 0xca570
movl $0x22, %edx
callq 0x9610
leaq -0x1260(%rbp), %rdi
leaq 0x2186f(%rip), %rsi     # 0xca5a0
movl $0x1100, %edx           # imm = 0x1100
callq 0x9610
movq -0x18(%rbp), %rax
movq %rax, -0x1268(%rbp)
movl $0x0, -0x1788(%rbp)
movq -0x10(%rbp), %rdx
movl $0x4, %edi
leaq 0x22af5(%rip), %rsi     # 0xcb855
movb $0x0, %al
callq 0x8b980
leaq -0x1670(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x96f0
leaq -0x1670(%rbp), %rdi
leaq 0x1f3fe(%rip), %rsi     # 0xc8183
callq 0x9b70
movq %rax, -0x1778(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x1778(%rbp)
movb %al, -0x1789(%rbp)
je 0xa8db3
cmpl $0x20, -0x1788(%rbp)
setl %al
movb %al, -0x1789(%rbp)
movb -0x1789(%rbp), %al
testb $0x1, %al
jne 0xa8dbf
jmp 0xa8dfa
movq -0x1778(%rbp), %rcx
movl -0x1788(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x1788(%rbp)
cltq
movq %rcx, -0x1770(%rbp,%rax,8)
xorl %eax, %eax
movl %eax, %edi
leaq 0x1f397(%rip), %rsi     # 0xc8183
callq 0x9b70
movq %rax, -0x1778(%rbp)
jmp 0xa8d91
cmpl $0x1, -0x1788(%rbp)
jl 0xa8e20
movq -0x1770(%rbp), %rdi
leaq 0x22a56(%rip), %rsi     # 0xcb867
movl $0x4, %edx
callq 0x9360
cmpl $0x0, %eax
je 0xa8e2c
movl $0x0, -0x4(%rbp)
jmp 0xa94b0
movl $0x0, -0x177c(%rbp)
movslq -0x177c(%rbp), %rax
movq -0x130(%rbp,%rax,8), %rax
cmpb $0x0, (%rax)
je 0xa8e83
movq -0x1770(%rbp), %rdi
addq $0x4, %rdi
movslq -0x177c(%rbp), %rax
movq -0x130(%rbp,%rax,8), %rsi
callq 0x9a60
cmpl $0x0, %eax
jne 0xa8e70
jmp 0xa8e83
jmp 0xa8e72
movl -0x177c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x177c(%rbp)
jmp 0xa8e36
movslq -0x177c(%rbp), %rax
movq -0x130(%rbp,%rax,8), %rax
cmpb $0x0, (%rax)
jne 0xa8ea3
movl $0x0, -0x4(%rbp)
jmp 0xa94b0
movq -0x1268(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x1268(%rbp)
movb $-0x4b, (%rax)
movq -0x1268(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x1268(%rbp)
movb $0x62, (%rax)
movq -0x1268(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x1268(%rbp)
movb $0x6, (%rax)
movslq -0x177c(%rbp), %rax
movb -0x160(%rbp,%rax), %cl
movq -0x1268(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x1268(%rbp)
movb %cl, (%rax)
movq -0x1268(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x1268(%rbp)
movl $0x1, -0x1780(%rbp)
movslq -0x177c(%rbp), %rax
leaq -0x1260(%rbp), %rcx
shlq $0x7, %rax
addq %rax, %rcx
movl -0x1780(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
movb $0x1, %al
cmpl $0x0, (%rcx,%rdx,4)
movb %al, -0x178a(%rbp)
jne 0xa8f70
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
setl %al
movb %al, -0x178a(%rbp)
movb -0x178a(%rbp), %al
testb $0x1, %al
jne 0xa8f7f
jmp 0xa9441
movslq -0x177c(%rbp), %rax
shlq $0x7, %rax
leaq -0x1260(%rbp,%rax), %rax
movl -0x1780(%rbp), %ecx
decl %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x1798(%rbp)
subl $0x8, %eax
ja 0xa93bf
movq -0x1798(%rbp), %rax
leaq 0x2146e(%rip), %rcx     # 0xca430
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x1268(%rbp), %rax
movq %rax, -0x17a0(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa9006
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x17a4(%rbp)
jmp 0xa9010
xorl %eax, %eax
movl %eax, -0x17a4(%rbp)
jmp 0xa9010
movq -0x17a0(%rbp), %rdi
movl -0x17a4(%rbp), %eax
movzbl %al, %esi
callq 0xa94c0
movq -0x1268(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x17b0(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa9077
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9b60
movzwl %ax, %eax
movl %eax, -0x17b4(%rbp)
jmp 0xa9081
xorl %eax, %eax
movl %eax, -0x17b4(%rbp)
jmp 0xa9081
movq -0x17b0(%rbp), %rdi
movl -0x17b4(%rbp), %eax
movzwl %ax, %esi
callq 0xa94e0
movq -0x1268(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x17c0(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa90e5
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9b60
movl %eax, -0x17c4(%rbp)
jmp 0xa90ef
xorl %eax, %eax
movl %eax, -0x17c4(%rbp)
jmp 0xa90ef
movq -0x17c0(%rbp), %rdi
movl -0x17c4(%rbp), %esi
callq 0xa9500
movq -0x1268(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x17d0(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa9153
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9b60
movsbl %al, %eax
movl %eax, -0x17d4(%rbp)
jmp 0xa915d
xorl %eax, %eax
movl %eax, -0x17d4(%rbp)
jmp 0xa915d
movq -0x17d0(%rbp), %rdi
movl -0x17d4(%rbp), %eax
movsbl %al, %esi
callq 0xa9520
movq -0x1268(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x17e0(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa91c2
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9b60
cwtl
movl %eax, -0x17e4(%rbp)
jmp 0xa91cc
xorl %eax, %eax
movl %eax, -0x17e4(%rbp)
jmp 0xa91cc
movq -0x17e0(%rbp), %rdi
movl -0x17e4(%rbp), %eax
movswl %ax, %esi
callq 0xa9540
movq -0x1268(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x17f0(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa9230
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9b60
movl %eax, -0x17f4(%rbp)
jmp 0xa923a
xorl %eax, %eax
movl %eax, -0x17f4(%rbp)
jmp 0xa923a
movq -0x17f0(%rbp), %rdi
movl -0x17f4(%rbp), %esi
callq 0xa9560
movq -0x1268(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x1800(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa92a1
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9940
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x1804(%rbp)
jmp 0xa92ae
xorps %xmm0, %xmm0
movss %xmm0, -0x1804(%rbp)
jmp 0xa92ae
movq -0x1800(%rbp), %rdi
movss -0x1804(%rbp), %xmm0
callq 0xa9580
movq -0x1268(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x1810(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa9313
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9940
movsd %xmm0, -0x1818(%rbp)
jmp 0xa9320
xorps %xmm0, %xmm0
movsd %xmm0, -0x1818(%rbp)
jmp 0xa9320
movq -0x1810(%rbp), %rdi
movsd -0x1818(%rbp), %xmm0
callq 0xa95a0
movq -0x1268(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x1820(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa937f
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rax
movq %rax, -0x1828(%rbp)
jmp 0xa938f
leaq 0x13981(%rip), %rax     # 0xbcd07
movq %rax, -0x1828(%rbp)
jmp 0xa938f
movq -0x1820(%rbp), %rdi
movq -0x1828(%rbp), %rdx
leaq 0x224c8(%rip), %rsi     # 0xcb86c
movb $0x0, %al
callq 0x9150
movq -0x1268(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942b
movq -0x1268(%rbp), %rax
movq %rax, -0x1830(%rbp)
movl -0x1780(%rbp), %eax
cmpl -0x1788(%rbp), %eax
jge 0xa93fa
movslq -0x1780(%rbp), %rax
movq -0x1770(%rbp,%rax,8), %rdi
callq 0x9b60
movzbl %al, %eax
movl %eax, -0x1834(%rbp)
jmp 0xa9404
xorl %eax, %eax
movl %eax, -0x1834(%rbp)
jmp 0xa9404
movq -0x1830(%rbp), %rdi
movl -0x1834(%rbp), %eax
movzbl %al, %esi
callq 0xa94c0
movq -0x1268(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1268(%rbp)
jmp 0xa942d
movl -0x1780(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1780(%rbp)
jmp 0xa8f2c
movq -0x1268(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
addl $0x2, %eax
movl %eax, -0x1784(%rbp)
movq -0x18(%rbp), %rdi
addq $0x4, %rdi
movl -0x1784(%rbp), %eax
subl $0x8, %eax
movzwl %ax, %esi
callq 0xa94e0
movq -0x18(%rbp), %rdi
movl -0x1784(%rbp), %esi
callq 0xa95c0
movl $0x5, %edi
leaq 0x223e9(%rip), %rsi     # 0xcb875
movb $0x0, %al
callq 0x8b980
movq -0x18(%rbp), %rsi
movl -0x1784(%rbp), %edx
movl $0x5, %edi
callq 0x95900
movl -0x1784(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1840, %rsp           # imm = 0x1840
popq %rbp
retq
nopl (%rax)