// File: /workspace/github_cpp_makefile_star2_O3/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
movsd %xmm0, (%rsp)
movq %rdi, %rbx
movaps 0x13eef(%rip), %xmm0    # 0x25010
movaps %xmm0, 0x110(%rsp)
movabsq $0x4071f0d97f62b6ae, %rax # imm = 0x4071F0D97F62B6AE
movq %rax, 0x120(%rsp)
movups 0x146be(%rip), %xmm0    # 0x25800
movups %xmm0, 0x128(%rsp)
movups 0x146bf(%rip), %xmm0    # 0x25810
movups %xmm0, 0x138(%rsp)
movups 0x14ee0(%rip), %xmm0    # 0x26040
movups %xmm0, 0x148(%rsp)
movups 0x14ee1(%rip), %xmm0    # 0x26050
movups %xmm0, 0x158(%rsp)
movups 0x14ee2(%rip), %xmm0    # 0x26060
movups %xmm0, 0x168(%rsp)
movups 0x14ee3(%rip), %xmm0    # 0x26070
movups %xmm0, 0x178(%rsp)
movups 0x14ee4(%rip), %xmm0    # 0x26080
movups %xmm0, 0x188(%rsp)
movups 0x14ee5(%rip), %xmm0    # 0x26090
movups %xmm0, 0x198(%rsp)
movups 0x14ee6(%rip), %xmm0    # 0x260a0
movups %xmm0, 0x1a8(%rsp)
movups 0x14ee7(%rip), %xmm0    # 0x260b0
movups %xmm0, 0x1b8(%rsp)
movups 0x14f18(%rip), %xmm0    # 0x260f0
movups %xmm0, 0x1f8(%rsp)
movups 0x14ef9(%rip), %xmm0    # 0x260e0
movups %xmm0, 0x1e8(%rsp)
movups 0x14eda(%rip), %xmm0    # 0x260d0
movups %xmm0, 0x1d8(%rsp)
movups 0x14ebb(%rip), %xmm0    # 0x260c0
movups %xmm0, 0x1c8(%rsp)
movl $0x0, 0x208(%rsp)
movaps 0x13e21(%rip), %xmm0    # 0x25040
movaps %xmm0, 0x210(%rsp)
movaps 0x13df2(%rip), %xmm0    # 0x25020
movaps %xmm0, 0x220(%rsp)
cmpb $0x1, 0x290(%rdi)
movsd %xmm1, 0x10(%rsp)
jne 0x112da
movsd 0xa90(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x2b8(%rbx), %r14
movq 0x2c0(%rbx), %rdx
movq 0x2c8(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0x230(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
movsd 0x8(%rsp), %xmm0
callq 0x622a
leaq 0x110(%rsp), %rdi
leaq 0x230(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x52f0
movq 0xf8(%rsp), %rdi
callq 0x5460
jmp 0x11315
movapd %xmm1, %xmm2
movsd 0x270(%rbx), %xmm1
leaq 0x230(%rsp), %r14
leaq 0x110(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
movapd %xmm2, %xmm0
callq 0x5e9c
movl $0x120, %edx            # imm = 0x120
movq %r15, %rdi
movq %r14, %rsi
callq 0x52f0
cmpb $0x1, 0x430(%rbx)
jne 0x113af
movsd 0x748(%rbx), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x4c0(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x458(%rbx), %r14
movq 0x460(%rbx), %rdx
movq 0x468(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
movsd (%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
leaq 0xe0(%rsp), %rdi
movl $0x1, %esi
callq 0x1a99c
movsd %xmm0, 0x788(%rbx)
movq 0xe0(%rsp), %rdi
callq 0x5460
jmp 0x113bf
movsd 0x478(%rbx), %xmm0
movsd %xmm0, 0x788(%rbx)
movsd 0x748(%rbx), %xmm2
cmpb $0x1, 0x480(%rbx)
jne 0x114c5
movsd %xmm2, 0x8(%rsp)
movsd 0x4c0(%rbx), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x4a8(%rbx), %r14
movq 0x4b0(%rbx), %rdx
movq 0x4b8(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
movsd (%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
leaq 0xc8(%rsp), %rdi
movl $0x1, %esi
callq 0x1a99c
movsd %xmm0, 0x778(%rbx)
movq 0xc8(%rsp), %rdi
callq 0x5460
movsd 0x778(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1146f
jnp 0x115b2
movsd 0x748(%rbx), %xmm0
movsd 0x4d0(%rbx), %xmm1
addsd %xmm0, %xmm1
movsd (%rsp), %xmm2
ucomisd %xmm1, %xmm2
jb 0x115b2
movsd 0x4e0(%rbx), %xmm2
divsd 0x4c0(%rbx), %xmm2
addsd %xmm2, %xmm1
ucomisd (%rsp), %xmm1
jbe 0x115b2
addsd 0x4e8(%rbx), %xmm0
ucomisd (%rsp), %xmm0
ja 0x11522
jmp 0x115b2
movsd 0x4d0(%rbx), %xmm0
addsd %xmm2, %xmm0
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x115b2
movsd 0x4e0(%rbx), %xmm1
divsd 0x4c0(%rbx), %xmm1
addsd %xmm1, %xmm0
ucomisd (%rsp), %xmm0
jbe 0x115b2
addsd 0x4e8(%rbx), %xmm2
ucomisd (%rsp), %xmm2
jbe 0x115b2
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 0x1479e(%rip), %xmm2    # 0x25d40
jbe 0x115cd
divsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movapd %xmm0, %xmm3
jmp 0x115cd
movb $0x0, 0x254(%rbx)
xorl %eax, %eax
movq %rax, 0x760(%rbx)
movq %rax, 0x790(%rbx)
xorpd %xmm3, %xmm3
movsd %xmm3, 0x780(%rbx)
cmpb $0x1, 0x5b8(%rbx)
jne 0x1173c
leaq 0x5e0(%rbx), %r14
movq 0x5e8(%rbx), %rdx
movq 0x5f0(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0xb0(%rsp), %rdi
movsd (%rsp), %xmm0
movl $0x1, %esi
callq 0x1a99c
divsd 0x146d8(%rip), %xmm0    # 0x25d10
mulsd 0x146d8(%rip), %xmm0    # 0x25d18
movsd %xmm0, 0x940(%rbx)
movq 0xb0(%rsp), %rdi
callq 0x5460
movq 0x5e8(%rbx), %rdx
movq 0x5f0(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0x98(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0x98(%rsp), %rdi
movsd (%rsp), %xmm0
movl $0x2, %esi
callq 0x1a99c
divsd 0x1466c(%rip), %xmm0    # 0x25d10
mulsd 0x1466c(%rip), %xmm0    # 0x25d18
movsd %xmm0, 0x948(%rbx)
movq 0x98(%rsp), %rdi
callq 0x5460
cmpq $0x4, 0x5f0(%rbx)
jne 0x1175c
movq 0x5e8(%rbx), %rdx
leaq (,%rdx,4), %rsi
leaq 0x80(%rsp), %r15
movl $0x4, %ecx
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0x80(%rsp), %rdi
movsd (%rsp), %xmm0
movl $0x3, %esi
callq 0x1a99c
divsd 0x145f3(%rip), %xmm0    # 0x25d10
mulsd 0x145f3(%rip), %xmm0    # 0x25d18
movsd %xmm0, 0x950(%rbx)
movq 0x80(%rsp), %rdi
callq 0x5460
jmp 0x1177c
movupd 0x5f8(%rbx), %xmm0
divpd 0x14854(%rip), %xmm0    # 0x25fa0
mulpd 0x1485c(%rip), %xmm0    # 0x25fb0
movapd %xmm0, 0x940(%rbx)
movsd 0x608(%rbx), %xmm0
divsd 0x145a4(%rip), %xmm0    # 0x25d10
mulsd 0x145a4(%rip), %xmm0    # 0x25d18
movsd %xmm0, 0x950(%rbx)
cmpb $0x1, 0x2d0(%rbx)
jne 0x11882
leaq 0x328(%rbx), %r14
movq 0x330(%rbx), %rdx
movq 0x338(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0x68(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0x68(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
movl $0x1, %esi
callq 0x1a99c
movsd %xmm0, 0x8(%rsp)
movq 0x68(%rsp), %rdi
callq 0x5460
movq 0x330(%rbx), %rdx
movq 0x338(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0x50(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0x50(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
movl $0x2, %esi
callq 0x1a99c
movsd %xmm0, 0x10(%rsp)
movq 0x50(%rsp), %rdi
callq 0x5460
movsd 0x10(%rsp), %xmm1
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
xorps %xmm2, %xmm2
sqrtsd %xmm3, %xmm2
movsd %xmm2, 0x918(%rbx)
callq 0x50a0
movsd 0x144a0(%rip), %xmm1    # 0x25d10
mulsd %xmm1, %xmm0
divsd 0x1449c(%rip), %xmm0    # 0x25d18
addsd %xmm1, %xmm0
jmp 0x1189a
movsd 0x2f8(%rbx), %xmm1
movsd 0x300(%rbx), %xmm0
movsd %xmm1, 0x918(%rbx)
movsd %xmm0, 0x920(%rbx)
cmpb $0x1, 0x680(%rbx)
jne 0x1198c
leaq 0x710(%rbx), %r14
movq 0x718(%rbx), %rdx
movq 0x720(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0x38(%rsp), %rdi
movsd (%rsp), %xmm0
movl $0x1, %esi
callq 0x1a99c
movsd %xmm0, 0x978(%rbx)
movq 0x38(%rsp), %rdi
callq 0x5460
movq 0x718(%rbx), %rdx
movq 0x720(%rbx), %rcx
movq %rcx, %rsi
imulq %rdx, %rsi
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x69e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6a4e
leaq 0x20(%rsp), %rdi
movsd (%rsp), %xmm0
movl $0x2, %esi
callq 0x1a99c
movsd %xmm0, 0x990(%rbx)
movq 0x20(%rsp), %rdi
callq 0x5460
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 (%rsp), %xmm0
ucomisd 0x750(%rbx), %xmm0
jb 0x119ab
cmpb $0x0, 0x255(%rbx)
jne 0x119ab
movb $0x1, 0x255(%rbx)
addq $0x350, %rsp            # imm = 0x350
popq %rbx
popq %r14
popq %r15
retq
jmp 0x119ba
movq %rax, %rbx
movq 0x80(%rsp), %rdi
jmp 0x11a40
jmp 0x119c9
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x11a40
jmp 0x119d7
jmp 0x119e1
movq %rax, %rbx
movq 0x38(%rsp), %rdi
jmp 0x11a40
movq %rax, %rbx
movq 0x50(%rsp), %rdi
jmp 0x11a40
jmp 0x119ef
jmp 0x119f9
movq %rax, %rbx
movq 0x68(%rsp), %rdi
jmp 0x11a40
movq %rax, %rbx
movq 0x98(%rsp), %rdi
jmp 0x11a40
jmp 0x11a08
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
jmp 0x11a40
jmp 0x11a17
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
jmp 0x11a40
jmp 0x11a26
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
jmp 0x11a40
jmp 0x11a35
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
callq 0x5460
movq %rbx, %rdi
callq 0x5650
nop