// File: /workspace/github_cpp_makefile_star2_O1/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, -0x60(%rbp)
movapd %xmm1, -0x50(%rbp)
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 0x52d26
movq %rdx, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x5034e
movq %rax, %r15
movsd %xmm0, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4f9a4
movsd %xmm0, -0x28(%rbp)
movq %r15, %rdi
movq %rax, %rsi
callq 0x8330
addsd -0x30(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
divsd 0x17ccf(%rip), %xmm0    # 0x6a8d0
addsd 0x220a7(%rip), %xmm0    # 0x74cb0
movq 0x8(%r14), %rax
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jae 0x52d2d
leaq -0x1(%r12), %rcx
imulq $0x38, %rcx, %rdx
movsd (%rax,%rdx), %xmm1
ucomisd %xmm1, %xmm0
jae 0x52d70
xorl %edx, %edx
cmpl $0x3, %r12d
jl 0x52c68
xorl %esi, %esi
leal (%rsi,%rcx), %edi
movl %edi, %edx
shrl $0x1f, %edx
addl %edi, %edx
sarl %edx
movslq %edx, %rdi
imulq $0x38, %rdi, %rdi
movsd (%rax,%rdi), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x52c5f
movl %edx, %ecx
movl %esi, %edx
leal -0x1(%rcx), %edi
movl %edx, %esi
cmpl %edi, %edx
jl 0x52c3d
movslq %edx, %rdx
imulq $0x38, %rdx, %rcx
movsd (%rax,%rcx), %xmm2
incl %edx
movslq %edx, %rdx
imulq $0x38, %rdx, %rdx
movsd (%rax,%rdx), %xmm1
subsd %xmm2, %xmm0
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
divsd %xmm3, %xmm0
cmpeqsd %xmm1, %xmm2
movsd 0x18fd9(%rip), %xmm1    # 0x6bc78
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm2, %xmm1
movsd 0x16c6d(%rip), %xmm0    # 0x69920
subsd %xmm1, %xmm0
movsd 0x8(%rax,%rdx), %xmm2
mulsd %xmm1, %xmm2
movsd 0x8(%rax,%rcx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, (%rbx)
movsd 0x10(%rax,%rdx), %xmm2
mulsd %xmm1, %xmm2
movsd 0x10(%rax,%rcx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rbx)
movsd 0x28(%rax,%rdx), %xmm2
mulsd %xmm1, %xmm2
movsd 0x28(%rax,%rcx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x10(%rbx)
movsd 0x30(%rax,%rdx), %xmm2
mulsd %xmm1, %xmm2
mulsd 0x30(%rax,%rcx), %xmm0
addsd %xmm2, %xmm0
jmp 0x52dbd
xorl %eax, %eax
jmp 0x52dc7
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 0x52dbd
addq %rax, %rdx
subsd %xmm1, %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