// File: DoubleString[P]RtConverter/src/Rtklib/skytraq.cpp
// Function: bamboo::decode_stqbds(bamboo::raw_t*)
static int decode_stqbds(raw_t *raw)
{
    eph_t eph={0};
    unsigned int word;
    int i,j=0,id,pgn,prn,sat;
    unsigned char *p=raw->buff+4;
    
    trace(4,"decode_stqbds: len=%d\n",raw->len);
    
    if (raw->len<38) {
        trace(2,"stq bds subframe length error: len=%d\n",raw->len);
        return -1;
    }
    if (raw->outtype) {
        sprintf(raw->msgtype,"SKYTRAQ BDSSF (%4d): prn=%2d id=%d",raw->len,
                U1(p+1)-200,U1(p+2));
    }
    prn=U1(p+1)-200;
    if (!(sat=satno(SYS_CMP,prn))) {
        trace(2,"stq bds subframe satellite number error: prn=%d\n",prn);
        return -1;
    }
    id=U1(p+2); /* subframe id */
    if (id<1||5<id) {
        trace(2,"stq bds subframe id error: prn=%2d\n",prn);
        return -1;
    }
    if (prn>5) { /* IGSO/MEO */
        word=getbitu(p+3,j,26)<<4; j+=26;
        setbitu(raw->subfrm[sat-1]+(id-1)*38,0,30,word);
        
        for (i=1;i<10;i++) {
            word=getbitu(p+3,j,22)<<8; j+=22;
            setbitu(raw->subfrm[sat-1]+(id-1)*38,i*30,30,word);
        }
        if (id!=3) return 0;
        
        /* decode beidou D1 ephemeris */
        if (!decode_bds_d1(raw->subfrm[sat-1],&eph)) return 0;
    }
    else { /* GEO */
        if (id!=1) return 0;
        
        pgn=getbitu(p+3,26+12,4); /* page number */
        if (pgn<1||10<pgn) {
            trace(2,"stq bds subframe page number error: prn=%2d pgn=%d\n",prn,pgn);
            return -1;
        }
        word=getbitu(p+3,j,26)<<4; j+=26;
        setbitu(raw->subfrm[sat-1]+(pgn-1)*38,0,30,word);
        
        for (i=1;i<10;i++) {
            word=getbitu(p+3,j,22)<<8; j+=22;
            setbitu(raw->subfrm[sat-1]+(pgn-1)*38,i*30,30,word);
        }
        if (pgn!=10) return 0;
        
        /* decode beidou D2 ephemeris */
        if (!decode_bds_d2(raw->subfrm[sat-1],&eph)) return 0;
    }
    if (!strstr(raw->opt,"-EPHALL")) {
        if (timediff(eph.toe,raw->nav.eph[sat-1].toe)==0.0&&
            eph.iode==raw->nav.eph[sat-1].iode&&
            eph.iodc==raw->nav.eph[sat-1].iodc) return 0; /* unchanged */
    }
    eph.sat=sat;
    raw->nav.eph[sat-1]=eph;
    raw->ephsat=sat;
    return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x10(%rbp)
leaq -0x130(%rbp), %rdi
xorl %esi, %esi
movl $0x120, %edx            # imm = 0x120
callq 0x93d0
movl $0x0, -0x13c(%rbp)
movq -0x10(%rbp), %rax
addq $0x81a90, %rax          # imm = 0x81A90
addq $0x4, %rax
movq %rax, -0x158(%rbp)
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %edx
movl $0x4, %edi
leaq 0x2c678(%rip), %rsi     # 0xc87af
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rax
cmpl $0x26, 0x81a78(%rax)
jge 0x9c174
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %edx
movl $0x2, %edi
leaq 0x2c665(%rip), %rsi     # 0xc87c6
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9c722
movq -0x10(%rbp), %rax
cmpl $0x0, 0x81a8c(%rax)
je 0x9c1c1
movq -0x10(%rbp), %rdi
addq $0x70e70, %rdi          # imm = 0x70E70
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %edx
movq -0x158(%rbp), %rax
movzbl 0x1(%rax), %ecx
subl $0xc8, %ecx
movq -0x158(%rbp), %rax
movzbl 0x2(%rax), %r8d
leaq 0x2c633(%rip), %rsi     # 0xc87ed
movb $0x0, %al
callq 0x9150
movq -0x158(%rbp), %rax
movzbl 0x1(%rax), %eax
subl $0xc8, %eax
movl %eax, -0x148(%rbp)
movl -0x148(%rbp), %esi
movl $0x20, %edi
callq 0x8b1b0
movl %eax, -0x14c(%rbp)
cmpl $0x0, %eax
jne 0x9c217
movl -0x148(%rbp), %edx
movl $0x2, %edi
leaq 0x2c60c(%rip), %rsi     # 0xc8810
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9c722
movq -0x158(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x140(%rbp)
cmpl $0x1, -0x140(%rbp)
jl 0x9c23e
movl $0x5, %eax
cmpl -0x140(%rbp), %eax
jge 0x9c263
movl -0x148(%rbp), %edx
movl $0x2, %edi
leaq 0x2c5f1(%rip), %rsi     # 0xc8841
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9c722
cmpl $0x5, -0x148(%rbp)
jle 0x9c3e3
movq -0x158(%rbp), %rdi
addq $0x3, %rdi
movl -0x13c(%rbp), %esi
movl $0x1a, %edx
callq 0x8bfc0
shll $0x4, %eax
movl %eax, -0x134(%rbp)
movl -0x13c(%rbp), %eax
addl $0x1a, %eax
movl %eax, -0x13c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14c(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
movl -0x140(%rbp), %eax
subl $0x1, %eax
imull $0x26, %eax, %eax
cltq
addq %rax, %rdi
movl -0x134(%rbp), %ecx
xorl %esi, %esi
movl $0x1e, %edx
callq 0x8c0d0
movl $0x1, -0x138(%rbp)
cmpl $0xa, -0x138(%rbp)
jge 0x9c38c
movq -0x158(%rbp), %rdi
addq $0x3, %rdi
movl -0x13c(%rbp), %esi
movl $0x16, %edx
callq 0x8bfc0
shll $0x8, %eax
movl %eax, -0x134(%rbp)
movl -0x13c(%rbp), %eax
addl $0x16, %eax
movl %eax, -0x13c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14c(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
movl -0x140(%rbp), %eax
subl $0x1, %eax
imull $0x26, %eax, %eax
cltq
addq %rax, %rdi
imull $0x1e, -0x138(%rbp), %esi
movl -0x134(%rbp), %ecx
movl $0x1e, %edx
callq 0x8c0d0
movl -0x138(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x138(%rbp)
jmp 0x9c2f0
cmpl $0x3, -0x140(%rbp)
je 0x9c3a1
movl $0x0, -0x4(%rbp)
jmp 0x9c722
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14c(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
leaq -0x130(%rbp), %rsi
callq 0x63080
cmpl $0x0, %eax
jne 0x9c3de
movl $0x0, -0x4(%rbp)
jmp 0x9c722
jmp 0x9c5c9
cmpl $0x1, -0x140(%rbp)
je 0x9c3f8
movl $0x0, -0x4(%rbp)
jmp 0x9c722
movq -0x158(%rbp), %rdi
addq $0x3, %rdi
movl $0x26, %esi
movl $0x4, %edx
callq 0x8bfc0
movl %eax, -0x144(%rbp)
cmpl $0x1, -0x144(%rbp)
jl 0x9c42e
movl $0xa, %eax
cmpl -0x144(%rbp), %eax
jge 0x9c459
movl -0x148(%rbp), %edx
movl -0x144(%rbp), %ecx
movl $0x2, %edi
leaq 0x2c41f(%rip), %rsi     # 0xc8865
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9c722
movq -0x158(%rbp), %rdi
addq $0x3, %rdi
movl -0x13c(%rbp), %esi
movl $0x1a, %edx
callq 0x8bfc0
shll $0x4, %eax
movl %eax, -0x134(%rbp)
movl -0x13c(%rbp), %eax
addl $0x1a, %eax
movl %eax, -0x13c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14c(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
movl -0x144(%rbp), %eax
subl $0x1, %eax
imull $0x26, %eax, %eax
cltq
addq %rax, %rdi
movl -0x134(%rbp), %ecx
xorl %esi, %esi
movl $0x1e, %edx
callq 0x8c0d0
movl $0x1, -0x138(%rbp)
cmpl $0xa, -0x138(%rbp)
jge 0x9c575
movq -0x158(%rbp), %rdi
addq $0x3, %rdi
movl -0x13c(%rbp), %esi
movl $0x16, %edx
callq 0x8bfc0
shll $0x8, %eax
movl %eax, -0x134(%rbp)
movl -0x13c(%rbp), %eax
addl $0x16, %eax
movl %eax, -0x13c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14c(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
movl -0x144(%rbp), %eax
subl $0x1, %eax
imull $0x26, %eax, %eax
cltq
addq %rax, %rdi
imull $0x1e, -0x138(%rbp), %esi
movl -0x134(%rbp), %ecx
movl $0x1e, %edx
callq 0x8c0d0
movl -0x138(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x138(%rbp)
jmp 0x9c4d9
cmpl $0xa, -0x144(%rbp)
je 0x9c58a
movl $0x0, -0x4(%rbp)
jmp 0x9c722
movq -0x10(%rbp), %rdi
addq $0x70f70, %rdi          # imm = 0x70F70
movl -0x14c(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x17c, %rax, %rax      # imm = 0x17C
addq %rax, %rdi
leaq -0x130(%rbp), %rsi
callq 0x63be0
cmpl $0x0, %eax
jne 0x9c5c7
movl $0x0, -0x4(%rbp)
jmp 0x9c722
jmp 0x9c5c9
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x22284(%rip), %rsi     # 0xbe85f
callq 0x91b0
cmpq $0x0, %rax
jne 0x9c6ce
movq -0x110(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rax
movq 0x1d80(%rax), %rax
movl -0x14c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x120, %rcx, %rcx      # imm = 0x120
addq %rcx, %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x178(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rdi
movsd -0x160(%rbp), %xmm0
movq -0x178(%rbp), %rsi
movsd -0x170(%rbp), %xmm1
callq 0x8e8e0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x9c6cc
jp 0x9c6cc
movl -0x12c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x1d80(%rcx), %rcx
movl -0x14c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x120, %rdx, %rdx      # imm = 0x120
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0x9c6cc
movl -0x128(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x1d80(%rcx), %rcx
movl -0x14c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x120, %rdx, %rdx      # imm = 0x120
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0x9c6cc
movl $0x0, -0x4(%rbp)
jmp 0x9c722
jmp 0x9c6ce
movl -0x14c(%rbp), %eax
movl %eax, -0x130(%rbp)
movq -0x10(%rbp), %rax
movq 0x1d80(%rax), %rdi
movl -0x14c(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x120, %rax, %rax      # imm = 0x120
addq %rax, %rdi
leaq -0x130(%rbp), %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x9610
movl -0x14c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x70e40(%rax)
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nop