// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: calc_earth_tide(double)
void calc_earth_tide(double jd_gps)
{
    static double glad, fmjd, glod, tsec, xsta[3];
    static int lout;
    static double rsun[3], tdel2, etide[3];
    static int iloop;
    static double rmoon[3], x0, y0, z0;
    static double ut, vt, wt;
    static double xt, yt, zt;
    static double sec;
    static int mjd;
    static int ihr, imn, imo, idy, iyr;
    static double gla0, eht0, glo0;

    if((lat == 0.0) && (lon == 0)) return;

    stuff_1.pi = PI;
    stuff_1.pi2 = (PI+PI);
    stuff_1.rad = (180. / PI);

    fmjd = jd_gps - JD_MJD;
    mjd0 = (int) (jd_gps - JD_MJD);
    fmjd = fmjd - (double) mjd0;
    mjd = mjd0;

    gla0 = lat;
    glo0 = lon;
    eht0 = alt; // 0.0;

    geoxyz_(&gla0, &glo0, &eht0, &x0, &y0, &z0);
//sprintf(plot_title, "geo:%f %f %f  mjd0:%d  fmjd:%f", x0,y0,z0, mjd0,fmjd);
    xsta[0] = x0;
    xsta[1] = y0;
    xsta[2] = z0;

    sunxyz_(&mjd, &fmjd, rsun);
//sprintf(debug_text, "rsun:%f %f %f", rsun[0],rsun[1],rsun[2]);
    moonxyz_(&mjd, &fmjd, rmoon);
//sprintf(debug_text2, "rmoon:%f %f %f", rmoon[0],rmoon[1],rmoon[2]);
    detide_(xsta, &mjd, &fmjd, rsun, rmoon, etide);
//sprintf(debug_text3, "etide:%f %f %f", etide[0],etide[1],etide[2]);
    xt = etide[0];
    yt = etide[1];
    zt = etide[2];
    /* determine local geodetic horizon components (topocentric) */
    rge_(&gla0, &glo0, &ut, &vt, &wt, &xt, &yt, &zt);

    last_lat_tide = lat_tide;
    last_lon_tide = lon_tide;
    last_alt_tide = alt_tide;

    lat_tide = ut * 1000.0;  // millimeters
    lon_tide = vt * 1000.0;
    alt_tide = wt * 1000.0;
    have_tides = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movsd %xmm0, -0x8(%rbp)
leaq 0x22b53c(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x140c9e
jp 0x140c9e
leaq 0x22b52e(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x140c9e
jp 0x140c9e
jmp 0x140f3b
movsd 0x30922(%rip), %xmm0    # 0x1715c8
movsd %xmm0, 0x299a2a(%rip)   # 0x3da6d8
movsd 0x41ea2(%rip), %xmm0    # 0x182b58
movsd %xmm0, 0x299a22(%rip)   # 0x3da6e0
movsd 0x2e4ba(%rip), %xmm0    # 0x16f180
movsd %xmm0, 0x299a02(%rip)   # 0x3da6d0
movsd -0x8(%rbp), %xmm0
movsd 0x30935(%rip), %xmm1    # 0x171610
subsd %xmm1, %xmm0
movsd %xmm0, 0x299a11(%rip)   # 0x3da6f8
movsd -0x8(%rbp), %xmm0
movsd 0x3091c(%rip), %xmm1    # 0x171610
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x2999e6(%rip)    # 0x3da6e8
movsd 0x2999ee(%rip), %xmm0   # 0x3da6f8
cvtsi2sdl 0x2999d6(%rip), %xmm1 # 0x3da6e8
subsd %xmm1, %xmm0
movsd %xmm0, 0x2999da(%rip)   # 0x3da6f8
movl 0x2999c4(%rip), %eax    # 0x3da6e8
movl %eax, 0x299aae(%rip)    # 0x3da7d8
leaq 0x22b47f(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
movsd %xmm0, 0x299ab3(%rip)   # 0x3da7f0
leaq 0x22b474(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
movsd %xmm0, 0x299ab0(%rip)   # 0x3da800
leaq 0x22b469(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm0
movsd %xmm0, 0x299a95(%rip)   # 0x3da7f8
leaq 0x299a86(%rip), %rdi    # 0x3da7f0
leaq 0x299a8f(%rip), %rsi    # 0x3da800
leaq 0x299a80(%rip), %rdx    # 0x3da7f8
leaq 0x299a09(%rip), %rcx    # 0x3da788
leaq 0x299a0a(%rip), %r8     # 0x3da790
leaq 0x299a0b(%rip), %r9     # 0x3da798
callq 0x140f50
movsd 0x2999ee(%rip), %xmm0   # 0x3da788
movsd %xmm0, 0x29996e(%rip)   # 0x3da710
movsd 0x2999e6(%rip), %xmm0   # 0x3da790
movsd %xmm0, 0x299966(%rip)   # 0x3da718
movsd 0x2999de(%rip), %xmm0   # 0x3da798
movsd %xmm0, 0x29995e(%rip)   # 0x3da720
leaq 0x299a0f(%rip), %rdi    # 0x3da7d8
leaq 0x299928(%rip), %rsi    # 0x3da6f8
leaq 0x299959(%rip), %rdx    # 0x3da730
callq 0x1410d0
leaq 0x2999f5(%rip), %rdi    # 0x3da7d8
leaq 0x29990e(%rip), %rsi    # 0x3da6f8
leaq 0x29997f(%rip), %rdx    # 0x3da770
callq 0x141520
leaq 0x299913(%rip), %rdi    # 0x3da710
leaq 0x2999d4(%rip), %rsi    # 0x3da7d8
leaq 0x2998ed(%rip), %rdx    # 0x3da6f8
leaq 0x29991e(%rip), %rcx    # 0x3da730
leaq 0x299957(%rip), %r8     # 0x3da770
leaq 0x299930(%rip), %r9     # 0x3da750
callq 0x142370
movsd 0x299923(%rip), %xmm0   # 0x3da750
movsd %xmm0, 0x299983(%rip)   # 0x3da7b8
movsd 0x29991b(%rip), %xmm0   # 0x3da758
movsd %xmm0, 0x29997b(%rip)   # 0x3da7c0
movsd 0x299913(%rip), %xmm0   # 0x3da760
movsd %xmm0, 0x299973(%rip)   # 0x3da7c8
leaq 0x299994(%rip), %rdi    # 0x3da7f0
leaq 0x29999d(%rip), %rsi    # 0x3da800
leaq 0x299936(%rip), %rdx    # 0x3da7a0
leaq 0x299937(%rip), %rcx    # 0x3da7a8
leaq 0x299938(%rip), %r8     # 0x3da7b0
leaq 0x299939(%rip), %r9     # 0x3da7b8
leaq 0x29993a(%rip), %r10    # 0x3da7c0
leaq 0x29993b(%rip), %rax    # 0x3da7c8
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x1430b0
leaq 0x22b386(%rip), %rax    # 0x36c228
movsd (%rax), %xmm0
leaq 0x22b393(%rip), %rax    # 0x36c240
movsd %xmm0, (%rax)
leaq 0x22b378(%rip), %rax    # 0x36c230
movsd (%rax), %xmm0
leaq 0x22b385(%rip), %rax    # 0x36c248
movsd %xmm0, (%rax)
leaq 0x22b36a(%rip), %rax    # 0x36c238
movsd (%rax), %xmm0
leaq 0x22b377(%rip), %rax    # 0x36c250
movsd %xmm0, (%rax)
movsd 0x2e14b(%rip), %xmm0    # 0x16f030
mulsd 0x2998b3(%rip), %xmm0   # 0x3da7a0
leaq 0x22b334(%rip), %rax    # 0x36c228
movsd %xmm0, (%rax)
movsd 0x2e130(%rip), %xmm0    # 0x16f030
mulsd 0x2998a0(%rip), %xmm0   # 0x3da7a8
leaq 0x22b321(%rip), %rax    # 0x36c230
movsd %xmm0, (%rax)
movsd 0x2e115(%rip), %xmm0    # 0x16f030
mulsd 0x29988d(%rip), %xmm0   # 0x3da7b0
leaq 0x22b30e(%rip), %rax    # 0x36c238
movsd %xmm0, (%rax)
leaq 0x22b323(%rip), %rax    # 0x36c258
movl $0x1, (%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)