// File: /workspace/github_cpp_makefile_star2_O2/istellartech[P]OpenTsiolkovsky/src/rocket.cpp
// Function: RocketStage::free_flight_3dof_defined(std::array<double, 14ul> const&, double)
void RocketStage::free_flight_3dof_defined(const RocketStage::state& x, double t){
    flight_mode = "free_3dof";
    // dcmNED2BODY_ = dcmNED2BODY(azimuth, elevation, roll);
    Matrix3d dcmNAVI2BODY_ = this->quatNAVI2BODY(t).toRotationMatrix();
    Matrix3d dcmNED2NAVI_ = dcmNED2BODY(azimuth_target, elevation_target, roll_target);
    dcmNED2BODY_ = dcmNAVI2BODY_ * dcmNED2NAVI_;
    Vector3d azelro = azimuth_elevation_roll(dcmNED2BODY_);
    elevation = azelro[1];
    azimuth = ((deg2rad(90.0) - elevation_target < 1e-9) && (deg2rad(90.0) - elevation < 1e-9))? azimuth_target : azelro[0];
    roll = ((deg2rad(90.0) - elevation_target < 1e-9) && (deg2rad(90.0) - elevation < 1e-9))? roll_target : azelro[2];
    vel_AIR_BODYframe_ = vel_AIR_BODYframe(dcmNED2BODY_, vel_ECEF_NEDframe_, vel_wind_NEDframe_);
    angle_of_attack_ = angle_of_attack(vel_AIR_BODYframe_);
    dcmECI2BODY_ = dcmECI2BODY(dcmNED2BODY_, dcmECI2NED_);
    dcmBODY2ECI_ = dcmECI2BODY_.transpose();

    //    thrust term
    force_thrust_vector << 0.0, 0.0, 0.0;
    //    aerodynamics term
    vel_AIR_BODYframe_abs = vel_AIR_BODYframe_.norm();
    mach_number = vel_AIR_BODYframe_abs / air.airspeed;
    update_from_mach_number();
    dynamic_pressure = 0.5 * air.density * vel_AIR_BODYframe_abs * vel_AIR_BODYframe_abs;
    force_axial        = CA       * dynamic_pressure * body_area;
    force_normal_yaw   = CN_yaw   * dynamic_pressure * body_area;
    force_normal_pitch = CN_pitch * dynamic_pressure * body_area;
    force_air_vector_BODYframe << - force_axial, - force_normal_yaw, - force_normal_pitch;
    //    dv/dt
    accECI_ = 1/x[0] * (dcmBODY2ECI_ * (force_thrust_vector + force_air_vector_BODYframe))
            + gravityECI_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movsd %xmm0, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
addq $0x230, %rdi            # imm = 0x230
leaq 0x12be7(%rip), %rsi     # 0x20aee
callq 0x56a0
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movsd 0x8(%rsp), %xmm0
callq 0xe7dc
leaq 0x280(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x10cb0
movsd 0x940(%rbx), %xmm0
movsd 0x948(%rbx), %xmm1
movsd 0x950(%rbx), %xmm2
leaq 0x238(%rsp), %r13
movq %r13, %rdi
callq 0x1d3c3
movq %r12, (%r15)
movq %r13, 0x8(%r15)
leaq 0xc90(%rbx), %r15
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x158da
leaq 0x1f0(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x152a2
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x1d79e
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x930(%rbx)
movsd 0x11e77(%rip), %xmm1    # 0x1fe28
movapd %xmm1, %xmm3
subsd 0x948(%rbx), %xmm3
movsd 0x11e6b(%rip), %xmm2    # 0x1fe30
ucomisd %xmm3, %xmm2
jbe 0xdfee
subsd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jbe 0xdfee
leaq 0x950(%rbx), %rax
movsd 0x940(%rbx), %xmm0
movsd %xmm0, 0x928(%rbx)
jmp 0xe001
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x928(%rbx)
leaq 0x28(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x938(%rbx)
leaq 0x1a8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x152a2
leaq 0xbb8(%rbx), %rsi
leaq 0x100(%rsp), %r13
movq %r13, %rdi
callq 0x129c6
leaq 0xbd0(%rbx), %rsi
leaq 0xe8(%rsp), %rbp
movq %rbp, %rdi
callq 0x129c6
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x1d287
leaq 0xbe8(%rbx), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x15314
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x129c6
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x1d2c8
leaq 0xc30(%rbx), %rsi
movq %r13, %rdi
callq 0x15314
leaq 0x160(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x152a2
leaq 0xb28(%rbx), %rsi
leaq 0x118(%rsp), %r15
movq %r15, %rdi
callq 0x152a2
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1d862
leaq 0xcd8(%rbx), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x151a4
movq %r14, (%r13)
leaq 0xd20(%rbx), %r13
leaq 0x30(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x1536a
leaq 0xe28(%rbx), %rbp
movq %rbp, (%r14)
andq $0x0, 0x8(%r14)
pushq $0x1
popq %r15
movq %r15, 0x10(%r14)
movq %r15, 0x18(%r14)
andq $0x0, 0xe28(%rbx)
leaq 0xa8(%rsp), %rsi
andq $0x0, (%rsi)
leaq 0x30(%rsp), %rdi
callq 0xfd60
movq %r13, %r14
leaq 0x90(%rsp), %rsi
andq $0x0, (%rsi)
movq %rax, %rdi
callq 0xfd60
leaq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0xfe08
movq %r12, %rdi
callq 0x10c94
movsd %xmm0, 0x7c8(%rbx)
divsd 0x900(%rbx), %xmm0
movsd %xmm0, 0x958(%rbx)
movq %rbx, %rdi
callq 0xe4a6
movsd 0x910(%rbx), %xmm0
mulsd 0x11c91(%rip), %xmm0    # 0x1fe38
movsd 0x7c8(%rbx), %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7d8(%rbx)
movsd 0x510(%rbx), %xmm1
movsd 0x7b0(%rbx), %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, 0x7f0(%rbx)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd 0x7a0(%rbx), %xmm0
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm0, %xmm1
movapd %xmm1, 0x7e0(%rbx)
leaq 0xdf8(%rbx), %r12
movq %r12, (%r13)
andq $0x0, 0x8(%r13)
movapd 0x10dfd(%rip), %xmm0    # 0x1f010
xorpd %xmm0, %xmm1
movq %r15, 0x10(%r13)
movq %r15, 0x18(%r13)
movlpd %xmm1, 0xdf8(%rbx)
xorpd %xmm0, %xmm2
leaq 0xa8(%rsp), %rsi
movlpd %xmm2, (%rsi)
leaq 0x30(%rsp), %rdi
callq 0xfd60
movsd 0x7e8(%rbx), %xmm0
xorpd 0x10dbf(%rip), %xmm0    # 0x1f010
leaq 0x90(%rsp), %rsi
movlpd %xmm0, (%rsi)
movq %rax, %rdi
callq 0xfd60
movq %r14, %r15
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0xfe08
movsd 0x10de3(%rip), %xmm0    # 0x1f060
movq 0x10(%rsp), %rax
divsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x90(%rsp), %rsi
movq %rbp, (%rsi)
movq %r12, 0x8(%rsi)
movq %r15, (%r14)
leaq 0x38(%rsp), %rdi
callq 0x15aec
leaq 0x30(%rsp), %rdi
callq 0x15b5c
leaq 0xe58(%rbx), %rcx
leaq 0xa8(%rsp), %rsi
movq %rax, 0x8(%rsi)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
addq $0x9f0, %rbx            # imm = 0x9F0
movq %rbx, %rdi
callq 0x15c52
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe2fb
jmp 0xe2fb
jmp 0xe2fb
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xfe08
movq %rbx, %rdi
callq 0x5640