// File: istellartech[P]OpenTsiolkovsky/src/rocket.cpp
// Function: RocketStage::free_flight_aerodynamic_stable(std::array<double, 14ul> const&, double)
void RocketStage::free_flight_aerodynamic_stable(const RocketStage::state& x, double t){
    flight_mode = "free_aero_stable";
    angle_of_attack_ << 0.0, 0.0, 0.0;
    vel_BODY_NEDframe_ = vel_ECEF_NEDframe_ - vel_wind_NEDframe_;
    vel_AIR_BODYframe_ << vel_BODY_NEDframe_.norm(), 0.0, 0.0;
    Vector2d azel;
    azel = azimuth_elevation(vel_BODY_NEDframe_);
    azimuth = azel[0];
    elevation = azel[1];
    // roll = roll;
    dcmNED2BODY_ = dcmNED2BODY(azimuth, elevation, roll);
    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_pitch = force_normal_yaw = 0.0;
    force_air_vector_BODYframe << -force_axial, 0.0, 0.0;
    //    dv/dt
    accECI_ = 1/x[0] * (dcmBODY2ECI_ * (force_thrust_vector + force_air_vector_BODYframe))
            + gravityECI_;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3c0, %rsp            # imm = 0x3C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x328(%rbp)
addq $0x230, %rdi            # imm = 0x230
leaq 0x3994c(%rip), %rsi     # 0x53c6d
callq 0x6600
movq -0x328(%rbp), %rsi
addq $0xc30, %rsi            # imm = 0xC30
movq $0x0, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x320(%rbp)
leaq -0x40(%rbp), %rdx
callq 0x1e1e0
movq -0x320(%rbp), %rdi
movq $0x0, -0x48(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x1e220
movq %rax, -0x318(%rbp)
jmp 0x1a371
movq -0x318(%rbp), %rdi
movq $0x0, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x1e220
jmp 0x1a38b
leaq -0x38(%rbp), %rdi
callq 0x1e390
movq -0x328(%rbp), %rdx
movq %rdx, %rsi
addq $0xbb8, %rsi            # imm = 0xBB8
addq $0xbd0, %rdx            # imm = 0xBD0
leaq -0x78(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0x20e20
movq -0x350(%rbp), %rsi
movq -0x328(%rbp), %rdi
addq $0xc18, %rdi            # imm = 0xC18
movq %rdi, -0x348(%rbp)
callq 0x20e90
movq -0x348(%rbp), %rdi
movq -0x328(%rbp), %rax
addq $0xbe8, %rax            # imm = 0xBE8
movq %rax, -0x340(%rbp)
callq 0x205d0
movq -0x340(%rbp), %rsi
movsd %xmm0, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
movq %rdi, -0x338(%rbp)
leaq -0xa0(%rbp), %rdx
callq 0x1e1e0
movq -0x338(%rbp), %rdi
movq $0x0, -0xa8(%rbp)
leaq -0xa8(%rbp), %rsi
callq 0x1e220
movq %rax, -0x330(%rbp)
jmp 0x1a44d
movq -0x330(%rbp), %rdi
movq $0x0, -0xb0(%rbp)
leaq -0xb0(%rbp), %rsi
callq 0x1e220
jmp 0x1a46d
leaq -0x98(%rbp), %rdi
callq 0x1e390
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x398(%rbp)
callq 0x1d690
movq -0x328(%rbp), %rsi
addq $0xc18, %rsi            # imm = 0xC18
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x3a8(%rbp)
callq 0x1f0e0
movq -0x3a8(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
callq 0x4bfe0
movq -0x3a0(%rbp), %rsi
movq -0x398(%rbp), %rdi
callq 0x20ec0
movq -0x398(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20050
movq -0x398(%rbp), %rdi
movq %rax, %rcx
movq -0x328(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x928(%rax)
movl $0x1, %esi
callq 0x20050
movq %rax, %rcx
movq -0x328(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x930(%rax)
movsd 0x928(%rax), %xmm0
movsd 0x930(%rax), %xmm1
movsd 0x938(%rax), %xmm2
leaq -0x130(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x4bb40
movq -0x390(%rbp), %rsi
movq -0x328(%rbp), %rdi
addq $0xc90, %rdi            # imm = 0xC90
movq %rdi, -0x388(%rbp)
callq 0x20370
movq -0x388(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x380(%rbp)
callq 0x203a0
movq -0x328(%rbp), %rsi
addq $0xb28, %rsi            # imm = 0xB28
leaq -0x208(%rbp), %rdi
movq %rdi, -0x378(%rbp)
callq 0x203a0
movq -0x380(%rbp), %rsi
movq -0x378(%rbp), %rdx
leaq -0x178(%rbp), %rdi
movq %rdi, -0x370(%rbp)
callq 0x4c2f0
movq -0x370(%rbp), %rsi
movq -0x328(%rbp), %rdi
addq $0xcd8, %rdi            # imm = 0xCD8
movq %rdi, -0x368(%rbp)
callq 0x20370
movq -0x368(%rbp), %rdi
callq 0x20450
movq -0x328(%rbp), %rdi
movq %rax, -0x210(%rbp)
addq $0xd20, %rdi            # imm = 0xD20
leaq -0x210(%rbp), %rsi
callq 0x20480
movq -0x328(%rbp), %rsi
addq $0xe28, %rsi            # imm = 0xE28
movq $0x0, -0x238(%rbp)
leaq -0x230(%rbp), %rdi
movq %rdi, -0x360(%rbp)
leaq -0x238(%rbp), %rdx
callq 0x1e1e0
movq -0x360(%rbp), %rdi
movq $0x0, -0x240(%rbp)
leaq -0x240(%rbp), %rsi
callq 0x1e220
movq %rax, -0x358(%rbp)
jmp 0x1a677
movq -0x358(%rbp), %rdi
movq $0x0, -0x248(%rbp)
leaq -0x248(%rbp), %rsi
callq 0x1e220
jmp 0x1a697
leaq -0x230(%rbp), %rdi
callq 0x1e390
movq -0x328(%rbp), %rdi
addq $0xbe8, %rdi            # imm = 0xBE8
callq 0x205d0
movq -0x328(%rbp), %rdi
movsd %xmm0, 0x7c8(%rdi)
movsd 0x7c8(%rdi), %xmm0
movsd 0x900(%rdi), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x958(%rdi)
callq 0x1b340
movq -0x328(%rbp), %rax
movsd 0x7c8(%rax), %xmm1
movsd 0x910(%rax), %xmm0
movsd 0x3875b(%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)
movq $0x0, 0x7f0(%rax)
movq $0x0, 0x7e8(%rax)
movq %rax, %rsi
addq $0xdf8, %rsi            # imm = 0xDF8
movsd 0x7e0(%rax), %xmm0
movaps 0x388d0(%rip), %xmm1    # 0x53040
pxor %xmm1, %xmm0
movlpd %xmm0, -0x270(%rbp)
leaq -0x268(%rbp), %rdi
movq %rdi, -0x3b8(%rbp)
leaq -0x270(%rbp), %rdx
callq 0x1e1e0
movq -0x3b8(%rbp), %rdi
movq $0x0, -0x278(%rbp)
leaq -0x278(%rbp), %rsi
callq 0x1e220
movq %rax, -0x3b0(%rbp)
jmp 0x1a7bd
movq -0x3b0(%rbp), %rdi
movq $0x0, -0x280(%rbp)
leaq -0x280(%rbp), %rsi
callq 0x1e220
jmp 0x1a7dd
leaq -0x268(%rbp), %rdi
callq 0x1e390
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20340
movq -0x328(%rbp), %rdx
movsd 0x3783b(%rip), %xmm0    # 0x52040
divsd (%rax), %xmm0
movsd %xmm0, -0x2c0(%rbp)
movq %rdx, %rax
addq $0xd20, %rax            # imm = 0xD20
movq %rax, -0x3c0(%rbp)
movq %rdx, %rsi
addq $0xe28, %rsi            # imm = 0xE28
addq $0xdf8, %rdx            # imm = 0xDF8
leaq -0x310(%rbp), %rdi
callq 0x20d10
movq -0x3c0(%rbp), %rsi
leaq -0x2f8(%rbp), %rdi
leaq -0x310(%rbp), %rdx
callq 0x20cc0
leaq -0x2b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
leaq -0x2f8(%rbp), %rdx
callq 0x20c80
movq -0x328(%rbp), %rdx
addq $0xe58, %rdx            # imm = 0xE58
leaq -0x2a8(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x20d80
movq -0x328(%rbp), %rdi
addq $0x9f0, %rdi            # imm = 0x9F0
leaq -0x2a8(%rbp), %rsi
callq 0x20df0
addq $0x3c0, %rsp            # imm = 0x3C0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1e390
jmp 0x1a919
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x1e390
jmp 0x1a919
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x1e390
jmp 0x1a919
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x1e390
movq -0x50(%rbp), %rdi
callq 0x67a0
nopw %cs:(%rax,%rax)