// File: /workspace/github_cpp_makefile_star2_O2/istellartech[P]OpenTsiolkovsky/src/rocket.cpp
// Function: RocketStage::update_from_time_and_altitude(double, double)
void RocketStage::update_from_time_and_altitude(double time, double altitude){
    Air air;
    //    air = air.altitude(altitude);
    if (air_density_file_exist){
        air = air.altitude_with_variation_table(posLLH_[2], air_density_mat);
    } else{
        air = air.altitude_with_variation(altitude, variation_ratio_of_air_density);
    }

    if (Isp_file_exist){
        Isp_vac = interp_matrix((time - previous_stage_separation_time) * thrust_coeff, Isp_mat);  // Isp vac
    } else {
        Isp_vac = Isp_const;  // Isp vac
    }
    if (thrust_file_exist){
        thrust_vac = interp_matrix((time - previous_stage_separation_time) * thrust_coeff, thrust_mat, 1);
        // nozzle_exhaust_pressure = interp_matrix((time - previous_stage_separation_time) * thrust_coeff, thrust_mat, 2);
        if (thrust_vac != 0 &&
            time >= previous_stage_separation_time + burn_start_time &&
            time < previous_stage_separation_time + burn_start_time + burn_time / thrust_coeff &&
            time < previous_stage_separation_time + forced_cutoff_time) {
            is_powered = true;
        } else {
            is_powered = false;
        }
    } else {
        if (time >= previous_stage_separation_time + burn_start_time &&
            time < previous_stage_separation_time + burn_start_time + burn_time / thrust_coeff &&
            time < previous_stage_separation_time + forced_cutoff_time){
            thrust_vac = thrust_const;
            is_powered = true;
        } else {
            is_powered = false;
        }
    }
    if (is_powered){ // ---- powered flight ----
        Isp_vac                 *= Isp_coeff;
        thrust_vac              *= Isp_coeff * thrust_coeff;
        // nozzle_exhaust_pressure *= Isp_coeff * thrust_coeff;

        m_dot = thrust_vac / Isp_vac / g0;
        // thrust_momentum = thrust_vac - nozzle_exhaust_area * nozzle_exhaust_pressure;
        thrust = thrust_vac - nozzle_exhaust_area * air.pressure;
        if (m_dot > 0.0001) {
            Isp = thrust / m_dot / g0;
        } else {
            Isp = 0.0;
        }
    } else {
        thrust = 0.0;
        m_dot = 0.0;
        Isp = 0.0;
    }

    if (attitude_file_exist) {
        azimuth_target = deg2rad(interp_matrix(time, attitude_mat, 1));
        elevation_target = deg2rad(interp_matrix(time, attitude_mat, 2));
        if (attitude_mat.cols() == 4) {
            roll_target = deg2rad(interp_matrix(time, attitude_mat, 3));
        } else {
            roll_target = deg2rad(attitude_roll_const_deg);
        }
    } else {
        azimuth_target = deg2rad(attitude_azimuth_const_deg);
        elevation_target = deg2rad(attitude_elevation_const_deg);
        roll_target = deg2rad(attitude_roll_const_deg);
    }

    if (wind_file_exist) {
        double wind_u = interp_matrix(altitude, wind_mat_uv, 1);
        double wind_v = interp_matrix(altitude, wind_mat_uv, 2);
        wind_speed = sqrt(wind_u * wind_u + wind_v * wind_v);
        wind_direction = rad2deg(atan2(wind_u, wind_v)) + 180.;
    } else {
        wind_speed = wind_const[0];
        wind_direction = wind_const[1];
    }

    if (is_consider_neutrality) {
        pos_CG         = interp_matrix(time, CGXt_mat, 1);
        pos_Controller = interp_matrix(time, CGXt_mat, 2);

        pos_CG -= Xcg_offset;               // +X direction = -STA direction
        pos_Controller -= Xt_offset;        // +X direction = -STA direction
    }

    if (time >= later_stage_separation_time && is_separated == false){
        is_separated = true;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x350, %rsp            # imm = 0x350
movapd %xmm1, %xmm2
movaps 0x12417(%rip), %xmm1    # 0x1f020
movaps %xmm1, 0x110(%rsp)
movabsq $0x4071f0d97f62b6ae, %rax # imm = 0x4071F0D97F62B6AE
movq %rax, 0x120(%rsp)
movups 0x12bc6(%rip), %xmm1    # 0x1f7f0
movups %xmm1, 0x128(%rsp)
movups 0x12bc7(%rip), %xmm1    # 0x1f800
movups %xmm1, 0x138(%rsp)
movups 0x13478(%rip), %xmm1    # 0x200c0
movups %xmm1, 0x148(%rsp)
movups 0x13479(%rip), %xmm1    # 0x200d0
movups %xmm1, 0x158(%rsp)
movups 0x1347a(%rip), %xmm1    # 0x200e0
movups %xmm1, 0x168(%rsp)
movups 0x1347b(%rip), %xmm1    # 0x200f0
movups %xmm1, 0x178(%rsp)
movups 0x1347c(%rip), %xmm1    # 0x20100
movups %xmm1, 0x188(%rsp)
movups 0x1347d(%rip), %xmm1    # 0x20110
movups %xmm1, 0x198(%rsp)
movups 0x1347e(%rip), %xmm1    # 0x20120
movups %xmm1, 0x1a8(%rsp)
movups 0x1347f(%rip), %xmm1    # 0x20130
movups %xmm1, 0x1b8(%rsp)
movups 0x134b0(%rip), %xmm1    # 0x20170
movups %xmm1, 0x1f8(%rsp)
movups 0x13491(%rip), %xmm1    # 0x20160
movups %xmm1, 0x1e8(%rsp)
movups 0x13472(%rip), %xmm1    # 0x20150
movups %xmm1, 0x1d8(%rsp)
movupd 0x13452(%rip), %xmm1    # 0x20140
movupd %xmm1, 0x1c8(%rsp)
andl $0x0, 0x208(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
movaps 0x12321(%rip), %xmm0    # 0x1f030
movaps %xmm0, 0x210(%rsp)
movaps 0x12322(%rip), %xmm0    # 0x1f040
movaps %xmm0, 0x220(%rsp)
cmpb $0x1, 0x290(%rdi)
movsd %xmm2, 0x18(%rsp)
jne 0xcda1
movsd 0xa90(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x2b8(%rbx), %rsi
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
callq 0x643a
leaq 0x230(%rsp), %rdi
leaq 0x110(%rsp), %rsi
movsd 0x10(%rsp), %xmm0
movq %r14, %rdx
callq 0x5e24
leaq 0x110(%rsp), %rdi
leaq 0x230(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x52f0
movq 0xf8(%rsp), %rdi
callq 0x5430
jmp 0xcdd8
movsd 0x270(%rbx), %xmm1
leaq 0x230(%rsp), %r14
leaq 0x110(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
movapd %xmm2, %xmm0
callq 0x5ba8
movl $0x120, %edx            # imm = 0x120
movq %r15, %rdi
movq %r14, %rsi
callq 0x52f0
cmpb $0x1, 0x430(%rbx)
movsd 0x8(%rsp), %xmm4
jne 0xce42
subsd 0x748(%rbx), %xmm4
mulsd 0x4c0(%rbx), %xmm4
movsd %xmm4, 0x10(%rsp)
leaq 0x458(%rbx), %rsi
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
callq 0x643a
pushq $0x1
popq %rsi
movsd 0x10(%rsp), %xmm0
movq %r14, %rdi
callq 0x15eb4
movsd %xmm0, 0x788(%rbx)
movq 0xe0(%rsp), %rdi
callq 0x5430
movsd 0x8(%rsp), %xmm4
jmp 0xce52
movsd 0x478(%rbx), %xmm0
movsd %xmm0, 0x788(%rbx)
movsd 0x748(%rbx), %xmm0
cmpb $0x1, 0x480(%rbx)
jne 0xcf23
subsd %xmm0, %xmm4
mulsd 0x4c0(%rbx), %xmm4
movsd %xmm4, 0x10(%rsp)
leaq 0x4a8(%rbx), %rsi
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
callq 0x643a
pushq $0x1
popq %rsi
movsd 0x10(%rsp), %xmm0
movq %r14, %rdi
callq 0x15eb4
movsd %xmm0, 0x778(%rbx)
movq 0xc8(%rsp), %rdi
callq 0x5430
movsd 0x778(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm4
jne 0xced4
jnp 0xd009
movsd 0x748(%rbx), %xmm0
movsd 0x4d0(%rbx), %xmm1
addsd %xmm0, %xmm1
ucomisd %xmm1, %xmm4
jb 0xd009
movsd 0x4e0(%rbx), %xmm2
divsd 0x4c0(%rbx), %xmm2
addsd %xmm2, %xmm1
ucomisd %xmm4, %xmm1
jbe 0xd009
addsd 0x4e8(%rbx), %xmm0
ucomisd %xmm4, %xmm0
ja 0xcf79
jmp 0xd009
movsd 0x4d0(%rbx), %xmm1
addsd %xmm0, %xmm1
ucomisd %xmm1, %xmm4
jb 0xd009
movsd 0x4e0(%rbx), %xmm2
divsd 0x4c0(%rbx), %xmm2
addsd %xmm2, %xmm1
ucomisd %xmm4, %xmm1
jbe 0xd009
addsd 0x4e8(%rbx), %xmm0
ucomisd %xmm4, %xmm0
jbe 0xd009
movsd 0x4c8(%rbx), %xmm0
movsd %xmm0, 0x778(%rbx)
movb $0x1, 0x254(%rbx)
movsd 0x470(%rbx), %xmm0
movsd 0x788(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x788(%rbx)
mulsd 0x4c0(%rbx), %xmm0
mulsd 0x778(%rbx), %xmm0
movsd %xmm0, 0x778(%rbx)
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd 0x758(%rbx), %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, 0x790(%rbx)
movsd 0x798(%rbx), %xmm3
mulsd 0x220(%rsp), %xmm3
subsd %xmm3, %xmm0
movsd %xmm0, 0x760(%rbx)
xorpd %xmm3, %xmm3
ucomisd 0x12e27(%rip), %xmm2    # 0x1fe20
jbe 0xd024
divsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movapd %xmm0, %xmm3
jmp 0xd024
movb $0x0, 0x254(%rbx)
andq $0x0, 0x760(%rbx)
andq $0x0, 0x790(%rbx)
xorpd %xmm3, %xmm3
movsd %xmm3, 0x780(%rbx)
cmpb $0x1, 0x5b8(%rbx)
jne 0xd12b
leaq 0x5e0(%rbx), %r14
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643a
pushq $0x1
popq %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdi
callq 0x15eb4
divsd 0x12d94(%rip), %xmm0    # 0x1fe00
mulsd 0x12d94(%rip), %xmm0    # 0x1fe08
movsd %xmm0, 0x940(%rbx)
movq 0xb0(%rsp), %rdi
callq 0x5430
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643a
pushq $0x2
popq %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdi
callq 0x15eb4
divsd 0x12d4b(%rip), %xmm0    # 0x1fe00
mulsd 0x12d4b(%rip), %xmm0    # 0x1fe08
movsd %xmm0, 0x948(%rbx)
movq 0x98(%rsp), %rdi
callq 0x5430
cmpq $0x4, 0x5f0(%rbx)
jne 0xd16d
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643a
pushq $0x3
popq %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdi
callq 0x15eb4
divsd 0x12cf4(%rip), %xmm0    # 0x1fe00
mulsd 0x12cf4(%rip), %xmm0    # 0x1fe08
movsd %xmm0, 0x950(%rbx)
movq 0x80(%rsp), %rdi
callq 0x5430
jmp 0xd18d
movupd 0x5f8(%rbx), %xmm0
divpd 0x12f05(%rip), %xmm0    # 0x20040
mulpd 0x12f0d(%rip), %xmm0    # 0x20050
movapd %xmm0, 0x940(%rbx)
movsd 0x608(%rbx), %xmm0
divsd 0x12ca5(%rip), %xmm0    # 0x1fe00
mulsd 0x12ca5(%rip), %xmm0    # 0x1fe08
movsd %xmm0, 0x950(%rbx)
jmp 0xd193
movsd 0x608(%rbx), %xmm0
divsd 0x12c83(%rip), %xmm0    # 0x1fe00
mulsd 0x12c83(%rip), %xmm0    # 0x1fe08
movsd %xmm0, 0x950(%rbx)
movsd 0x8(%rsp), %xmm4
cmpb $0x1, 0x2d0(%rbx)
jne 0xd25a
leaq 0x328(%rbx), %r14
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643a
pushq $0x1
popq %rsi
movsd 0x18(%rsp), %xmm0
movq %r15, %rdi
callq 0x15eb4
movsd %xmm0, 0x10(%rsp)
movq 0x68(%rsp), %rdi
callq 0x5430
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643a
pushq $0x2
popq %rsi
movsd 0x18(%rsp), %xmm0
movq %r15, %rdi
callq 0x15eb4
movsd %xmm0, 0x18(%rsp)
movq 0x50(%rsp), %rdi
callq 0x5430
movsd 0x18(%rsp), %xmm1
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
sqrtsd %xmm3, %xmm2
movsd %xmm2, 0x918(%rbx)
callq 0x5090
movsd 0x12bbe(%rip), %xmm1    # 0x1fe00
mulsd %xmm1, %xmm0
divsd 0x12bba(%rip), %xmm0    # 0x1fe08
addsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm4
jmp 0xd272
movsd 0x2f8(%rbx), %xmm1
movsd 0x300(%rbx), %xmm0
movsd %xmm1, 0x918(%rbx)
movsd %xmm0, 0x920(%rbx)
cmpb $0x1, 0x680(%rbx)
jne 0xd32a
leaq 0x710(%rbx), %r14
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643a
pushq $0x1
popq %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdi
callq 0x15eb4
movsd %xmm0, 0x978(%rbx)
movq 0x38(%rsp), %rdi
callq 0x5430
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643a
pushq $0x2
popq %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdi
callq 0x15eb4
movsd %xmm0, 0x990(%rbx)
movq 0x20(%rsp), %rdi
callq 0x5430
movsd 0x978(%rbx), %xmm0
movsd 0x990(%rbx), %xmm1
subsd 0x6c8(%rbx), %xmm0
movsd %xmm0, 0x978(%rbx)
subsd 0x6f8(%rbx), %xmm1
movsd %xmm1, 0x990(%rbx)
movsd 0x8(%rsp), %xmm4
ucomisd 0x750(%rbx), %xmm4
jb 0xd344
cmpb $0x0, 0x255(%rbx)
jne 0xd344
movb $0x1, 0x255(%rbx)
addq $0x350, %rsp            # imm = 0x350
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x80(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0x38(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0x50(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0x68(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0x98(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
jmp 0xd3c5
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
callq 0x5430
movq %rbx, %rdi
callq 0x5640