// File: 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
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x438(%rbp)
addq $0x230, %rdi            # imm = 0x230
leaq 0x3931d(%rip), %rsi     # 0x53c7e
callq 0x6600
movq -0x438(%rbp), %rsi
movsd -0x18(%rbp), %xmm0
leaq -0x80(%rbp), %rdi
callq 0x1b8b0
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x207e0
movq -0x438(%rbp), %rax
movsd 0x940(%rax), %xmm0
movsd 0x948(%rax), %xmm1
movsd 0x950(%rax), %xmm2
leaq -0xc8(%rbp), %rdi
callq 0x4bb40
leaq -0x120(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0x20c00
movq -0x438(%rbp), %rdi
addq $0xc90, %rdi            # imm = 0xC90
leaq -0x120(%rbp), %rsi
callq 0x20c50
movq -0x438(%rbp), %rsi
addq $0xc90, %rsi            # imm = 0xC90
leaq -0x180(%rbp), %rdi
callq 0x203a0
leaq -0x138(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x4c120
leaq -0x138(%rbp), %rdi
movl $0x1, %esi
callq 0x1de40
movq %rax, %rcx
movq -0x438(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x930(%rax)
movsd 0x38418(%rip), %xmm0    # 0x52e58
callq 0x1e000
movq -0x438(%rbp), %rax
movaps %xmm0, %xmm1
subsd 0x948(%rax), %xmm1
movsd 0x383e9(%rip), %xmm0    # 0x52e48
ucomisd %xmm1, %xmm0
jbe 0x1aaab
movsd 0x383eb(%rip), %xmm0    # 0x52e58
callq 0x1e000
movq -0x438(%rbp), %rax
movaps %xmm0, %xmm1
subsd 0x930(%rax), %xmm1
movsd 0x383bc(%rip), %xmm0    # 0x52e48
ucomisd %xmm1, %xmm0
jbe 0x1aaab
movq -0x438(%rbp), %rax
movsd 0x940(%rax), %xmm0
movsd %xmm0, -0x440(%rbp)
jmp 0x1aac7
leaq -0x138(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
movsd %xmm0, -0x440(%rbp)
movq -0x438(%rbp), %rax
movsd -0x440(%rbp), %xmm0
movsd %xmm0, 0x928(%rax)
movsd 0x38372(%rip), %xmm0    # 0x52e58
callq 0x1e000
movq -0x438(%rbp), %rax
movaps %xmm0, %xmm1
subsd 0x948(%rax), %xmm1
movsd 0x38343(%rip), %xmm0    # 0x52e48
ucomisd %xmm1, %xmm0
jbe 0x1ab51
movsd 0x38345(%rip), %xmm0    # 0x52e58
callq 0x1e000
movq -0x438(%rbp), %rax
movaps %xmm0, %xmm1
subsd 0x930(%rax), %xmm1
movsd 0x38316(%rip), %xmm0    # 0x52e48
ucomisd %xmm1, %xmm0
jbe 0x1ab51
movq -0x438(%rbp), %rax
movsd 0x950(%rax), %xmm0
movsd %xmm0, -0x448(%rbp)
jmp 0x1ab6e
leaq -0x138(%rbp), %rdi
movl $0x2, %esi
callq 0x1de40
movsd (%rax), %xmm0
movsd %xmm0, -0x448(%rbp)
movq -0x438(%rbp), %rsi
movsd -0x448(%rbp), %xmm0
movsd %xmm0, 0x938(%rsi)
addq $0xc90, %rsi            # imm = 0xC90
movq %rsi, -0x480(%rbp)
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x4b8(%rbp)
callq 0x203a0
movq -0x438(%rbp), %rsi
addq $0xbb8, %rsi            # imm = 0xBB8
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x4b0(%rbp)
callq 0x1f0e0
movq -0x438(%rbp), %rsi
addq $0xbd0, %rsi            # imm = 0xBD0
leaq -0x210(%rbp), %rdi
movq %rdi, -0x4a8(%rbp)
callq 0x1f0e0
movq -0x4b8(%rbp), %rsi
movq -0x4b0(%rbp), %rdx
movq -0x4a8(%rbp), %rcx
leaq -0x198(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x4b820
movq -0x4a0(%rbp), %rsi
movq -0x438(%rbp), %rdi
addq $0xbe8, %rdi            # imm = 0xBE8
movq %rdi, -0x498(%rbp)
callq 0x20420
movq -0x498(%rbp), %rsi
leaq -0x240(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x1f0e0
movq -0x490(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movq %rdi, -0x488(%rbp)
callq 0x4b8b0
movq -0x488(%rbp), %rsi
movq -0x438(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
callq 0x20420
movq -0x480(%rbp), %rsi
leaq -0x2d0(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x203a0
movq -0x438(%rbp), %rsi
addq $0xb28, %rsi            # imm = 0xB28
leaq -0x318(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x203a0
movq -0x478(%rbp), %rsi
movq -0x470(%rbp), %rdx
leaq -0x288(%rbp), %rdi
movq %rdi, -0x468(%rbp)
callq 0x4c2f0
movq -0x468(%rbp), %rsi
movq -0x438(%rbp), %rdi
addq $0xcd8, %rdi            # imm = 0xCD8
movq %rdi, -0x460(%rbp)
callq 0x20370
movq -0x460(%rbp), %rdi
callq 0x20450
movq -0x438(%rbp), %rdi
movq %rax, -0x320(%rbp)
addq $0xd20, %rdi            # imm = 0xD20
leaq -0x320(%rbp), %rsi
callq 0x20480
movq -0x438(%rbp), %rsi
addq $0xe28, %rsi            # imm = 0xE28
movq $0x0, -0x348(%rbp)
leaq -0x340(%rbp), %rdi
movq %rdi, -0x458(%rbp)
leaq -0x348(%rbp), %rdx
callq 0x1e1e0
movq -0x458(%rbp), %rdi
movq $0x0, -0x350(%rbp)
leaq -0x350(%rbp), %rsi
callq 0x1e220
movq %rax, -0x450(%rbp)
jmp 0x1ad83
movq -0x450(%rbp), %rdi
movq $0x0, -0x368(%rbp)
leaq -0x368(%rbp), %rsi
callq 0x1e220
jmp 0x1ada3
leaq -0x340(%rbp), %rdi
callq 0x1e390
movq -0x438(%rbp), %rdi
addq $0xbe8, %rdi            # imm = 0xBE8
callq 0x205d0
movq -0x438(%rbp), %rdi
movsd %xmm0, 0x7c8(%rdi)
movsd 0x7c8(%rdi), %xmm0
movsd 0x900(%rdi), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x958(%rdi)
callq 0x1b340
movq -0x438(%rbp), %rax
movsd 0x7c8(%rax), %xmm1
movsd 0x910(%rax), %xmm0
movsd 0x3804f(%rip), %xmm2    # 0x52e60
mulsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7d8(%rax)
movsd 0x7a0(%rax), %xmm0
movsd 0x7d8(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x510(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7e0(%rax)
movsd 0x7b0(%rax), %xmm0
movsd 0x7d8(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x510(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7f0(%rax)
movsd 0x7a8(%rax), %xmm0
movsd 0x7d8(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x510(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7e8(%rax)
movq %rax, %rsi
addq $0xdf8, %rsi            # imm = 0xDF8
movsd 0x7e0(%rax), %xmm0
movapd 0x38189(%rip), %xmm1    # 0x53040
movaps %xmm1, -0x4e0(%rbp)
pxor %xmm1, %xmm0
movlpd %xmm0, -0x390(%rbp)
leaq -0x388(%rbp), %rdi
movq %rdi, -0x4c8(%rbp)
leaq -0x390(%rbp), %rdx
callq 0x1e1e0
movq -0x438(%rbp), %rax
movaps -0x4e0(%rbp), %xmm1
movq -0x4c8(%rbp), %rdi
movsd 0x7f0(%rax), %xmm0
pxor %xmm1, %xmm0
movlpd %xmm0, -0x398(%rbp)
leaq -0x398(%rbp), %rsi
callq 0x1e220
movq %rax, -0x4c0(%rbp)
jmp 0x1af22
movq -0x4c0(%rbp), %rdi
movq -0x438(%rbp), %rax
movsd 0x7e8(%rax), %xmm0
movaps 0x38101(%rip), %xmm1    # 0x53040
pxor %xmm1, %xmm0
movlpd %xmm0, -0x3a0(%rbp)
leaq -0x3a0(%rbp), %rsi
callq 0x1e220
jmp 0x1af59
leaq -0x388(%rbp), %rdi
callq 0x1e390
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20340
movq -0x438(%rbp), %rdx
movsd 0x370bf(%rip), %xmm0    # 0x52040
divsd (%rax), %xmm0
movsd %xmm0, -0x3e0(%rbp)
movq %rdx, %rax
addq $0xd20, %rax            # imm = 0xD20
movq %rax, -0x4e8(%rbp)
movq %rdx, %rsi
addq $0xe28, %rsi            # imm = 0xE28
addq $0xdf8, %rdx            # imm = 0xDF8
leaq -0x430(%rbp), %rdi
callq 0x20d10
movq -0x4e8(%rbp), %rsi
leaq -0x418(%rbp), %rdi
leaq -0x430(%rbp), %rdx
callq 0x20cc0
leaq -0x3d8(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
leaq -0x418(%rbp), %rdx
callq 0x20c80
movq -0x438(%rbp), %rdx
addq $0xe58, %rdx            # imm = 0xE58
leaq -0x3c8(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x20d80
movq -0x438(%rbp), %rdi
addq $0x9f0, %rdi            # imm = 0x9F0
leaq -0x3c8(%rbp), %rsi
callq 0x20df0
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x358(%rbp)
movl %eax, -0x35c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x1e390
jmp 0x1b070
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x358(%rbp)
movl %eax, -0x35c(%rbp)
leaq -0x388(%rbp), %rdi
callq 0x1e390
movq -0x358(%rbp), %rdi
callq 0x67a0
nopl (%rax)