// File: /workspace/github_cpp_makefile_star2_O3/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 0x522fe
movq %rdx, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x4f9b0
movq %rax, %r15
movsd %xmm0, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4f027
movsd %xmm0, -0x28(%rbp)
movq %r15, %rdi
movq %rax, %rsi
callq 0x8330
addsd -0x30(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
divsd 0x18703(%rip), %xmm0    # 0x6a8d0
addsd 0x22abb(%rip), %xmm0    # 0x74c90
movq 0x8(%r14), %rax
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jae 0x52305
leal -0x1(%r12), %ecx
imulq $0x38, %rcx, %rdx
movsd (%rax,%rdx), %xmm2
ucomisd %xmm2, %xmm0
jae 0x52348
xorl %edx, %edx
cmpl $0x3, %r12d
jb 0x52240
xorl %edx, %edx
leal (%rdx,%rcx), %edi
movl %edi, %esi
shrl $0x1f, %esi
addl %edi, %esi
sarl %esi
movslq %esi, %rdi
imulq $0x38, %rdi, %rdi
movsd (%rax,%rdi), %xmm1
ucomisd %xmm0, %xmm1
ja 0x5222b
movl %esi, %edx
jmp 0x5222d
movl %esi, %ecx
leal -0x1(%rcx), %esi
cmpl %esi, %edx
jl 0x52209
movslq %edx, %rcx
imulq $0x38, %rcx, %rcx
movsd (%rax,%rcx), %xmm1
movslq %edx, %rdx
leal 0x1(%rdx), %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
movsd (%rax,%rcx), %xmm2
subsd %xmm1, %xmm0
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
divsd %xmm3, %xmm0
cmpeqsd %xmm2, %xmm1
movapd %xmm1, %xmm3
andnpd %xmm0, %xmm3
movsd 0x19a01(%rip), %xmm2    # 0x6bc78
andpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movsd 0x17699(%rip), %xmm0    # 0x69920
subsd %xmm2, %xmm0
imulq $0x38, %rdx, %rdx
movsd 0x8(%rax,%rcx), %xmm1
mulsd %xmm2, %xmm1
movsd 0x8(%rax,%rdx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd %xmm3, (%rbx)
movsd 0x10(%rax,%rcx), %xmm1
mulsd %xmm2, %xmm1
movsd 0x10(%rax,%rdx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd %xmm3, 0x8(%rbx)
movsd 0x28(%rax,%rcx), %xmm1
mulsd %xmm2, %xmm1
movsd 0x28(%rax,%rdx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd %xmm3, 0x10(%rbx)
movsd 0x30(%rax,%rcx), %xmm1
mulsd %xmm2, %xmm1
mulsd 0x30(%rax,%rdx), %xmm0
addsd %xmm1, %xmm0
jmp 0x52395
xorl %eax, %eax
jmp 0x5239f
subsd %xmm1, %xmm0
movsd 0x18(%rax), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rax), %xmm1
movsd %xmm1, (%rbx)
movsd 0x20(%rax), %xmm1
mulsd %xmm0, %xmm1
addsd 0x10(%rax), %xmm1
movsd %xmm1, 0x8(%rbx)
mulsd 0x30(%rax), %xmm0
movsd 0x28(%rax), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rbx)
movsd 0x30(%rax), %xmm0
jmp 0x52395
addq %rax, %rdx
subsd %xmm2, %xmm0
movsd 0x18(%rdx), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rdx), %xmm1
movsd %xmm1, (%rbx)
imulq $0x38, %r12, %rcx
movsd -0x18(%rax,%rcx), %xmm1
mulsd %xmm0, %xmm1
addsd -0x28(%rax,%rcx), %xmm1
movsd %xmm1, 0x8(%rbx)
mulsd -0x8(%rax,%rcx), %xmm0
movsd -0x10(%rax,%rcx), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rbx)
movsd -0x8(%rax,%rcx), %xmm0
movsd %xmm0, 0x18(%rbx)
movl $0x1, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq