// File: /workspace/github_cpp_makefile_star2_O2/istellartech[P]OpenTsiolkovsky/src/rocket.cpp
// Function: RocketStage::operator()(std::array<double, 14ul> const&, std::array<double, 14ul>&, double)
void RocketStage::operator()(const RocketStage::state& x, RocketStage::state& dx, double t){
    posECI_ << x[1], x[2], x[3];
    velECI_ << x[4], x[5], x[6];

    dcmECI2ECEF_ = dcmECI2ECEF(t);
    posECEF_ = posECEF(dcmECI2ECEF_, posECI_);
    posLLH_ = posLLH(posECEF_);

    //    It does not calculate after the rocket falls to the ground
    if ( posLLH_[2] < 0) {
        dx = {0, 0, 0, 0, 0, 0, 0};
        /*
        if ((int)t % 10 == 0 && (int)(t*10) % 10 == 0 ){ // progress
            progress(t);
        }
        */
        if ( flag_impact_g == false ) {
            impact_point_g << posLLH_[0], posLLH_[1];
            flag_impact_g = true;
        }
        return;
    }

    //    update rocket variables
    update_from_time_and_altitude(t, posLLH_[2]);

    //    transform coordinate
    dcmECEF2NED_ = dcmECEF2NED(posLLH_);
    dcmNED2ECEF_ = dcmECEF2NED_.transpose();
    dcmECI2NED_ = dcmECI2NED(dcmECEF2NED_, dcmECI2ECEF_);
    dcmNED2ECI_ = dcmECI2NED_.transpose();
    dcmECEF2NED_init_ = dcmECEF2NED(launch_pos_LLH);
    dcmECI2NED_init_ = dcmECI2NED(dcmECEF2NED_init_, dcmECI2ECEF(0.0));
    vel_ECEF_NEDframe_ = vel_ECEF_NEDframe(dcmECI2NED_, velECI_, posECI_);
    vel_wind_NEDframe_ = vel_wind_NEDframe(wind_speed, wind_direction);
    //    air = air.altitude(posLLH_[2]);
    if (air_density_file_exist){
        air = air.altitude_with_variation_table(posLLH_[2], air_density_mat);
    } else{
        air = air.altitude_with_variation(posLLH_[2], variation_ratio_of_air_density);
    }
    //    gravity term : gravity acceleration in the north direction is not considered
    gravityECI_ = gravityECI(posECI_);

    if (is_powered){  // ---- powered flight ----
        switch (power_flight_mode) {
            case _3DoF:
                power_flight_3dof(x,t);
                break;
            case _3DoF_with_delay:  // Unimplemented
                power_flight_3dof_with_delay(x, t);
                break;
            case _6DoF:  // Unimplemented
                power_flight_6dof(x, t);
                break;
            case _6DoF_aerodynamic_stable:  // Unimplemented
                power_flight_6dof_aerodynamic_stable(x, t);
                break;
            default:
                m_dot = 0;
                accECI_ << 0.0, 0.0, 0.0;
                break;
        }
    } else {  // ---- free flight ----
        switch (free_flight_mode) {
            case aerodynamic_stable:
                free_flight_aerodynamic_stable(x, t);
                break;
            case _3DoF_defined:
                free_flight_3dof_defined(x, t);
                break;
            case ballistic_flight:
                free_flight_ballistic(x, t);
                break;
            default:
                m_dot = 0;
                accECI_ << 0.0, 0.0, 0.0;
                break;
        }
    }

    dx[0] = -m_dot;
    dx[1] = x[4];
    dx[2] = x[5];
    dx[3] = x[6];
    dx[4] = accECI_[0];
    dx[5] = accECI_[1];
    dx[6] = accECI_[2];

    //    separation
    if (flag_separation_g == false && t >= later_stage_separation_time){
        flag_separation_g = true;
        posECI_init_g = posECI_;
        velECI_init_g = velECI_;
    }

    // dumping product
    if (flag_dump_g == false && t >= dump_separation_time){
        flag_dump_g = true;
        posECI_dump_init_g = posECI_;
        velECI_dump_init_g = velECI_ + dcmNED2ECI_ * vel_dump_additional_NEDframe;
    }

    if (max_alt_g < posLLH_[2]){  // update maximum altitude[m]
        max_alt_g = posLLH_[2];
    }
    downrange = distance_surface(launch_pos_LLH, posLLH_);
    if (max_downrange_g < downrange){  // update maximum downrange
        max_downrange_g = downrange;
    }

    /*
    if ((int)t % 10 == 0 && (int)(t*10) % 10 == 0 ){ // progress
        progress(t);
    }
    */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
leaq 0x9c0(%rdi), %r12
leaq 0x68(%rsp), %rdi
movq %r12, (%rdi)
andq $0x0, 0x8(%rdi)
movq %rdx, %r14
movq %rsi, %r13
pushq $0x1
popq %rbp
movq %rbp, 0x10(%rdi)
movq %rbp, 0x18(%rdi)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x9c0(%rbx)
addq $0x10, %rsi
callq 0xfd60
leaq 0x18(%r13), %rsi
movq %rax, %rdi
callq 0xfd60
movq %r14, 0x20(%rsp)
leaq 0x68(%rsp), %r15
movq %r15, %rdi
callq 0xfe08
leaq 0x9d8(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %rax, (%r15)
andq $0x0, 0x8(%r15)
movq %rbp, 0x10(%r15)
movq %rbp, 0x18(%r15)
movsd 0x20(%r13), %xmm0
movsd %xmm0, 0x9d8(%rbx)
leaq 0x28(%r13), %rsi
leaq 0x68(%rsp), %rdi
callq 0xfd60
leaq 0x30(%r13), %rsi
movq %rax, %rdi
callq 0xfd60
leaq 0x68(%rsp), %rdi
callq 0xfe08
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x1cb1c
leaq 0xa20(%rbx), %r15
movq %rbp, %rdi
movq %r15, %rsi
callq 0x151a4
leaq 0x3f0(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x152a2
leaq 0x270(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x129c6
movq %r12, 0x10(%rsp)
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1cc47
leaq 0xa68(%rbx), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x15314
leaq 0x258(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x129c6
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x1ccf4
leaq 0xa80(%rbx), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x15314
movsd 0xa90(%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc60d
xorpd %xmm0, %xmm0
movq 0x20(%rsp), %rax
movupd %xmm0, 0x60(%rax)
movupd %xmm0, 0x50(%rax)
movupd %xmm0, 0x40(%rax)
movupd %xmm0, 0x30(%rax)
movupd %xmm0, 0x20(%rax)
movupd %xmm0, 0x10(%rax)
movupd %xmm0, (%rax)
cmpb $0x0, 0x22ed8(%rip)     # 0x2f48b
jne 0xcba3
leaq 0x22ee0(%rip), %rax     # 0x2f4a0
leaq 0x68(%rsp), %rdi
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
pushq $0x1
popq %rax
movq %rax, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movsd 0xa80(%rbx), %xmm0
movsd %xmm0, 0x22eb8(%rip)    # 0x2f4a0
addq $0xa88, %rbx            # imm = 0xA88
movq %rbx, %rsi
callq 0x10bb8
leaq 0x68(%rsp), %rdi
callq 0x10c60
movb $0x1, 0x22e83(%rip)     # 0x2f48b
jmp 0xcba3
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
callq 0xcbf2
leaq 0x240(%rsp), %r14
movq %r14, %rdi
movq %r12, 0x40(%rsp)
movq %r12, %rsi
callq 0x129c6
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x1ce81
leaq 0xa98(%rbx), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x151a4
movq %r14, (%r12)
leaq 0xae0(%rbx), %rdi
leaq 0x68(%rsp), %rsi
callq 0x1536a
leaq 0x3a8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x152a2
leaq 0x360(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x152a2
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1d085
leaq 0xb28(%rbx), %r15
movq %rbp, %rdi
movq %r15, %rsi
callq 0x151a4
movq %r15, (%rbp)
leaq 0xb70(%rbx), %rdi
leaq 0x68(%rsp), %rsi
movq %rdi, 0x30(%rsp)
callq 0x1536a
leaq 0x340(%rbx), %rsi
leaq 0x228(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x38(%rsp)
callq 0x129c6
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x1ce81
leaq 0xd68(%rbx), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x151a4
leaq 0x318(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x152a2
leaq 0x2d0(%rsp), %r14
xorps %xmm0, %xmm0
movq %r14, %rdi
callq 0x1cb1c
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1d085
leaq 0xdb0(%rbx), %rsi
movq %rbp, %rdi
callq 0x151a4
leaq 0x288(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x152a2
leaq 0x210(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x129c6
leaq 0x1f8(%rsp), %r12
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0x129c6
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x1d0b2
leaq 0xbb8(%rbx), %rsi
movq %rbp, %rdi
callq 0x15314
movsd 0x918(%rbx), %xmm0
movsd 0x920(%rbx), %xmm1
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x1d218
leaq 0xbd0(%rbx), %rsi
movq %r14, %rdi
callq 0x15314
leaq 0x7f8(%rbx), %r15
cmpb $0x1, 0x290(%rbx)
jne 0xc851
movsd 0xa90(%rbx), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x2b8(%rbx), %rsi
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x643a
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
movsd 0x28(%rsp), %xmm0
movq %r14, %rdx
callq 0x5e24
pushq $0x1
popq %rbp
leaq 0x68(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
movq %r15, %rdi
callq 0x52f0
movq 0x50(%rsp), %rdi
callq 0x5430
movq 0x10(%rsp), %r12
jmp 0xc889
movsd 0xa90(%rbx), %xmm0
movsd 0x270(%rbx), %xmm1
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x5ba8
movl $0x120, %edx            # imm = 0x120
movq %r15, %rdi
movq %r14, %rsi
callq 0x52f0
movq 0x10(%rsp), %r12
pushq $0x1
popq %rbp
leaq 0x1e0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x129c6
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1be7c
leaq 0xe58(%rbx), %rsi
movq %r15, %rdi
callq 0x15314
cmpb $0x1, 0x254(%rbx)
jne 0xc8ff
movl 0x278(%rbx), %eax
cmpq $0x3, %rax
movsd 0x8(%rsp), %xmm0
movq 0x20(%rsp), %r14
ja 0xc9d3
leaq 0x1379a(%rip), %rcx     # 0x20080
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd3d2
jmp 0xca2b
movl 0x27c(%rbx), %eax
cmpl $0x2, %eax
movsd 0x8(%rsp), %xmm0
movq 0x20(%rsp), %r14
je 0xc93e
cmpl $0x1, %eax
je 0xc92e
testl %eax, %eax
jne 0xc94b
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdb4a
jmp 0xca2b
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdeda
jmp 0xca2b
movq %rbx, %rdi
callq 0xe310
jmp 0xca2b
andq $0x0, 0x790(%rbx)
leaq 0x9f0(%rbx), %rax
leaq 0x68(%rsp), %rdi
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movq %rbp, 0x10(%rdi)
movq %rbp, 0x18(%rdi)
andq $0x0, 0x9f0(%rbx)
leaq 0x188(%rsp), %rsi
andq $0x0, (%rsi)
callq 0xfd60
leaq 0x48(%rsp), %rsi
andq $0x0, (%rsi)
movq %rax, %rdi
callq 0xfd60
jmp 0xca21
leaq 0x230(%rbx), %rdi
leaq 0x1410f(%rip), %rsi     # 0x20abb
jmp 0xc9cc
leaq 0x230(%rbx), %rdi
leaq 0x1410a(%rip), %rsi     # 0x20ac6
jmp 0xc9cc
leaq 0x230(%rbx), %rdi
leaq 0x140de(%rip), %rsi     # 0x20aaa
callq 0x56a0
jmp 0xca2b
andq $0x0, 0x790(%rbx)
leaq 0x9f0(%rbx), %rax
leaq 0x68(%rsp), %rdi
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movq %rbp, 0x10(%rdi)
movq %rbp, 0x18(%rdi)
andq $0x0, 0x9f0(%rbx)
leaq 0x188(%rsp), %rsi
andq $0x0, (%rsi)
callq 0xfd60
leaq 0x48(%rsp), %rsi
andq $0x0, (%rsi)
movq %rax, %rdi
callq 0xfd60
leaq 0x68(%rsp), %rdi
callq 0xfe08
movsd 0x790(%rbx), %xmm0
xorps 0x125d6(%rip), %xmm0    # 0x1f010
movlps %xmm0, (%r14)
movsd 0x20(%r13), %xmm0
movsd %xmm0, 0x8(%r14)
movsd 0x28(%r13), %xmm0
movsd %xmm0, 0x10(%r14)
movsd 0x30(%r13), %xmm0
movsd %xmm0, 0x18(%r14)
movsd 0x9f0(%rbx), %xmm0
movsd %xmm0, 0x20(%r14)
movsd 0x9f8(%rbx), %xmm0
movsd %xmm0, 0x28(%r14)
movsd 0xa00(%rbx), %xmm0
movsd %xmm0, 0x30(%r14)
cmpb $0x0, 0x229f5(%rip)     # 0x2f488
movsd 0x8(%rsp), %xmm0
jne 0xcad2
ucomisd 0x750(%rbx), %xmm0
jb 0xcad2
movb $0x1, 0x229dc(%rip)     # 0x2f488
leaq 0x229a5(%rip), %rdi     # 0x2f458
movq %r12, %rsi
callq 0x129c6
leaq 0x229ae(%rip), %rdi     # 0x2f470
movq 0x18(%rsp), %rsi
callq 0x129c6
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0x229b1(%rip)     # 0x2f48a
jne 0xcb3a
ucomisd 0x650(%rbx), %xmm0
jb 0xcb3a
movb $0x1, 0x2299e(%rip)     # 0x2f48a
leaq 0x229bd(%rip), %rdi     # 0x2f4b0
movq %r12, %rsi
callq 0x129c6
leaq 0x668(%rbx), %rax
leaq 0x188(%rsp), %rsi
movq 0x30(%rsp), %rcx
movq %rcx, (%rsi)
movq %rax, 0x8(%rsi)
leaq 0x70(%rsp), %rdi
movq 0x18(%rsp), %rax
movq %rax, -0x8(%rdi)
callq 0x1543a
leaq 0x22998(%rip), %rdi     # 0x2f4c8
leaq 0x68(%rsp), %rsi
callq 0x1551c
movsd 0xa90(%rbx), %xmm0
ucomisd 0x2294e(%rip), %xmm0    # 0x2f498
jbe 0xcb54
movsd %xmm0, 0x22944(%rip)    # 0x2f498
leaq 0x1c8(%rsp), %r14
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x129c6
leaq 0x1b0(%rsp), %r15
movq %r15, %rdi
movq 0x40(%rsp), %rsi
callq 0x129c6
movq %r14, %rdi
movq %r15, %rsi
callq 0x1dd52
movsd %xmm0, 0xe88(%rbx)
ucomisd 0x228f7(%rip), %xmm0    # 0x2f490
jbe 0xcba3
movsd %xmm0, 0x228ed(%rip)    # 0x2f490
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xcbdd
jmp 0xcbdd
jmp 0xcbdd
jmp 0xcbdd
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x10c60
jmp 0xcbea
movq %rax, %rbx
movq 0x50(%rsp), %rdi
callq 0x5430
jmp 0xcbea
jmp 0xcbdd
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0xfe08
movq %rbx, %rdi
callq 0x5640