// File: /workspace/github_cpp_makefile_star2_O3/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, -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 0x41693(%rip), %rsi     # 0x91ff0
movl $0x3, %edx
callq 0x4fcf1
movq 0x416c2(%rip), %rsi     # 0x92030
movsd 0x416c2(%rip), %xmm0    # 0x92038
movsd %xmm0, -0x30(%rbp)
movq %rbx, %rdi
callq 0x8330
movsd -0x40(%rbp), %xmm2
addsd %xmm2, %xmm0
subsd -0x30(%rbp), %xmm0
andpd 0x18f97(%rip), %xmm0    # 0x69930
movsd 0x1ae1f(%rip), %xmm1    # 0x6b7c0
ucomisd %xmm0, %xmm1
jbe 0x509ca
xorl %eax, %eax
leaq 0x41690(%rip), %rcx     # 0x92040
movsd (%rax,%rcx), %xmm0
movsd %xmm0, (%r14,%rax)
addq $0x8, %rax
cmpq $0x48, %rax
jne 0x509b0
jmp 0x511d5
movq %r12, -0x70(%rbp)
movq %r15, -0x78(%rbp)
movq %rbx, 0x41657(%rip)     # 0x92030
movsd %xmm2, 0x41657(%rip)    # 0x92038
movq %rbx, %rdi
movapd %xmm2, %xmm0
callq 0x4fa70
movq %rax, %rbx
movsd %xmm0, -0x30(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4f027
movsd %xmm0, -0x40(%rbp)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8330
addsd -0x30(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
addsd 0x19ea5(%rip), %xmm0    # 0x6a8c8
addsd 0x241c5(%rip), %xmm0    # 0x74bf0
divsd 0x19e9d(%rip), %xmm0    # 0x6a8d0
divsd 0x24165(%rip), %xmm0    # 0x74ba0
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 0x511f9
movsd 0x2418a(%rip), %xmm0    # 0x74bf8
movsd -0x50(%rbp), %xmm5
mulsd %xmm5, %xmm0
movsd 0x24181(%rip), %xmm1    # 0x74c00
movsd -0x40(%rbp), %xmm4
mulsd %xmm4, %xmm1
addsd %xmm1, %xmm0
movsd 0x24174(%rip), %xmm2    # 0x74c08
movapd -0x60(%rbp), %xmm3
mulsd %xmm3, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, -0x30(%rbp)
movsd 0x24162(%rip), %xmm0    # 0x74c10
mulsd %xmm5, %xmm0
movsd 0x2415e(%rip), %xmm2    # 0x74c18
mulsd %xmm4, %xmm2
addsd %xmm0, %xmm2
movsd 0x24156(%rip), %xmm0    # 0x74c20
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
mulsd 0x2414e(%rip), %xmm0    # 0x74c28
movsd %xmm0, -0x48(%rbp)
movsd 0x24149(%rip), %xmm0    # 0x74c30
movapd %xmm5, %xmm2
mulsd %xmm5, %xmm0
addsd %xmm1, %xmm0
movsd 0x2413d(%rip), %xmm1    # 0x74c38
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd 0x24135(%rip), %xmm0    # 0x74c40
mulsd %xmm4, %xmm0
addsd 0x24131(%rip), %xmm0    # 0x74c48
mulsd 0x24131(%rip), %xmm2    # 0x74c50
addsd %xmm0, %xmm2
movapd %xmm3, %xmm0
mulsd 0x24129(%rip), %xmm0    # 0x74c58
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 0x2410a(%rip), %xmm0    # 0x74c60
movsd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
movupd %xmm1, 0x20(%rbx)
movq %r12, 0x30(%rbx)
callq 0x8bf0
movsd %xmm0, 0x18(%rbx)
movsd %xmm0, -0x8(%rbx)
movsd -0x50(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x10(%rbx)
xorps 0x19f43(%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 0x8bf0
movsd %xmm0, 0x18(%rbx)
movsd %xmm0, -0x28(%rbx)
movsd -0x48(%rbp), %xmm0
callq 0x8150
movsd %xmm0, -0x18(%rbx)
xorps 0x19efc(%rip), %xmm0    # 0x6aad0
movlps %xmm0, 0x8(%rbx)
leaq -0xd8(%rbp), %rbx
movq %r13, 0x18(%rbx)
movq %r12, -0x18(%rbx)
movsd -0x30(%rbp), %xmm0
mulsd 0x2406c(%rip), %xmm0    # 0x74c60
movsd %xmm0, -0x30(%rbp)
xorpd %xmm1, %xmm1
movupd %xmm1, (%rbx)
movq %r12, 0x10(%rbx)
callq 0x8bf0
movsd %xmm0, -0x8(%rbx)
movsd %xmm0, -0x28(%rbx)
movsd -0x30(%rbp), %xmm0
callq 0x8150
movsd %xmm0, -0x10(%rbx)
xorps 0x19ea6(%rip), %xmm0    # 0x6aad0
movlps %xmm0, -0x20(%rbx)
leaq -0x1d0(%rbp), %r15
movq %r15, (%rsp)
leaq 0x24427(%rip), %rbx     # 0x75067
movsd 0x18cd8(%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 0x4dfb0
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 0x18c74(%rip), %xmm0    # 0x69920
movq %r15, %r8
callq 0x4dfb0
leaq 0x21bb5(%rip), %rbx     # 0x72870
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 0x50ccd
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 0x8bf0
mulsd -0x68(%rbp), %xmm0
movsd -0x48(%rbp), %xmm3
addsd %xmm0, %xmm3
incq %r12
addq $0x50, %r13
cmpq $0x6a, %r12
jne 0x50cc2
movapd -0x60(%rbp), %xmm0
mulsd 0x23eb3(%rip), %xmm0    # 0x74c28
movapd %xmm0, %xmm2
movapd %xmm0, -0x60(%rbp)
movsd 0x23ee2(%rip), %xmm0    # 0x74c68
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 0x19d12(%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 0x8bf0
movsd %xmm0, 0x40(%r13)
movsd %xmm0, 0x20(%r13)
movaps -0x40(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x38(%r13)
xorps 0x19cc7(%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 0x8bf0
movsd %xmm0, 0x20(%r15)
movsd %xmm0, (%r15)
movsd -0x30(%rbp), %xmm0
callq 0x8150
movaps %xmm0, %xmm1
xorps 0x19c79(%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 0x8bf0
movsd %xmm0, 0x40(%r15)
movsd %xmm0, 0x20(%r15)
movaps -0x60(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x38(%r15)
xorps 0x19c23(%rip), %xmm0    # 0x6aad0
movlps %xmm0, 0x28(%r15)
leaq -0x1d0(%rbp), %r12
movq %r12, (%rsp)
leaq 0x241a3(%rip), %r15     # 0x75067
movsd 0x18a54(%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 0x4dfb0
leaq -0x2c0(%rbp), %rax
movq %rax, (%rsp)
xorps %xmm1, %xmm1
movq %r15, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x18a08(%rip), %xmm0    # 0x69920
movq %r12, %r8
leaq -0x100(%rbp), %r9
callq 0x4dfb0
movq 0x41102(%rip), %rdi     # 0x92030
movsd 0x41102(%rip), %xmm0    # 0x92038
movq -0x70(%rbp), %r12
movsd 0x10(%r12), %xmm1
callq 0x4fb87
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, 0x41135(%rip)    # 0x92088
movapd -0x60(%rbp), %xmm0
callq 0x8bf0
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 0x23cd7(%rip), %xmm0    # 0x74c70
movsd -0x40(%rbp), %xmm1
mulsd 0x23cd2(%rip), %xmm1    # 0x74c78
addsd %xmm1, %xmm0
mulsd 0x23c76(%rip), %xmm0    # 0x74c28
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 0x8bf0
movsd %xmm0, 0x40(%r13)
movsd %xmm0, (%r13)
movsd (%r12), %xmm0
callq 0x8150
movaps %xmm0, %xmm1
xorps 0x19aca(%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 0x8bf0
movsd %xmm0, 0x40(%r15)
movsd %xmm0, 0x20(%r15)
movsd 0x8(%r12), %xmm0
callq 0x8150
movapd %xmm0, %xmm1
xorpd 0x19a6c(%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 0x8bf0
movsd %xmm0, 0x20(%r15)
movsd %xmm0, (%r15)
movsd -0x30(%rbp), %xmm0
callq 0x8150
movsd %xmm0, 0x18(%r15)
xorps 0x19a08(%rip), %xmm0    # 0x6aad0
movlps %xmm0, 0x8(%r15)
leaq -0x360(%rbp), %r15
movq %r15, (%rsp)
xorpd %xmm1, %xmm1
leaq 0x23f84(%rip), %r12     # 0x75067
movq %r12, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x18823(%rip), %xmm0    # 0x69920
movq %r13, %r8
leaq -0x150(%rbp), %r9
callq 0x4dfb0
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 0x187e8(%rip), %xmm0    # 0x69920
movq %r15, %r8
leaq -0x100(%rbp), %r9
callq 0x4dfb0
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 0x187a9(%rip), %xmm0    # 0x69920
leaq -0x2c0(%rbp), %r8
callq 0x4dfb0
leaq 0x40eb6(%rip), %r12     # 0x92040
movq %r12, (%rsp)
xorpd %xmm1, %xmm1
movq %r13, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x3, %ecx
movsd 0x18774(%rip), %xmm0    # 0x69920
leaq -0x1d0(%rbp), %r8
movq %r15, %r9
callq 0x4dfb0
movsd (%rbx,%r12), %xmm0
movsd %xmm0, (%r14,%rbx)
addq $0x8, %rbx
cmpq $0x48, %rbx
jne 0x511bb
movq -0x78(%rbp), %r15
testq %r15, %r15
je 0x511e7
movsd 0x40ea6(%rip), %xmm0    # 0x92088
movsd %xmm0, (%r15)
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq