// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rtklib/rtkcmn.cpp
// Function: bamboo::eci2ecef(bamboo::gtime_t, double const*, double*, double*)
extern void eci2ecef(gtime_t tutc, const double *erpv, double *U, double *gmst)
{
    const double ep2000[]={2000,1,1,12,0,0};
    static gtime_t tutc_;
    static double U_[9],gmst_;
    gtime_t tgps;
    double eps,ze,th,z,t,t2,t3,dpsi,deps,gast,f[5];
    double R1[9],R2[9],R3[9],R[9],W[9],N[9],P[9],NP[9];
    int i;
    
    trace(4,"eci2ecef: tutc=%s\n",time_str(tutc,3));
    
    if (fabs(timediff(tutc,tutc_))<0.01) { /* read cache */
        for (i=0;i<9;i++) U[i]=U_[i];
        if (gmst) *gmst=gmst_; 
        return;
    }
    tutc_=tutc;
    
    /* terrestrial time */
    tgps=utc2gpst(tutc_);
    t=(timediff(tgps,epoch2time(ep2000))+19.0+32.184)/86400.0/36525.0;
    t2=t*t; t3=t2*t;
    
    /* astronomical arguments */
    ast_args(t,f);
    
    /* iau 1976 precession */
    ze=(2306.2181*t+0.30188*t2+0.017998*t3)*AS2R;
    th=(2004.3109*t-0.42665*t2-0.041833*t3)*AS2R;
    z =(2306.2181*t+1.09468*t2+0.018203*t3)*AS2R;
    eps=(84381.448-46.8150*t-0.00059*t2+0.001813*t3)*AS2R;
    Rz(-z,R1); Ry(th,R2); Rz(-ze,R3);
    matmul("NN",3,3,3,1.0,R1,R2,0.0,R);
    matmul("NN",3,3,3,1.0,R, R3,0.0,P); /* P=Rz(-z)*Ry(th)*Rz(-ze) */
    
    /* iau 1980 nutation */
    nut_iau1980(t,f,&dpsi,&deps);
    Rx(-eps-deps,R1); Rz(-dpsi,R2); Rx(eps,R3);
    matmul("NN",3,3,3,1.0,R1,R2,0.0,R);
    matmul("NN",3,3,3,1.0,R ,R3,0.0,N); /* N=Rx(-eps)*Rz(-dspi)*Rx(eps) */
    
    /* greenwich aparent sidereal time (rad) */
    gmst_=utc2gmst(tutc_,erpv[2]);
    gast=gmst_+dpsi*cos(eps);
    gast+=(0.00264*sin(f[4])+0.000063*sin(2.0*f[4]))*AS2R;
    
    /* eci to ecef transformation matrix */
    Ry(-erpv[0],R1); Rx(-erpv[1],R2); Rz(gast,R3);
    matmul("NN",3,3,3,1.0,R1,R2,0.0,W );
    matmul("NN",3,3,3,1.0,W ,R3,0.0,R ); /* W=Ry(-xp)*Rx(-yp) */
    matmul("NN",3,3,3,1.0,N ,P ,0.0,NP);
    matmul("NN",3,3,3,1.0,R ,NP,0.0,U_); /* U=W*Rz(gast)*N*P */
    
    for (i=0;i<9;i++) U[i]=U_[i];
    if (gmst) *gmst=gmst_; 
    
    trace(5,"gmst=%.12f gast=%.12f\n",gmst_,gast);
    trace(5,"P=\n"); tracemat(5,P,3,3,15,12);
    trace(5,"N=\n"); tracemat(5,N,3,3,15,12);
    trace(5,"W=\n"); tracemat(5,W,3,3,15,12);
    trace(5,"U=\n"); tracemat(5,U,3,3,15,12);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r12
movsd %xmm0, -0x40(%rbp)
movq %rdi, %rbx
xorps %xmm1, %xmm1
movaps %xmm1, -0xb0(%rbp)
movaps %xmm1, -0xa0(%rbp)
movaps %xmm1, -0x90(%rbp)
movabsq $0x409f400000000000, %rax # imm = 0x409F400000000000
movq %rax, -0xb0(%rbp)
movabsq $0x3ff0000000000000, %r13 # imm = 0x3FF0000000000000
movq %r13, -0xa8(%rbp)
movq %r13, -0xa0(%rbp)
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, -0x98(%rbp)
leaq 0x40ca3(%rip), %rsi     # 0x91ff0
movl $0x3, %edx
callq 0x50696
movq 0x40cd2(%rip), %rsi     # 0x92030
movsd 0x40cd2(%rip), %xmm0    # 0x92038
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
callq 0x8330
movsd -0x40(%rbp), %xmm2
addsd %xmm2, %xmm0
subsd -0x30(%rbp), %xmm0
andpd 0x185a7(%rip), %xmm0    # 0x69930
movsd 0x1a42f(%rip), %xmm1    # 0x6b7c0
ucomisd %xmm0, %xmm1
jbe 0x513ba
xorl %eax, %eax
leaq 0x40ca0(%rip), %rcx     # 0x92040
movsd (%rax,%rcx), %xmm0
movsd %xmm0, (%r14,%rax)
addq $0x8, %rax
cmpq $0x48, %rax
jne 0x513a0
jmp 0x51bc5
movq %r12, -0x70(%rbp)
movq %r15, -0x78(%rbp)
movq %rbx, 0x40c67(%rip)     # 0x92030
movsd %xmm2, 0x40c67(%rip)    # 0x92038
movq %rbx, %rdi
movapd %xmm2, %xmm0
callq 0x5040e
movq %rax, %rbx
movsd %xmm0, -0x30(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4f9a4
movsd %xmm0, -0x40(%rbp)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8330
addsd -0x30(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
addsd 0x194b5(%rip), %xmm0    # 0x6a8c8
addsd 0x237f5(%rip), %xmm0    # 0x74c10
divsd 0x194ad(%rip), %xmm0    # 0x6a8d0
divsd 0x23795(%rip), %xmm0    # 0x74bc0
movsd %xmm0, -0x40(%rbp)
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movapd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm2, -0x60(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x51be9
movsd 0x237ba(%rip), %xmm0    # 0x74c18
movsd -0x50(%rbp), %xmm5
mulsd %xmm5, %xmm0
movsd 0x237b1(%rip), %xmm1    # 0x74c20
movsd -0x40(%rbp), %xmm4
mulsd %xmm4, %xmm1
addsd %xmm1, %xmm0
movsd 0x237a4(%rip), %xmm2    # 0x74c28
movapd -0x60(%rbp), %xmm3
mulsd %xmm3, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, -0x30(%rbp)
movsd 0x23792(%rip), %xmm0    # 0x74c30
mulsd %xmm5, %xmm0
movsd 0x2378e(%rip), %xmm2    # 0x74c38
mulsd %xmm4, %xmm2
addsd %xmm0, %xmm2
movsd 0x23786(%rip), %xmm0    # 0x74c40
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
mulsd 0x2377e(%rip), %xmm0    # 0x74c48
movsd %xmm0, -0x48(%rbp)
movsd 0x23779(%rip), %xmm0    # 0x74c50
movapd %xmm5, %xmm2
mulsd %xmm5, %xmm0
addsd %xmm1, %xmm0
movsd 0x2376d(%rip), %xmm1    # 0x74c58
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd 0x23765(%rip), %xmm0    # 0x74c60
mulsd %xmm4, %xmm0
addsd 0x23761(%rip), %xmm0    # 0x74c68
mulsd 0x23761(%rip), %xmm2    # 0x74c70
addsd %xmm0, %xmm2
movapd %xmm3, %xmm0
mulsd 0x23759(%rip), %xmm0    # 0x74c78
addsd %xmm2, %xmm0
movapd %xmm0, -0x60(%rbp)
leaq -0x218(%rbp), %rbx
movq %r13, 0x38(%rbx)
xorl %r12d, %r12d
movq %r12, 0x8(%rbx)
movapd %xmm1, %xmm0
mulsd 0x2373a(%rip), %xmm0    # 0x74c80
movsd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
movupd %xmm1, 0x20(%rbx)
movq %r12, 0x30(%rbx)
callq 0x8c00
movsd %xmm0, 0x18(%rbx)
movsd %xmm0, -0x8(%rbx)
movsd -0x50(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x10(%rbx)
xorps 0x19553(%rip), %xmm0    # 0x6aad0
movlps %xmm0, (%rbx)
leaq -0x128(%rbp), %rbx
movq %r13, -0x8(%rbx)
movq %r12, 0x10(%rbx)
movq %r12, (%rbx)
movq %r12, -0x10(%rbx)
movq %r12, -0x20(%rbx)
movsd -0x48(%rbp), %xmm0
callq 0x8c00
movsd %xmm0, 0x18(%rbx)
movsd %xmm0, -0x28(%rbx)
movsd -0x48(%rbp), %xmm0
callq 0x8150
movsd %xmm0, -0x18(%rbx)
xorps 0x1950c(%rip), %xmm0    # 0x6aad0
movlps %xmm0, 0x8(%rbx)
leaq -0xd8(%rbp), %rbx
movq %r13, 0x18(%rbx)
movq %r12, -0x18(%rbx)
movsd -0x30(%rbp), %xmm0
mulsd 0x2369c(%rip), %xmm0    # 0x74c80
movsd %xmm0, -0x30(%rbp)
xorpd %xmm1, %xmm1
movupd %xmm1, (%rbx)
movq %r12, 0x10(%rbx)
callq 0x8c00
movsd %xmm0, -0x8(%rbx)
movsd %xmm0, -0x28(%rbx)
movsd -0x30(%rbp), %xmm0
callq 0x8150
movsd %xmm0, -0x10(%rbx)
xorps 0x194b6(%rip), %xmm0    # 0x6aad0
movlps %xmm0, -0x20(%rbx)
leaq -0x1d0(%rbp), %r15
movq %r15, (%rsp)
leaq 0x23a57(%rip), %rbx     # 0x75087
movsd 0x182e8(%rip), %xmm2    # 0x69920
leaq -0x220(%rbp), %r8
leaq -0x150(%rbp), %r9
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movaps %xmm2, %xmm0
callq 0x4e91f
leaq -0x270(%rbp), %rax
movq %rax, (%rsp)
leaq -0x100(%rbp), %r9
xorpd %xmm1, %xmm1
movq %rbx, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x18284(%rip), %xmm0    # 0x69920
movq %r15, %r8
callq 0x4e91f
leaq 0x211e5(%rip), %rbx     # 0x72890
movq %rbx, %r13
xorpd %xmm3, %xmm3
movsd %xmm3, -0x48(%rbp)
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd (%r13,%rax,8), %xmm1
mulsd -0x180(%rbp,%rax,8), %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq $0x5, %rax
jne 0x516bd
leaq (%r12,%r12,4), %r15
shlq $0x4, %r15
movsd 0x38(%r15,%rbx), %xmm1
mulsd -0x40(%rbp), %xmm1
addsd 0x30(%r15,%rbx), %xmm1
movsd %xmm1, -0x68(%rbp)
movsd %xmm0, -0x50(%rbp)
callq 0x8150
mulsd -0x68(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0x48(%r15,%rbx), %xmm0
mulsd -0x40(%rbp), %xmm0
addsd 0x40(%r15,%rbx), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x8c00
mulsd -0x68(%rbp), %xmm0
movsd -0x48(%rbp), %xmm3
addsd %xmm0, %xmm3
incq %r12
addq $0x50, %r13
cmpq $0x6a, %r12
jne 0x516b2
movapd -0x60(%rbp), %xmm0
mulsd 0x234e3(%rip), %xmm0    # 0x74c48
movapd %xmm0, %xmm2
movapd %xmm0, -0x60(%rbp)
movsd 0x23512(%rip), %xmm0    # 0x74c88
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
mulsd %xmm0, %xmm3
leaq -0x220(%rbp), %r13
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%r13)
movq %rax, %r12
xorl %ebx, %ebx
movq %rbx, 0x30(%r13)
movapd 0x19322(%rip), %xmm0    # 0x6aad0
xorpd %xmm0, %xmm2
subsd %xmm3, %xmm2
movapd %xmm2, -0x40(%rbp)
leaq -0x218(%rbp), %rax
movq %rbx, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movapd %xmm2, %xmm0
callq 0x8c00
movsd %xmm0, 0x40(%r13)
movsd %xmm0, 0x20(%r13)
movaps -0x40(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x38(%r13)
xorps 0x192d7(%rip), %xmm0    # 0x6aad0
movlps %xmm0, 0x28(%r13)
leaq -0x150(%rbp), %r15
movq %r12, 0x40(%r15)
movq %rbx, 0x10(%r15)
leaq -0x128(%rbp), %rax
movq %rbx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
callq 0x8c00
movsd %xmm0, 0x20(%r15)
movsd %xmm0, (%r15)
movsd -0x30(%rbp), %xmm0
callq 0x8150
movaps %xmm0, %xmm1
xorps 0x19289(%rip), %xmm1    # 0x6aad0
movlps %xmm1, 0x18(%r15)
movsd %xmm0, 0x8(%r15)
leaq -0x100(%rbp), %r15
movq %r12, (%r15)
movq %rbx, 0x30(%r15)
leaq -0xd8(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movq %rbx, -0x10(%rax)
movaps -0x60(%rbp), %xmm0
callq 0x8c00
movsd %xmm0, 0x40(%r15)
movsd %xmm0, 0x20(%r15)
movaps -0x60(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x38(%r15)
xorps 0x19233(%rip), %xmm0    # 0x6aad0
movlps %xmm0, 0x28(%r15)
leaq -0x1d0(%rbp), %r12
movq %r12, (%rsp)
leaq 0x237d3(%rip), %r15     # 0x75087
movsd 0x18064(%rip), %xmm0    # 0x69920
xorps %xmm1, %xmm1
movq %r15, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movq %r13, %r8
leaq -0x150(%rbp), %r9
callq 0x4e91f
leaq -0x2c0(%rbp), %rax
movq %rax, (%rsp)
xorps %xmm1, %xmm1
movq %r15, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x18018(%rip), %xmm0    # 0x69920
movq %r12, %r8
leaq -0x100(%rbp), %r9
callq 0x4e91f
movq 0x40712(%rip), %rdi     # 0x92030
movsd 0x40712(%rip), %xmm0    # 0x92038
movq -0x70(%rbp), %r12
movsd 0x10(%r12), %xmm1
callq 0x50525
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, 0x40745(%rip)    # 0x92088
movapd -0x60(%rbp), %xmm0
callq 0x8c00
mulsd -0x30(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x160(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x8150
movsd %xmm0, -0x40(%rbp)
movsd -0x48(%rbp), %xmm0
addsd %xmm0, %xmm0
callq 0x8150
mulsd 0x23307(%rip), %xmm0    # 0x74c90
movsd -0x40(%rbp), %xmm1
mulsd 0x23302(%rip), %xmm1    # 0x74c98
addsd %xmm1, %xmm0
mulsd 0x232a6(%rip), %xmm0    # 0x74c48
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movabsq $0x3ff0000000000000, %r15 # imm = 0x3FF0000000000000
movq %r15, 0x20(%r13)
movq %rbx, 0x38(%r13)
movq %rbx, 0x28(%r13)
movq %rbx, 0x18(%r13)
movq %rbx, 0x8(%r13)
movsd (%r12), %xmm0
callq 0x8c00
movsd %xmm0, 0x40(%r13)
movsd %xmm0, (%r13)
movsd (%r12), %xmm0
callq 0x8150
movaps %xmm0, %xmm1
xorps 0x190da(%rip), %xmm1    # 0x6aad0
movlps %xmm1, 0x10(%r13)
movsd %xmm0, 0x30(%r13)
leaq -0x150(%rbp), %rax
movq %r15, (%rax)
movq %rbx, 0x30(%rax)
movq %rax, %r15
leaq -0x128(%rbp), %rax
movq %rbx, -0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movsd 0x8(%r12), %xmm0
callq 0x8c00
movsd %xmm0, 0x40(%r15)
movsd %xmm0, 0x20(%r15)
movsd 0x8(%r12), %xmm0
callq 0x8150
movapd %xmm0, %xmm1
xorpd 0x1907c(%rip), %xmm1    # 0x6aad0
movlpd %xmm1, 0x38(%r15)
movsd %xmm0, 0x28(%r15)
leaq -0x100(%rbp), %r15
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x40(%r15)
movq %rbx, 0x10(%r15)
leaq -0xd8(%rbp), %rax
movq %rbx, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
callq 0x8c00
movsd %xmm0, 0x20(%r15)
movsd %xmm0, (%r15)
movsd -0x30(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x18(%r15)
xorps 0x19018(%rip), %xmm0    # 0x6aad0
movlps %xmm0, 0x8(%r15)
leaq -0x360(%rbp), %r15
movq %r15, (%rsp)
xorpd %xmm1, %xmm1
leaq 0x235b4(%rip), %r12     # 0x75087
movq %r12, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x17e33(%rip), %xmm0    # 0x69920
movq %r13, %r8
leaq -0x150(%rbp), %r9
callq 0x4e91f
leaq -0x1d0(%rbp), %rax
movq %rax, (%rsp)
xorpd %xmm1, %xmm1
movq %r12, %rdi
movq %r12, %r13
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x17df8(%rip), %xmm0    # 0x69920
movq %r15, %r8
leaq -0x100(%rbp), %r9
callq 0x4e91f
leaq -0x310(%rbp), %r15
movq %r15, (%rsp)
leaq -0x270(%rbp), %r9
xorpd %xmm1, %xmm1
movq %r12, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x17db9(%rip), %xmm0    # 0x69920
leaq -0x2c0(%rbp), %r8
callq 0x4e91f
leaq 0x404c6(%rip), %r12     # 0x92040
movq %r12, (%rsp)
xorpd %xmm1, %xmm1
movq %r13, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x17d84(%rip), %xmm0    # 0x69920
leaq -0x1d0(%rbp), %r8
movq %r15, %r9
callq 0x4e91f
movsd (%rbx,%r12), %xmm0
movsd %xmm0, (%r14,%rbx)
addq $0x8, %rbx
cmpq $0x48, %rbx
jne 0x51bab
movq -0x78(%rbp), %r15
testq %r15, %r15
je 0x51bd7
movsd 0x404b6(%rip), %xmm0    # 0x92088
movsd %xmm0, (%r15)
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq