// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: sun_position(double)
double sun_position(double jd)
{
double n,x,e,l,dl,v;
int i;
double ecc;

//  ecc = 0.016718;
    ecc = orbit_eccentricity(jd);
    jd -= 2444238.5;

    n = (360.0/SOLAR_YEAR) * jd;
    i = (int) (n / 360.0);
    n = n - 360.0 * (double) i;
    x = n - 3.762863;
    if(x < 0.0) x += 360.0;
    x *= DEG_TO_RAD;
    e = x;

    i = 0;
    do {  // solve Keppler's equation
        dl = e - (ecc*sin(e)) - x;
        e  = e - (dl / (1.0 - (ecc*cos(e))));
        if(++i > 10) break;
    } while (fabs(dl) >= SMALL_FLOAT);

    v = (360.0 / PI) * atan(1.01686011182*tan(e/2));
    l = v + 282.596403;
    i = (int) (l / 360.0);
    l = l - 360.0 * (double) i;
    return l;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
callq 0x134200
movsd %xmm0, -0x48(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x5480f(%rip), %xmm1    # 0x18e748
subsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
movsd 0x547f6(%rip), %xmm0    # 0x18e740
mulsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x48bcf(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movsd -0x10(%rbp), %xmm1
cvtsi2sdl -0x3c(%rbp), %xmm0
movsd 0x547ba(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x54798(%rip), %xmm1    # 0x18e730
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x139fbd
movsd 0x48b7d(%rip), %xmm0    # 0x182b30
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd 0x376cb(%rip), %xmm0    # 0x171690
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x9080
movsd -0x70(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x68(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
subsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x96f0
movsd -0x60(%rbp), %xmm2
movsd -0x58(%rbp), %xmm1
movaps %xmm0, %xmm3
movsd -0x50(%rbp), %xmm0
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm3, %xmm2
movsd 0x34fd7(%rip), %xmm3    # 0x16f068
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0xa, %eax
jle 0x13a0b2
jmp 0x13a0d6
jmp 0x13a0b4
movsd -0x30(%rbp), %xmm0
movaps 0x351d0(%rip), %xmm1    # 0x16f290
pand %xmm1, %xmm0
movsd 0x48b2c(%rip), %xmm1    # 0x182bf8
ucomisd %xmm1, %xmm0
jae 0x139fe0
movsd -0x20(%rbp), %xmm0
movsd 0x3506d(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
callq 0x91b0
movaps %xmm0, %xmm1
movsd 0x54659(%rip), %xmm0    # 0x18e750
mulsd %xmm1, %xmm0
callq 0x92e0
movaps %xmm0, %xmm1
movsd 0x54515(%rip), %xmm0    # 0x18e620
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x544f4(%rip), %xmm0    # 0x18e610
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x489fd(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movsd -0x28(%rbp), %xmm1
cvtsi2sdl -0x3c(%rbp), %xmm0
movsd 0x545e8(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)