// File: DoubleString[P]RtConverter/src/Rtklib/binex.cpp
// Function: bamboo::decode_bnx_01_04(bamboo::raw_t*, unsigned char*, int)
static int decode_bnx_01_04(raw_t *raw, unsigned char *buff, int len)
{
    eph_t eph={0};
    unsigned char *p=buff;
    double tow,ura,sqrtA;
    int prn,eph_sel=0;
    
    trace(4,"binex 0x01-04: len=%d\n",len);
    
    if (strstr(raw->opt,"-GALINAV")) eph_sel=1;
    if (strstr(raw->opt,"-GALFNAV")) eph_sel=2;
    
    if (len>=127) {
        prn       =U1(p)+1;      p+=1;
        eph.week  =U2(p);        p+=2; /* gal-week = gps-week */
        tow       =I4(p);        p+=4;
        eph.toes  =I4(p);        p+=4;
        eph.tgd[0]=R4(p);        p+=4; /* BGD E5a/E1 */
        eph.tgd[1]=R4(p);        p+=4; /* BGD E5b/E1 */
        eph.iode  =I4(p);        p+=4; /* IODnav */
        eph.f2    =R4(p);        p+=4;
        eph.f1    =R4(p);        p+=4;
        eph.f0    =R4(p);        p+=4;
        eph.deln  =R4(p)*SC2RAD; p+=4;
        eph.M0    =R8(p);        p+=8;
        eph.e     =R8(p);        p+=8;
        sqrtA     =R8(p);        p+=8;
        eph.cic   =R4(p);        p+=4;
        eph.crc   =R4(p);        p+=4;
        eph.cis   =R4(p);        p+=4;
        eph.crs   =R4(p);        p+=4;
        eph.cuc   =R4(p);        p+=4;
        eph.cus   =R4(p);        p+=4;
        eph.OMG0  =R8(p);        p+=8;
        eph.omg   =R8(p);        p+=8;
        eph.i0    =R8(p);        p+=8;
        eph.OMGd  =R4(p)*SC2RAD; p+=4;
        eph.idot  =R4(p)*SC2RAD; p+=4;
        ura       =R4(p);        p+=4;
        eph.svh   =U2(p);        p+=2;
        eph.code  =U2(p); /* data source defined as rinex 3.03 */
    }
    else {
        trace(2,"binex 0x01-04: length error len=%d\n",len);
        return -1;
    }
    if (!(eph.sat=satno(SYS_GAL,prn))) {
        trace(2,"binex 0x01-04: satellite error prn=%d\n",prn);
        return -1;
    }
    if (eph_sel==1&&!(eph.code&(1<<9))) return 0; /* only I/NAV */
    if (eph_sel==2&&!(eph.code&(1<<8))) return 0; /* only F/NAV */
    
    eph.A=sqrtA*sqrtA;
    eph.iodc=eph.iode;
    eph.toe=gpst2time(eph.week,eph.toes);
    eph.toc=gpst2time(eph.week,eph.toes);
    eph.ttr=adjweek(eph.toe,tow);
    eph.sva=ura<0.0?(int)(-ura)-1:sisaindex(ura); /* sisa index */
    if (!strstr(raw->opt,"-EPHALL")) {
        if (raw->nav.eph[eph.sat-1].iode==eph.iode&&
            raw->nav.eph[eph.sat-1].iodc==eph.iodc) return 0; /* unchanged */
    }
    raw->nav.eph[eph.sat-1]=eph;
    raw->ephsat=eph.sat;
    return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
leaq -0x140(%rbp), %rdi
xorl %esi, %esi
movl $0x120, %edx            # imm = 0x120
callq 0x93d0
movq -0x18(%rbp), %rax
movq %rax, -0x148(%rbp)
movl $0x0, -0x168(%rbp)
movl -0x1c(%rbp), %edx
movl $0x4, %edi
leaq 0x60f8e(%rip), %rsi     # 0xbe92b
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x60f8c(%rip), %rsi     # 0xbe942
callq 0x91b0
cmpq $0x0, %rax
je 0x5d9cb
movl $0x1, -0x168(%rbp)
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x60f6e(%rip), %rsi     # 0xbe94b
callq 0x91b0
cmpq $0x0, %rax
je 0x5d9f2
movl $0x2, -0x168(%rbp)
cmpl $0x7f, -0x1c(%rbp)
jl 0x5de67
movq -0x148(%rbp), %rax
movzbl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
movq -0x148(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5b2b0
movzwl %ax, %eax
movl %eax, -0x12c(%rbp)
movq -0x148(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f860
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x150(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f860
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f860
movl %eax, -0x13c(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd 0x601c0(%rip), %xmm1    # 0xbdd58
mulsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f8e0
movsd %xmm0, -0xc8(%rbp)
movq -0x148(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f8e0
movsd %xmm0, -0xe8(%rbp)
movq -0x148(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f8e0
movsd %xmm0, -0x160(%rbp)
movq -0x148(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f8e0
movsd %xmm0, -0xd8(%rbp)
movq -0x148(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f8e0
movsd %xmm0, -0xd0(%rbp)
movq -0x148(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f8e0
movsd %xmm0, -0xe0(%rbp)
movq -0x148(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd 0x5ffad(%rip), %xmm1    # 0xbdd58
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd 0x5ff77(%rip), %xmm1    # 0xbdd58
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5f880
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x158(%rbp)
movq -0x148(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5b2b0
movzwl %ax, %eax
movl %eax, -0x130(%rbp)
movq -0x148(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x5b2b0
movzwl %ax, %eax
movl %eax, -0x128(%rbp)
jmp 0x5de89
movl -0x1c(%rbp), %edx
movl $0x2, %edi
leaq 0x60ade(%rip), %rsi     # 0xbe954
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e132
movl -0x164(%rbp), %esi
movl $0x8, %edi
callq 0x8b1b0
movl %eax, -0x140(%rbp)
cmpl $0x0, %eax
jne 0x5dec9
movl -0x164(%rbp), %edx
movl $0x2, %edi
leaq 0x60ac2(%rip), %rsi     # 0xbe978
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5e132
cmpl $0x1, -0x168(%rbp)
jne 0x5deee
movl -0x128(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x5deee
movl $0x0, -0x4(%rbp)
jmp 0x5e132
cmpl $0x2, -0x168(%rbp)
jne 0x5df13
movl -0x128(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0x5df13
movl $0x0, -0x4(%rbp)
jmp 0x5e132
movsd -0x160(%rbp), %xmm0
mulsd -0x160(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movl -0x13c(%rbp), %eax
movl %eax, -0x138(%rbp)
movl -0x12c(%rbp), %edi
movsd -0x78(%rbp), %xmm0
callq 0x8e4a0
movq %rax, -0x178(%rbp)
movsd %xmm0, -0x170(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x118(%rbp)
movl -0x12c(%rbp), %edi
movsd -0x78(%rbp), %xmm0
callq 0x8e4a0
movq %rax, -0x188(%rbp)
movsd %xmm0, -0x180(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movsd -0x150(%rbp), %xmm1
movq -0x1a8(%rbp), %rdi
movsd -0x1a0(%rbp), %xmm0
callq 0x5f940
movq %rax, -0x198(%rbp)
movsd %xmm0, -0x190(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x190(%rbp), %rax
movq %rax, -0xf8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x158(%rbp), %xmm0
jbe 0x5e04b
movsd -0x158(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
cvttsd2si %xmm0, %eax
subl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x5e05e
movsd -0x158(%rbp), %xmm0
callq 0x5fb90
movl %eax, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
movl %eax, -0x134(%rbp)
movq -0x10(%rbp), %rdi
addq $0x82a90, %rdi          # imm = 0x82A90
leaq 0x607e3(%rip), %rsi     # 0xbe85f
callq 0x91b0
cmpq $0x0, %rax
jne 0x5e0ea
movq -0x10(%rbp), %rax
movq 0x1d80(%rax), %rax
movl -0x140(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x120, %rcx, %rcx      # imm = 0x120
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpl -0x13c(%rbp), %eax
jne 0x5e0e8
movq -0x10(%rbp), %rax
movq 0x1d80(%rax), %rax
movl -0x140(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x120, %rcx, %rcx      # imm = 0x120
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x138(%rbp), %eax
jne 0x5e0e8
movl $0x0, -0x4(%rbp)
jmp 0x5e132
jmp 0x5e0ea
movq -0x10(%rbp), %rax
movq 0x1d80(%rax), %rdi
movl -0x140(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x120, %rax, %rax      # imm = 0x120
addq %rax, %rdi
leaq -0x140(%rbp), %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x9610
movl -0x140(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x70e40(%rax)
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
nop