// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %r14
leaq -0x168(%rbp), %rdi
movl $0x120, %edx            # imm = 0x120
xorl %esi, %esi
callq 0x8390
movl 0x81a78(%r14), %edx
leaq 0x1d0bd(%rip), %rsi     # 0x6ba3f
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0x455bc
movl 0x81a78(%r14), %edx
cmpl $0x25, %edx
jg 0x4e9a4
leaq 0x1d0b7(%rip), %rsi     # 0x6ba56
pushq $0x2
popq %rdi
jmp 0x4ea1d
cmpl $0x0, 0x81a8c(%r14)
je 0x4e9d9
leaq 0x70e70(%r14), %rdi
movzbl 0x81a95(%r14), %ecx
addl $0xffffff38, %ecx       # imm = 0xFFFFFF38
movzbl 0x81a96(%r14), %r8d
leaq 0x1d0ab(%rip), %rsi     # 0x6ba7d
xorl %eax, %eax
callq 0x8110
movzbl 0x81a95(%r14), %ebx
leal -0xc8(%rbx), %r13d
pushq $0x20
popq %rdi
movl %r13d, %esi
callq 0x452fd
testl %eax, %eax
je 0x4ea10
movzbl 0x81a96(%r14), %edx
leal -0x6(%rdx), %ecx
cmpb $-0x6, %cl
ja 0x4ea3d
leaq 0x1d0c3(%rip), %rsi     # 0x6bad1
jmp 0x4ea17
leaq 0x1d089(%rip), %rsi     # 0x6baa0
pushq $0x2
popq %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x455bc
pushq $-0x1
popq %r12
movl %r12d, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $-0x32, %bl
jb 0x4eaea
leaq 0x81a97(%r14), %r15
movq %rax, %rbx
pushq $0x1a
popq %r12
movq %r15, %rdi
xorl %esi, %esi
movq %rdx, %r13
movl %r12d, %edx
callq 0x459f7
shll $0x4, %eax
movq %rbx, -0x40(%rbp)
leal -0x1(%rbx), %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
leaq (%r14,%rcx), %rdx
movq %r14, -0x48(%rbp)
addq %r14, %rcx
addq $0x70f70, %rcx          # imm = 0x70F70
movq %rcx, -0x30(%rbp)
movq %r13, -0x38(%rbp)
imulq $0x26, %r13, %rcx
leaq (%rcx,%rdx), %r13
addq $0x70f4a, %r13          # imm = 0x70F4A
pushq $0x1e
popq %r14
movq %r13, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %eax, %ecx
callq 0x45a69
movl %r14d, %ebx
cmpl $0xe0, %r12d
je 0x4eb35
movq %r15, %rdi
movl %r12d, %esi
pushq $0x16
popq %rdx
callq 0x459f7
shll $0x8, %eax
addl $0x16, %r12d
movq %r13, %rdi
movl %r14d, %esi
movl %ebx, %edx
movl %eax, %ecx
callq 0x45a69
addl $0x1e, %r14d
jmp 0x4eab7
cmpl $0x1, %edx
jne 0x4ece1
movq %rax, -0x40(%rbp)
leaq 0x81a97(%r14), %r12
pushq $0x26
popq %rsi
pushq $0x4
popq %rdx
movq %r12, %rdi
callq 0x459f7
movl %eax, %ebx
leal -0xb(%rbx), %eax
cmpl $-0xb, %eax
ja 0x4ebbc
leaq 0x1cfd4(%rip), %rsi     # 0x6baf5
pushq $0x2
popq %rdi
movl %r13d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x455bc
jmp 0x4ea24
xorl %r12d, %r12d
cmpl $0x3, -0x38(%rbp)
jne 0x4ea28
leaq -0x168(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2e0d2
testl %eax, %eax
je 0x4ea28
movq -0x48(%rbp), %r14
leaq 0x82a90(%r14), %rdi
leaq 0x13b5b(%rip), %rsi     # 0x626c7
callq 0x8170
testq %rax, %rax
movq -0x40(%rbp), %r15
je 0x4ec70
leaq -0x168(%rbp), %rsi
movl %r15d, (%rsi)
movq 0x1d80(%r14), %rax
movslq %r15d, %rcx
imulq $0x120, %rcx, %rcx      # imm = 0x120
leaq (%rax,%rcx), %rdi
addq $-0x120, %rdi           # imm = 0xFEE0
movl $0x120, %edx            # imm = 0x120
callq 0x84f0
movl %r15d, 0x70e40(%r14)
pushq $0x2
jmp 0x4ea26
pushq $0x1a
popq %r13
movq %r12, %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x459f7
shll $0x4, %eax
movq -0x40(%rbp), %rcx
decl %ecx
movslq %ecx, %rcx
imulq $0x17c, %rcx, %rcx      # imm = 0x17C
leaq (%r14,%rcx), %rdx
movq %r14, -0x48(%rbp)
addq %r14, %rcx
addq $0x70f70, %rcx          # imm = 0x70F70
movq %rcx, -0x30(%rbp)
movq %rbx, -0x38(%rbp)
imull $0x26, %ebx, %ecx
leaq (%rcx,%rdx), %r15
addq $0x70f4a, %r15          # imm = 0x70F4A
pushq $0x1e
popq %rbx
movq %r15, %rdi
xorl %esi, %esi
movl %ebx, %edx
movl %eax, %ecx
callq 0x45a69
movl %ebx, %r14d
cmpl $0xe0, %r13d
je 0x4ec4e
movq %r12, %rdi
movl %r13d, %esi
pushq $0x16
popq %rdx
callq 0x459f7
shll $0x8, %eax
addl $0x16, %r13d
movq %r15, %rdi
movl %ebx, %esi
movl %r14d, %edx
movl %eax, %ecx
callq 0x45a69
addl $0x1e, %ebx
jmp 0x4ec1c
xorl %r12d, %r12d
cmpl $0xa, -0x38(%rbp)
jne 0x4ea28
leaq -0x168(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x2e81c
jmp 0x4eb52
movq -0x148(%rbp), %rdi
movsd -0x140(%rbp), %xmm0
movq 0x1d80(%r14), %rax
leal -0x1(%r15), %ecx
movslq %ecx, %rcx
imulq $0x120, %rcx, %rbx      # imm = 0x120
movq 0x20(%rax,%rbx), %rsi
movsd 0x28(%rax,%rbx), %xmm1
callq 0x47322
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4eb7e
jp 0x4eb7e
movl -0x164(%rbp), %ecx
movq 0x1d80(%r14), %rax
cmpl 0x4(%rax,%rbx), %ecx
jne 0x4eb7e
addq %rbx, %rax
movl -0x160(%rbp), %ecx
cmpl 0x8(%rax), %ecx
jne 0x4eb7e
xorl %r12d, %r12d
jmp 0x4ea28