// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: detide_(double*, int*, double*, double*, double*, double*)
int detide_(double *xsta, int *mjd, double *fmjd,
         double *xsun, double *xmon, double *dxtide)
{
    /* Initialized data */

    static double h20 = .6078;
    static double l20 = .0847;
    static double h3 = .292;
    static double l3 = .015;

    /* F2C generated locals */
    double d__1, d__2;

    /* Local variables */
    static double mass_ratio_moon__;
    static double rsta, rmon, rsun, p2mon, p3mon, x2mon, x3mon, p2sun, p3sun;
    static int i;
    static double x2sun, x3sun;
    static double t, scmon;
    static double h2, scsun, l2;
    static double re, cosphi, dmjdtt, fmjdtt, tsectt;
    static double fac2mon, fac3mon, fac2sun, fac3sun;
    static double mass_ratio_sun__;
    static double fhr, scm, scs, tsecgps, xcorsta[3];

    static double sinphi;
    static double cosla, sinla;
    static double dr, dn;

    if(xsta == 0) return (-1);
    if(mjd == 0) return (-1); 
    if(fmjd == 0) return (-1); 
    if(xsun == 0) return (-1); 
    if(xmon == 0) return (-1); 
    if(dxtide == 0) return (-1); 

/* computation of tidal corrections of station displacements caused */
/*    by lunar and solar gravitational attraction */
/* step 1 (here general degree 2 and 3 corrections + */
/*         call st1idiu + call st1isem + call st1l1) */
/*   + step 2 (call step2diu + call step2lon + call step2idiu) */
/* it has been decided that the step 3 un-correction for permanent tide */
/* would *not* be applied in order to avoid jump in the reference frame */
/*** (this step 3 must added in order to get the mean tide station position*/
/* and to be conformed with the iag resolution.) */
/* inputs */
/***   xsta(i),i=1,2,3   -- geocentric position of the station (ITRF/ECEF)
*/
/*   xsun(i),i=1,2,3   -- geoc. position of the sun (ECEF) */
/*   xmon(i),i=1,2,3   -- geoc. position of the moon (ECEF) */
/***   mjd,fmjd          -- modified julian day (and fraction) (in GPS time)*/
/****old calling sequence****************************************************/
/***   dmjd               -- time in mean julian date (including day fract
ion)*/
/*   fhr=hr+zmin/60.+sec/3600.   -- hr in the day */
/* outputs */
/*   dxtide(i),i=1,2,3           -- displacement vector (ITRF) */
/* author iers 1996 :  v. dehant, s. mathews and j. gipson */
/*    (test between two subroutines) */
/* author iers 2000 :  v. dehant, c. bruyninx and s. mathews */
/*    (test in the bernese program by c. bruyninx) */
/* created:  96/03/23 (see above) */
/* modified from dehanttideinelMJD.f by Dennis Milbert 2006sep10 */
/* bug fix regarding fhr (changed calling sequence, too) */
/* modified to reflect table 7.5a and b IERS Conventions 2003 */
/* modified to use TT time system to call step 2 functions */
/* sign correction by V.Dehant to match eq.16b, p.81, Conventions */
/* applied by Dennis Milbert 2007may05 */
/*** nominal second degree and third degree love numbers and shida numbers
*/
    /* Function Body */
/* internal support for new calling sequence */
/* also convert GPS time into TT time */
    tsecgps = *fmjd * 86400.;
/* *** GPS time (sec of */
    tsectt = gps2tt_(&tsecgps);
/* *** TT  time (sec of */
    fmjdtt = tsectt / 86400.;
/* *** TT  time (fract. */
    dmjdtt = *mjd + fmjdtt;
/* commented line was live code in dehanttideinelMJD.f */
/* changed on the suggestion of Dr. Don Kim, UNB -- 09mar21 */
/* Julian date for 2000 January 1 00:00:00.0 UT is  JD 2451544.5 */
/* MJD         for 2000 January 1 00:00:00.0 UT is MJD   51544.0 */
/***** t=(dmjdtt-51545.d0)/36525.d0                !*** days to centuries,
 TT*/
/* *** float MJD in TT */
    t = (dmjdtt - 51544.) / 36525.;
/* *** days to centuries */
    fhr = (dmjdtt - (int) dmjdtt) * 24.;
/* scalar product of station vector with sun/moon vector */
/* *** hours in the day, */
    sprod_(&xsta[0], &xsun[0], &scs, &rsta, &rsun);
    sprod_(&xsta[0], &xmon[0], &scm, &rsta, &rmon);
    scsun = scs / rsta / rsun;
    scmon = scm / rsta / rmon;
/* computation of new h2 and l2 */
    cosphi = sqrt(xsta[0] * xsta[0] + xsta[1] * xsta[1]) / rsta;
    h2 = h20 - (1. - cosphi * 1.5 * cosphi) * 6e-4;
    l2 = l20 + (1. - cosphi * 1.5 * cosphi) * 2e-4;
/* p2-term */
    p2sun = (h2 / 2. - l2) * 3. * scsun * scsun - h2 / 2.;
    p2mon = (h2 / 2. - l2) * 3. * scmon * scmon - h2 / 2.;
/* p3-term */
/* Computing 3rd power */
    d__1 = scsun, d__2 = d__1;
    p3sun = (h3 - l3 * 3.) * 2.5 * (d__2 * (d__1 * d__1)) + (l3 - h3) * 1.5 * 
            scsun;
/* Computing 3rd power */
    d__1 = scmon, d__2 = d__1;
    p3mon = (h3 - l3 * 3.) * 2.5 * (d__2 * (d__1 * d__1)) + (l3 - h3) * 1.5 * 
            scmon;
/* term in direction of sun/moon vector */
    x2sun = l2 * 3. * scsun;
    x2mon = l2 * 3. * scmon;
    x3sun = l3 * 3. / 2. * (scsun * 5. * scsun - 1.);
    x3mon = l3 * 3. / 2. * (scmon * 5. * scmon - 1.);
/* factors for sun/moon */
    mass_ratio_sun__ = 332945.943062;
    mass_ratio_moon__ = .012300034;
    re = 6378136.55;
/* Computing 3rd power */
    d__1 = re / rsun, d__2 = d__1;
    fac2sun = mass_ratio_sun__ * re * (d__2 * (d__1 * d__1));
/* Computing 3rd power */
    d__1 = re / rmon, d__2 = d__1;
    fac2mon = mass_ratio_moon__ * re * (d__2 * (d__1 * d__1));
    fac3sun = fac2sun * (re / rsun);
    fac3mon = fac2mon * (re / rmon);
/* total displacement */
    for(i=0; i<=2; ++i) {
        dxtide[i] = fac2sun * (x2sun * xsun[i] / rsun + p2sun * xsta[i] / 
                rsta) + fac2mon * (x2mon * xmon[i] / rmon + p2mon * xsta[i] / 
                rsta) + fac3sun * (x3sun * xsun[i] / rsun + p3sun * xsta[i] / 
                rsta) + fac3mon * (x3mon * xmon[i] / rmon + p3mon * xsta[i] / 
                rsta);
    }
    zero_vec8__(xcorsta);

/* corrections for the out-of-phase part of love numbers */
/*     (part h_2^(0)i and l_2^(0)i ) */
/* first, for the diurnal band */
    st1idiu_(&xsta[0], &xsun[0], &xmon[0], &fac2sun, &fac2mon, xcorsta);
    dxtide[0] += xcorsta[0];
    dxtide[1] += xcorsta[1];
    dxtide[2] += xcorsta[2];
/* second, for the semi-diurnal band */
    st1isem_(&xsta[0], &xsun[0], &xmon[0], &fac2sun, &fac2mon, xcorsta);
    dxtide[0] += xcorsta[0];
    dxtide[1] += xcorsta[1];
    dxtide[2] += xcorsta[2];
/*** corrections for the latitude dependence of love numbers (part l^(1) ) */
    st1l1_(&xsta[0], &xsun[0], &xmon[0], &fac2sun, &fac2mon, xcorsta);
    dxtide[0] += xcorsta[0];
    dxtide[1] += xcorsta[1];
    dxtide[2] += xcorsta[2];

/* consider corrections for step 2 */
/* corrections for the diurnal band: */
/*  first, we need to know the date converted in julian centuries */
/***  this is now handled at top of code   (also convert to TT time system) */
/* **** t=(dmjd-51545.)/36525. */
/***** fhr=dmjd-int(dmjd)             !*** this is/was a buggy line (day vs. hr) */
/*  second, the diurnal band corrections, */
/*   (in-phase and out-of-phase frequency dependence): */
    step2diu_(&xsta[0], &fhr, &t, xcorsta);
    dxtide[0] += xcorsta[0];
    dxtide[1] += xcorsta[1];
    dxtide[2] += xcorsta[2];
/*  corrections for the long-period band, */
/*   (in-phase and out-of-phase frequency dependence): */
    step2lon_(&xsta[0], &fhr, &t, xcorsta);
    dxtide[0] += xcorsta[0];
    dxtide[1] += xcorsta[1];
    dxtide[2] += xcorsta[2];

/* consider corrections for step 3 */
/* ----------------------------------------------------------------------- */
/* The code below is commented to prevent restoring deformation */
/* due to permanent tide.  All the code above removes */
/* total tidal deformation with conventional Love numbers. */
/* The code above realizes a conventional tide free crust (i.e. ITRF). */
/* This does NOT conform to Resolution 16 of the 18th General Assembly */
/* of the IAG (1983).  This resolution has not been implemented by */
/* the space geodesy community in general (c.f. IERS Conventions 2003). */

/* ----------------------------------------------------------------------- */
/*** uncorrect for the permanent tide  (only if you want mean tide system)
*/
   if(tide_options & CALC_MEAN_TIDES) {
       sinphi = xsta[2] / rsta;
       cosphi = sqrt((xsta[0]*xsta[0])  + (xsta[1]*xsta[1])) / rsta;
       cosla = xsta[0] / cosphi / rsta;
       sinla = xsta[0] / cosphi / rsta;
       dr = -sqrt(5./4./PI) * h2 * 0.31460 * (3./2. * (sinphi*sinphi) - 0.5);
       dn = -sqrt(5./4./PI) * l2 * 0.31460 * 3. * cosphi*sinphi;
       dxtide[0] = dxtide[0]-dr*cosla*cosphi+dn*cosla*sinphi;
       dxtide[1] = dxtide[1]-dr*sinla*cosphi+dn*sinla*sinphi;
       dxtide[2] = dxtide[2]-dr*sinphi-dn*cosphi;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r12
movq %rdi, %r14
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testq %rdx, %rdx
sete %al
testq %r12, %r12
sete %dil
orb %al, %dil
orb %cl, %dil
testq %r8, %r8
sete %al
testq %r9, %r9
sete %cl
orb %al, %cl
orb %dil, %cl
je 0xd7799
pushq $-0x1
popq %rax
jmp 0xd7dcd
movq %r9, %rbx
movq %r8, %r15
movsd 0x1b871(%rip), %xmm0    # 0xf3018
movsd (%rdx), %xmm1
mulsd %xmm0, %xmm1
addsd 0x3e9d9(%rip), %xmm1    # 0x116190
divsd %xmm0, %xmm1
cvtsi2sdl (%rsi), %xmm0
addsd %xmm1, %xmm0
movsd 0x3eb65(%rip), %xmm1    # 0x116330
addsd %xmm0, %xmm1
divsd 0x3dfa1(%rip), %xmm1    # 0x115778
movsd %xmm1, 0x28ddb9(%rip)   # 0x365598
cvttpd2dq %xmm0, %xmm1
cvtdq2pd %xmm1, %xmm1
subsd %xmm1, %xmm0
mulsd 0x1b84d(%rip), %xmm0    # 0xf3040
movsd %xmm0, 0x28ddc5(%rip)   # 0x3655c0
leaq 0x28ddce(%rip), %rdx    # 0x3655d0
leaq 0x28dd77(%rip), %r13    # 0x365580
leaq 0x28dd80(%rip), %r8     # 0x365590
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rcx
callq 0xd7f05
leaq 0x28dda3(%rip), %rdx    # 0x3655c8
leaq 0x28dd5c(%rip), %r8     # 0x365588
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0xd7f05
movsd 0x28dd8d(%rip), %xmm8   # 0x3655d0
movsd 0x28dd35(%rip), %xmm0   # 0x365580
divsd %xmm0, %xmm8
movsd 0x28dd37(%rip), %xmm9   # 0x365590
divsd %xmm9, %xmm8
movsd 0x28dd61(%rip), %xmm10  # 0x3655c8
divsd %xmm0, %xmm10
movsd 0x28dd14(%rip), %xmm7   # 0x365588
divsd %xmm7, %xmm10
movsd (%r14), %xmm1
movsd 0x8(%r14), %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
sqrtsd %xmm1, %xmm1
divsd %xmm0, %xmm1
movsd 0x3e520(%rip), %xmm2    # 0x115dc0
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd 0x1b7c0(%rip), %xmm2    # 0xf3070
movsd 0x3ea80(%rip), %xmm3    # 0x116338
mulsd %xmm2, %xmm3
addsd 0x3ea7c(%rip), %xmm3    # 0x116340
movsd %xmm3, 0x28dcd4(%rip)   # 0x3655a0
mulsd 0x3ea74(%rip), %xmm2    # 0x116348
addsd 0x3ea74(%rip), %xmm2    # 0x116350
mulsd 0x1b784(%rip), %xmm3    # 0xf3068
movapd %xmm3, %xmm0
subsd %xmm2, %xmm0
movsd 0x1e18b(%rip), %xmm11   # 0xf5a80
mulsd %xmm11, %xmm0
movapd %xmm8, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm8, %xmm1
subsd %xmm3, %xmm1
movsd %xmm1, -0x38(%rbp)
mulsd %xmm10, %xmm0
mulsd %xmm10, %xmm0
subsd %xmm3, %xmm0
movsd %xmm0, -0x40(%rbp)
movapd %xmm8, %xmm0
mulsd %xmm8, %xmm0
mulsd %xmm8, %xmm0
movsd 0x3ea1c(%rip), %xmm12   # 0x116358
movapd %xmm8, %xmm3
movsd 0x1b7f7(%rip), %xmm5    # 0xf3140
movapd %xmm8, %xmm6
mulsd %xmm5, %xmm6
mulsd %xmm8, %xmm6
mulsd %xmm12, %xmm8
movsd 0x3e9fb(%rip), %xmm13   # 0x116360
mulsd %xmm13, %xmm0
addsd %xmm8, %xmm0
movsd %xmm0, -0x30(%rbp)
movapd %xmm10, %xmm8
mulsd %xmm10, %xmm8
mulsd %xmm10, %xmm8
mulsd %xmm13, %xmm8
movsd %xmm2, 0x28dc18(%rip)   # 0x3655a8
mulsd %xmm10, %xmm12
addsd %xmm12, %xmm8
mulsd %xmm11, %xmm2
mulsd %xmm2, %xmm3
mulsd %xmm10, %xmm2
movsd 0x1b747(%rip), %xmm11   # 0xf30f8
addsd %xmm11, %xmm6
movsd 0x3e9a9(%rip), %xmm12   # 0x116368
mulsd %xmm12, %xmm6
mulsd %xmm10, %xmm5
mulsd %xmm10, %xmm5
addsd %xmm11, %xmm5
movsd 0x3e994(%rip), %xmm10   # 0x116370
movapd %xmm10, %xmm11
divsd %xmm9, %xmm11
movapd %xmm11, %xmm9
mulsd %xmm11, %xmm9
mulsd %xmm11, %xmm9
mulsd 0x3e97a(%rip), %xmm9    # 0x116378
mulsd %xmm12, %xmm5
movsd %xmm9, 0x28dbac(%rip)   # 0x3655b8
divsd %xmm7, %xmm10
movapd %xmm10, %xmm7
mulsd %xmm10, %xmm7
mulsd %xmm10, %xmm7
mulsd 0x3e958(%rip), %xmm7    # 0x116380
movsd %xmm7, 0x28db80(%rip)   # 0x3655b0
mulsd %xmm11, %xmm9
mulsd %xmm10, %xmm7
xorl %eax, %eax
cmpq $0x3, %rax
je 0xd7b25
movsd (%r12,%rax,8), %xmm12
movapd %xmm3, %xmm13
mulsd %xmm12, %xmm13
movsd 0x28db31(%rip), %xmm15  # 0x365590
divsd %xmm15, %xmm13
movsd (%r14,%rax,8), %xmm10
movsd -0x38(%rbp), %xmm14
mulsd %xmm10, %xmm14
movsd 0x28db02(%rip), %xmm11  # 0x365580
divsd %xmm11, %xmm14
addsd %xmm13, %xmm14
movsd (%r15,%rax,8), %xmm13
movapd %xmm2, %xmm0
mulsd %xmm13, %xmm0
movsd 0x28dae9(%rip), %xmm4   # 0x365588
divsd %xmm4, %xmm0
movsd -0x40(%rbp), %xmm1
mulsd %xmm10, %xmm1
divsd %xmm11, %xmm1
addsd %xmm0, %xmm1
mulsd 0x28daf2(%rip), %xmm1   # 0x3655b0
mulsd 0x28daf1(%rip), %xmm14  # 0x3655b8
addsd %xmm1, %xmm14
mulsd %xmm6, %xmm12
divsd %xmm15, %xmm12
movsd -0x30(%rbp), %xmm0
mulsd %xmm10, %xmm0
divsd %xmm11, %xmm0
addsd %xmm12, %xmm0
mulsd %xmm9, %xmm0
addsd %xmm14, %xmm0
mulsd %xmm5, %xmm13
divsd %xmm4, %xmm13
mulsd %xmm8, %xmm10
divsd %xmm11, %xmm10
addsd %xmm13, %xmm10
mulsd %xmm7, %xmm10
addsd %xmm0, %xmm10
movsd %xmm10, (%rbx,%rax,8)
incq %rax
jmp 0xd7a3c
xorpd %xmm0, %xmm0
movapd %xmm0, 0x28daaf(%rip)   # 0x3655e0
andq $0x0, 0x28dab7(%rip)    # 0x3655f0
leaq 0x28daa0(%rip), %r9     # 0x3655e0
leaq 0x28da71(%rip), %rcx    # 0x3655b8
leaq 0x28da62(%rip), %r13    # 0x3655b0
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %r8
callq 0xd7fde
movsd 0x28da79(%rip), %xmm0   # 0x3655e0
addsd (%rbx), %xmm0
movsd %xmm0, (%rbx)
movsd 0x28da71(%rip), %xmm0   # 0x3655e8
addsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%rbx)
movsd 0x28da67(%rip), %xmm0   # 0x3655f0
addsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
leaq 0x28da15(%rip), %rcx    # 0x3655b8
movq %r13, %r8
leaq 0x28da33(%rip), %r9     # 0x3655e0
callq 0xd828f
movsd 0x28da26(%rip), %xmm0   # 0x3655e0
addsd (%rbx), %xmm0
movsd %xmm0, (%rbx)
movsd 0x28da1e(%rip), %xmm0   # 0x3655e8
addsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%rbx)
movsd 0x28da14(%rip), %xmm0   # 0x3655f0
addsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
leaq 0x28d9c2(%rip), %rcx    # 0x3655b8
movq %r13, %r8
leaq 0x28d9e0(%rip), %r13    # 0x3655e0
movq %r13, %r9
callq 0xd8582
movsd 0x28d9d0(%rip), %xmm0   # 0x3655e0
addsd (%rbx), %xmm0
movsd %xmm0, (%rbx)
movsd 0x28d9c8(%rip), %xmm0   # 0x3655e8
addsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%rbx)
movsd 0x28d9be(%rip), %xmm0   # 0x3655f0
addsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
leaq 0x28d97d(%rip), %r15    # 0x3655c0
leaq 0x28d94e(%rip), %r12    # 0x365598
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xd89e1
movsd 0x28d97d(%rip), %xmm0   # 0x3655e0
addsd (%rbx), %xmm0
movsd %xmm0, (%rbx)
movsd 0x28d975(%rip), %xmm0   # 0x3655e8
addsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%rbx)
movsd 0x28d96b(%rip), %xmm0   # 0x3655f0
addsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xd90fe
movsd 0x28d938(%rip), %xmm1   # 0x3655e0
addsd (%rbx), %xmm1
movsd %xmm1, (%rbx)
movsd 0x28d930(%rip), %xmm2   # 0x3655e8
addsd 0x8(%rbx), %xmm2
movsd %xmm2, 0x8(%rbx)
movsd 0x28d926(%rip), %xmm0   # 0x3655f0
addsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rbx)
leaq 0x21f3b1(%rip), %rcx    # 0x2f708c
xorl %eax, %eax
testb $0x2, (%rcx)
je 0xd7dcd
movsd 0x10(%r14), %xmm3
movsd 0x28d88b(%rip), %xmm8   # 0x365580
divsd %xmm8, %xmm3
movsd (%r14), %xmm4
movsd 0x8(%r14), %xmm5
mulsd %xmm5, %xmm5
movapd %xmm4, %xmm6
mulsd %xmm4, %xmm6
addsd %xmm5, %xmm6
sqrtsd %xmm6, %xmm5
divsd %xmm8, %xmm5
divsd %xmm5, %xmm4
movsd 0x3e65e(%rip), %xmm6    # 0x116388
movsd 0x28d86e(%rip), %xmm7   # 0x3655a0
mulsd %xmm6, %xmm7
movapd %xmm3, %xmm9
mulsd %xmm3, %xmm9
mulsd 0x1b36f(%rip), %xmm9    # 0xf30b8
addsd 0x1dcae(%rip), %xmm9    # 0xf5a00
mulsd 0x28d84e(%rip), %xmm6   # 0x3655a8
mulsd 0x3e62e(%rip), %xmm6    # 0x116390
divsd %xmm8, %xmm4
mulsd 0x1dd11(%rip), %xmm6    # 0xf5a80
mulsd %xmm5, %xmm6
mulsd %xmm3, %xmm6
mulsd 0x3e619(%rip), %xmm7    # 0x116398
mulsd %xmm9, %xmm7
movapd %xmm4, %xmm8
mulsd %xmm7, %xmm8
mulsd %xmm5, %xmm8
addsd %xmm8, %xmm1
mulsd %xmm6, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm1
movsd %xmm1, (%rbx)
addsd %xmm2, %xmm8
addsd %xmm4, %xmm8
movsd %xmm8, 0x8(%rbx)
mulsd %xmm3, %xmm7
addsd %xmm0, %xmm7
mulsd %xmm5, %xmm6
subsd %xmm6, %xmm7
movsd %xmm7, 0x10(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq