// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/rtkcmn.cpp
// Function: bamboo::geterp(bamboo::erp_t const*, bamboo::gtime_t, double*)
extern int geterp(const erp_t *erp, gtime_t time, double *erpv)
{
    const double ep[]={2000,1,1,12,0,0};
    double mjd,day,a;
    int i,j,k;
    
    trace(4,"geterp:\n");
    
    if (erp->n<=0) return 0;
    
    mjd=51544.5+(timediff(gpst2utc(time),epoch2time(ep)))/86400.0;
    
    if (mjd<=erp->data[0].mjd) {
        day=mjd-erp->data[0].mjd;
        erpv[0]=erp->data[0].xp     +erp->data[0].xpr*day;
        erpv[1]=erp->data[0].yp     +erp->data[0].ypr*day;
        erpv[2]=erp->data[0].ut1_utc-erp->data[0].lod*day;
        erpv[3]=erp->data[0].lod;
        return 1;
    }
    if (mjd>=erp->data[erp->n-1].mjd) {
        day=mjd-erp->data[erp->n-1].mjd;
        erpv[0]=erp->data[erp->n-1].xp     +erp->data[erp->n-1].xpr*day;
        erpv[1]=erp->data[erp->n-1].yp     +erp->data[erp->n-1].ypr*day;
        erpv[2]=erp->data[erp->n-1].ut1_utc-erp->data[erp->n-1].lod*day;
        erpv[3]=erp->data[erp->n-1].lod;
        return 1;
    }
    for (j=0,k=erp->n-1;j<k-1;) {
        i=(j+k)/2;
        if (mjd<erp->data[i].mjd) k=i; else j=i;
    }
    if (erp->data[j].mjd==erp->data[j+1].mjd) {
        a=0.5;
    }
    else {
        a=(mjd-erp->data[j].mjd)/(erp->data[j+1].mjd-erp->data[j].mjd);
    }
    erpv[0]=(1.0-a)*erp->data[j].xp     +a*erp->data[j+1].xp;
    erpv[1]=(1.0-a)*erp->data[j].yp     +a*erp->data[j+1].yp;
    erpv[2]=(1.0-a)*erp->data[j].ut1_utc+a*erp->data[j+1].ut1_utc;
    erpv[3]=(1.0-a)*erp->data[j].lod    +a*erp->data[j+1].lod;
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
xorpd %xmm1, %xmm1
movapd %xmm1, -0x40(%rbp)
movabsq $0x409f400000000000, %rax # imm = 0x409F400000000000
movq %rax, -0x60(%rbp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x58(%rbp)
movq %rax, -0x50(%rbp)
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, -0x48(%rbp)
movslq (%rdi), %r12
testq %r12, %r12
jle 0x49b7d
movq %rdx, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x47732
movq %rax, %r15
movsd %xmm0, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x46ee2
movsd %xmm0, -0x28(%rbp)
movq %r15, %rdi
movq %rax, %rsi
callq 0x8340
addsd -0x30(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
divsd 0x16d9e(%rip), %xmm0    # 0x608c0
addsd 0x21166(%rip), %xmm0    # 0x6ac90
movq 0x8(%r14), %rcx
movsd (%rcx), %xmm1
ucomisd %xmm0, %xmm1
jae 0x49b84
leal -0x1(%r12), %esi
imulq $0x38, %rsi, %rax
movsd (%rcx,%rax), %xmm1
ucomisd %xmm1, %xmm0
jae 0x49bca
xorl %edi, %edi
pushq $0x2
popq %r8
leal -0x1(%rsi), %eax
cmpl %eax, %edi
jge 0x49c1c
leal (%rdi,%rsi), %eax
cltd
idivl %r8d
cltq
imulq $0x38, %rax, %rdx
movsd (%rcx,%rdx), %xmm1
ucomisd %xmm0, %xmm1
cmoval %eax, %esi
cmoval %edi, %eax
movl %eax, %edi
jmp 0x49b52
xorl %eax, %eax
jmp 0x49cdd
subsd %xmm1, %xmm0
movsd 0x18(%rcx), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rcx), %xmm1
movsd %xmm1, (%rbx)
movsd 0x20(%rcx), %xmm1
mulsd %xmm0, %xmm1
addsd 0x10(%rcx), %xmm1
movsd %xmm1, 0x8(%rbx)
mulsd 0x30(%rcx), %xmm0
movsd 0x28(%rcx), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rbx)
movsd 0x30(%rcx), %xmm0
jmp 0x49cd5
addq %rcx, %rax
subsd %xmm1, %xmm0
movsd 0x18(%rax), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rax), %xmm1
movsd %xmm1, (%rbx)
imulq $0x38, %r12, %rax
movsd -0x18(%rcx,%rax), %xmm1
mulsd %xmm0, %xmm1
addsd -0x28(%rcx,%rax), %xmm1
movsd %xmm1, 0x8(%rbx)
mulsd -0x8(%rcx,%rax), %xmm0
movsd -0x10(%rcx,%rax), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rbx)
movsd -0x8(%rcx,%rax), %xmm0
jmp 0x49cd5
movslq %edi, %rax
imulq $0x38, %rax, %rax
movsd (%rcx,%rax), %xmm2
incl %edi
movslq %edi, %rdx
imulq $0x38, %rdx, %rdx
movsd (%rcx,%rdx), %xmm1
subsd %xmm2, %xmm0
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
divsd %xmm3, %xmm0
cmpeqsd %xmm1, %xmm2
movsd 0x18025(%rip), %xmm1    # 0x61c78
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm2, %xmm1
movsd 0x15cb9(%rip), %xmm0    # 0x5f920
subsd %xmm1, %xmm0
movsd 0x8(%rcx,%rdx), %xmm2
mulsd %xmm1, %xmm2
movsd 0x8(%rcx,%rax), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, (%rbx)
movsd 0x10(%rcx,%rdx), %xmm2
mulsd %xmm1, %xmm2
movsd 0x10(%rcx,%rax), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rbx)
movsd 0x28(%rcx,%rdx), %xmm2
mulsd %xmm1, %xmm2
movsd 0x28(%rcx,%rax), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x10(%rbx)
movsd 0x30(%rcx,%rdx), %xmm2
mulsd %xmm1, %xmm2
mulsd 0x30(%rcx,%rax), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x18(%rbx)
pushq $0x1
popq %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq