// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/rcvraw.cpp
// Function: bamboo::decode_gal_inav(unsigned char const*, bamboo::eph_t*)
extern int decode_gal_inav(const unsigned char *buff, eph_t *eph)
{
    double tow,toc,tt,sqrtA;
    int i,time_f,week,svid,e5b_hs,e1b_hs,e5b_dvs,e1b_dvs,type[6],iod_nav[4];
    
    i=0; /* word type 0 */
    type[0]    =getbitu(buff,i, 6);              i+= 6;
    time_f     =getbitu(buff,i, 2);              i+= 2+88;
    week       =getbitu(buff,i,12);              i+=12; /* gst-week */
    tow        =getbitu(buff,i,20);
    
    i=128; /* word type 1 */
    type[1]    =getbitu(buff,i, 6);              i+= 6;
    iod_nav[0] =getbitu(buff,i,10);              i+=10;
    eph->toes  =getbitu(buff,i,14)*60.0;         i+=14;
    eph->M0    =getbits(buff,i,32)*P2_31*SC2RAD; i+=32;
    eph->e     =getbitu(buff,i,32)*P2_33;        i+=32;
    sqrtA      =getbitu(buff,i,32)*P2_19;
    
    i=128*2; /* word type 2 */
    type[2]    =getbitu(buff,i, 6);              i+= 6;
    iod_nav[1] =getbitu(buff,i,10);              i+=10;
    eph->OMG0  =getbits(buff,i,32)*P2_31*SC2RAD; i+=32;
    eph->i0    =getbits(buff,i,32)*P2_31*SC2RAD; i+=32;
    eph->omg   =getbits(buff,i,32)*P2_31*SC2RAD; i+=32;
    eph->idot  =getbits(buff,i,14)*P2_43*SC2RAD;
    
    i=128*3; /* word type 3 */
    type[3]    =getbitu(buff,i, 6);              i+= 6;
    iod_nav[2] =getbitu(buff,i,10);              i+=10;
    eph->OMGd  =getbits(buff,i,24)*P2_43*SC2RAD; i+=24;
    eph->deln  =getbits(buff,i,16)*P2_43*SC2RAD; i+=16;
    eph->cuc   =getbits(buff,i,16)*P2_29;        i+=16;
    eph->cus   =getbits(buff,i,16)*P2_29;        i+=16;
    eph->crc   =getbits(buff,i,16)*P2_5;         i+=16;
    eph->crs   =getbits(buff,i,16)*P2_5;         i+=16;
    eph->sva   =getbitu(buff,i, 8);
    
    i=128*4; /* word type 4 */
    type[4]    =getbitu(buff,i, 6);              i+= 6;
    iod_nav[3] =getbitu(buff,i,10);              i+=10;
    svid       =getbitu(buff,i, 6);              i+= 6;
    eph->cic   =getbits(buff,i,16)*P2_29;        i+=16;
    eph->cis   =getbits(buff,i,16)*P2_29;        i+=16;
    toc        =getbitu(buff,i,14)*60.0;         i+=14;
    eph->f0    =getbits(buff,i,31)*P2_34;        i+=31;
    eph->f1    =getbits(buff,i,21)*P2_46;        i+=21;
    eph->f2    =getbits(buff,i, 6)*P2_59;
    
    i=128*5; /* word type 5 */
    type[5]    =getbitu(buff,i, 6);              i+= 6+41;
    eph->tgd[0]=getbits(buff,i,10)*P2_32;        i+=10; /* BGD E5a/E1 */
    eph->tgd[1]=getbits(buff,i,10)*P2_32;        i+=10; /* BGD E5b/E1 */
    e5b_hs     =getbitu(buff,i, 2);              i+= 2;
    e1b_hs     =getbitu(buff,i, 2);              i+= 2;
    e5b_dvs    =getbitu(buff,i, 1);              i+= 1;
    e1b_dvs    =getbitu(buff,i, 1);
    
    /* test word types */
    if (type[0]!=0||type[1]!=1||type[2]!=2||type[3]!=3||type[4]!=4||type[5]!=5) {
        trace(3,"decode_gal_inav error: type=%d %d %d %d %d %d\n",type[0],
              type[1],type[2],type[3],type[4],type[5]);
        return 0;
    }
    /* test word type 0 time field */
    if (time_f!=2) {
        trace(3,"decode_gal_inav error: word0-time=%d\n",time_f);
        return 0;
    }
    /* test consistency of iod_nav */
    if (iod_nav[0]!=iod_nav[1]||iod_nav[0]!=iod_nav[2]||iod_nav[0]!=iod_nav[3]) {
        trace(3,"decode_gal_inav error: ionav=%d %d %d %d\n",iod_nav[0],
              iod_nav[1],iod_nav[2],iod_nav[3]);
        return 0;
    }
    if (!(eph->sat=satno(SYS_GAL,svid))) {
        trace(2,"decode_gal_inav svid error: svid=%d\n",svid);
        return 0;
    }
    eph->A=sqrtA*sqrtA;
    eph->iode=eph->iodc=iod_nav[0];
    eph->svh=(e5b_hs<<7)|(e5b_dvs<<6)|(e1b_hs<<1)|e1b_dvs;
    eph->ttr=gst2time(week,tow);
    tt=timediff(gst2time(week,eph->toes),eph->ttr); /* week complient to toe */
    if      (tt> 302400.0) week--;
    else if (tt<-302400.0) week++;
    eph->toe=gst2time(week,eph->toes);
    eph->toc=gst2time(week,toc);
    eph->week=week+1024; /* gal-week = gst-week + 1024 */
    eph->code =(1<<0)|(1<<9); /* data source = i/nav e1b, af0-2,toc,sisa for e5b-e1 */
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r13
pushq $0x6
popq %r15
xorl %esi, %esi
movl %r15d, %edx
callq 0x459f7
movl %eax, -0x38(%rbp)
pushq $0x2
popq %rdx
movq %r13, %rdi
movl %r15d, %esi
callq 0x459f7
movl %eax, -0x64(%rbp)
pushq $0x60
popq %rsi
pushq $0xc
popq %rdx
movq %r13, %rdi
callq 0x459f7
movl %eax, -0x50(%rbp)
pushq $0x6c
popq %rsi
pushq $0x14
popq %rdx
movq %r13, %rdi
callq 0x459f7
movl %eax, -0x4c(%rbp)
movq %r13, %rdi
movl $0x80, %esi
movl %r15d, %edx
callq 0x459f7
movl %eax, -0x70(%rbp)
pushq $0xa
popq %r12
movq %r13, %rdi
movl $0x86, %esi
movl %r12d, %edx
callq 0x459f7
movl %eax, -0x60(%rbp)
pushq $0xe
popq %rdx
movq %r13, %rdi
movl $0x90, %esi
callq 0x459f7
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x32dcc(%rip), %xmm0    # 0x608a8
movsd %xmm0, 0xc8(%rbx)
pushq $0x20
popq %r14
movq %r13, %rdi
movl $0x9e, %esi
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x351b4(%rip), %xmm0    # 0x62cb8
mulsd 0x3429c(%rip), %xmm0    # 0x61da8
movsd %xmm0, 0x78(%rbx)
movq %r13, %rdi
movl $0xbe, %esi
movl %r14d, %edx
callq 0x459f7
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd 0x35190(%rip), %xmm0    # 0x62cc0
movsd %xmm0, 0x58(%rbx)
movq %r13, %rdi
movl $0xde, %esi
movl %r14d, %edx
callq 0x459f7
movl %eax, -0x48(%rbp)
movq %r13, %rdi
movl $0x100, %esi            # imm = 0x100
movl %r15d, %edx
callq 0x459f7
movl %eax, -0x6c(%rbp)
movq %r13, %rdi
movl $0x106, %esi            # imm = 0x106
movl %r12d, %edx
callq 0x459f7
movl %eax, -0x5c(%rbp)
movq %r13, %rdi
movl $0x110, %esi            # imm = 0x110
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x3512e(%rip), %xmm0    # 0x62cb8
mulsd 0x34216(%rip), %xmm0    # 0x61da8
movsd %xmm0, 0x68(%rbx)
movq %r13, %rdi
movl $0x130, %esi            # imm = 0x130
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x35105(%rip), %xmm0    # 0x62cb8
mulsd 0x341ed(%rip), %xmm0    # 0x61da8
movsd %xmm0, 0x60(%rbx)
movq %r13, %rdi
movl $0x150, %esi            # imm = 0x150
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x350dc(%rip), %xmm0    # 0x62cb8
mulsd 0x341c4(%rip), %xmm0    # 0x61da8
movsd %xmm0, 0x70(%rbx)
movq %r13, %rdi
movl $0x170, %esi            # imm = 0x170
pushq $0xe
popq %rdx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x350cb(%rip), %xmm0    # 0x62cd0
mulsd 0x3419b(%rip), %xmm0    # 0x61da8
movsd %xmm0, 0x90(%rbx)
movq %r13, %rdi
movl $0x180, %esi            # imm = 0x180
movl %r15d, %edx
callq 0x459f7
movl %eax, -0x68(%rbp)
movq %r13, %rdi
movl $0x186, %esi            # imm = 0x186
movl %r12d, %edx
callq 0x459f7
movl %eax, -0x58(%rbp)
pushq $0x18
popq %rdx
movq %r13, %rdi
movl $0x190, %esi            # imm = 0x190
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x35079(%rip), %xmm0    # 0x62cd0
mulsd 0x34149(%rip), %xmm0    # 0x61da8
movsd %xmm0, 0x88(%rbx)
pushq $0x10
popq %r14
movq %r13, %rdi
movl $0x1a8, %esi            # imm = 0x1A8
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x35049(%rip), %xmm0    # 0x62cd0
mulsd 0x34119(%rip), %xmm0    # 0x61da8
movsd %xmm0, 0x80(%rbx)
movq %r13, %rdi
movl $0x1b8, %esi            # imm = 0x1B8
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x35025(%rip), %xmm0    # 0x62cd8
movsd %xmm0, 0xa8(%rbx)
movq %r13, %rdi
movl $0x1c8, %esi            # imm = 0x1C8
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x35001(%rip), %xmm0    # 0x62cd8
movsd %xmm0, 0xb0(%rbx)
movq %r13, %rdi
movl $0x1d8, %esi            # imm = 0x1D8
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34fe5(%rip), %xmm0    # 0x62ce0
movsd %xmm0, 0x98(%rbx)
movq %r13, %rdi
movl $0x1e8, %esi            # imm = 0x1E8
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34fc1(%rip), %xmm0    # 0x62ce0
movsd %xmm0, 0xa0(%rbx)
pushq $0x8
popq %rdx
movq %r13, %rdi
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x459f7
movl %eax, 0xc(%rbx)
movq %r13, %rdi
movl $0x200, %esi            # imm = 0x200
movl %r15d, %edx
callq 0x459f7
movq %rax, -0x78(%rbp)
movq %r13, %rdi
movl $0x206, %esi            # imm = 0x206
movl %r12d, %edx
callq 0x459f7
movl %eax, -0x54(%rbp)
movq %r13, %rdi
movl $0x210, %esi            # imm = 0x210
movl %r15d, %edx
callq 0x459f7
movl %eax, -0x2c(%rbp)
movq %r13, %rdi
movl $0x216, %esi            # imm = 0x216
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34f48(%rip), %xmm0    # 0x62cd8
movsd %xmm0, 0xb8(%rbx)
movq %r13, %rdi
movl $0x226, %esi            # imm = 0x226
movl %r14d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34f24(%rip), %xmm0    # 0x62cd8
movsd %xmm0, 0xc0(%rbx)
movq %r13, %rdi
movl $0x236, %esi            # imm = 0x236
pushq $0xe
popq %rdx
callq 0x459f7
movl %eax, -0x44(%rbp)
pushq $0x1f
popq %rdx
movq %r13, %rdi
movl $0x244, %esi            # imm = 0x244
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34efd(%rip), %xmm0    # 0x62ce8
movsd %xmm0, 0xd8(%rbx)
pushq $0x15
popq %rdx
movq %r13, %rdi
movl $0x263, %esi            # imm = 0x263
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34ee1(%rip), %xmm0    # 0x62cf0
movsd %xmm0, 0xe0(%rbx)
movq %r13, %rdi
movl $0x278, %esi            # imm = 0x278
movl %r15d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34ec5(%rip), %xmm0    # 0x62cf8
movsd %xmm0, 0xe8(%rbx)
movq %r13, %rdi
movl $0x280, %esi            # imm = 0x280
movl %r15d, %edx
callq 0x459f7
movl %eax, %r15d
movq %r13, %rdi
movl $0x2af, %esi            # imm = 0x2AF
movl %r12d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34e96(%rip), %xmm0    # 0x62d00
movsd %xmm0, 0xf0(%rbx)
movq %r13, %rdi
movl $0x2b9, %esi            # imm = 0x2B9
movl %r12d, %edx
callq 0x45a39
cvtsi2sd %eax, %xmm0
mulsd 0x34e72(%rip), %xmm0    # 0x62d00
movsd %xmm0, 0xf8(%rbx)
movq %r13, %rdi
movl $0x2c3, %esi            # imm = 0x2C3
pushq $0x2
popq %r14
movl %r14d, %edx
callq 0x459f7
movl %eax, -0x40(%rbp)
movq %r13, %rdi
movl $0x2c5, %esi            # imm = 0x2C5
movl %r14d, %edx
callq 0x459f7
movl %eax, -0x3c(%rbp)
pushq $0x1
popq %r14
movq %r13, %rdi
movl $0x2c7, %esi            # imm = 0x2C7
movl %r14d, %edx
callq 0x459f7
movl %eax, %r12d
movq %r13, %rdi
movl $0x2c8, %esi            # imm = 0x2C8
movl %r14d, %edx
callq 0x459f7
movq -0x78(%rbp), %r10
movl -0x68(%rbp), %r9d
movl -0x6c(%rbp), %r8d
movl -0x70(%rbp), %ecx
movl -0x38(%rbp), %edx
movl %eax, %r13d
movl %ecx, %eax
xorl $0x1, %eax
orl %edx, %eax
movl %r8d, %edi
xorl $0x2, %edi
movl %r9d, %esi
xorl $0x3, %esi
orl %edi, %esi
orl %eax, %esi
movl %r10d, %eax
xorl $0x4, %eax
orl %esi, %eax
movl %r15d, %esi
xorl $0x5, %esi
orl %eax, %esi
je 0x2df44
leaq 0x3505c(%rip), %rsi     # 0x62f88
pushq $0x3
popq %rdi
xorl %eax, %eax
pushq %r15
pushq %r10
callq 0x455bc
popq %rax
popq %rcx
xorl %r14d, %r14d
jmp 0x2e0c0
movl -0x64(%rbp), %edx
cmpl $0x2, %edx
jne 0x2e02d
movl -0x60(%rbp), %r15d
movl %r15d, %eax
movl -0x5c(%rbp), %ecx
xorl %ecx, %eax
movl %r15d, %edx
movl -0x58(%rbp), %r8d
xorl %r8d, %edx
orl %eax, %edx
movl %r15d, %eax
movl -0x54(%rbp), %r9d
xorl %r9d, %eax
orl %edx, %eax
jne 0x2e043
pushq $0x8
popq %rdi
movl -0x2c(%rbp), %esi
callq 0x452fd
movl %eax, (%rbx)
testl %eax, %eax
je 0x2e05c
movl -0x4c(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x48(%rbp), %eax
cvtsi2sd %rax, %xmm1
mulsd 0x34d21(%rip), %xmm1    # 0x62cc8
movl -0x44(%rbp), %eax
cvtsi2sd %rax, %xmm2
mulsd 0x328f1(%rip), %xmm2    # 0x608a8
movsd %xmm2, -0x38(%rbp)
mulsd %xmm1, %xmm1
movsd %xmm1, 0x50(%rbx)
movl %r15d, 0x8(%rbx)
movl %r15d, 0x4(%rbx)
movl -0x40(%rbp), %eax
shll $0x7, %eax
shll $0x6, %r12d
movl -0x3c(%rbp), %ecx
addl %ecx, %ecx
orl %eax, %ecx
orl %r13d, %r12d
orl %ecx, %r12d
movl %r12d, 0x10(%rbx)
movl -0x50(%rbp), %r15d
movl %r15d, %edi
callq 0x47156
movq %rax, 0x40(%rbx)
movsd %xmm0, 0x48(%rbx)
movsd 0xc8(%rbx), %xmm0
movl %r15d, %edi
callq 0x47156
movq 0x40(%rbx), %rsi
movsd 0x48(%rbx), %xmm1
movq %rax, %rdi
callq 0x47322
ucomisd 0x33da2(%rip), %xmm0    # 0x61dc8
jbe 0x2e06e
decl %r15d
jmp 0x2e07f
leaq 0x34f83(%rip), %rsi     # 0x62fb7
xorl %r14d, %r14d
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x455bc
jmp 0x2e0c0
leaq 0x34f93(%rip), %rsi     # 0x62fdd
xorl %r14d, %r14d
pushq $0x3
popq %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x455bc
jmp 0x2e0c0
leaq 0x34fa4(%rip), %rsi     # 0x63007
xorl %r14d, %r14d
pushq $0x2
popq %rdi
movl -0x2c(%rbp), %edx
jmp 0x2e03a
movsd 0x33d4a(%rip), %xmm1    # 0x61dc0
ucomisd %xmm0, %xmm1
jbe 0x2e07f
incl %r15d
movsd 0xc8(%rbx), %xmm0
movl %r15d, %edi
callq 0x47156
movq %rax, 0x20(%rbx)
movsd %xmm0, 0x28(%rbx)
movl %r15d, %edi
movsd -0x38(%rbp), %xmm0
callq 0x47156
movq %rax, 0x30(%rbx)
movsd %xmm0, 0x38(%rbx)
addl $0x400, %r15d           # imm = 0x400
movl %r15d, 0x14(%rbx)
movl $0x201, 0x18(%rbx)      # imm = 0x201
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq