// File: /workspace/github_cpp_makefile_star2_O2/istellartech[P]OpenTsiolkovsky/src/rocket.cpp
// Function: RocketStage::update_from_mach_number()
void RocketStage::update_from_mach_number(){
    double angle_sign, angle_abs;
    double alpha, beta;

    if (CA_file_exist) {
        CA = interp_matrix(mach_number, CA_mat);
    } else {
        CA = CA_const;
    }
    CA *= CA_multiplier;

    if (CN_file_exist) {
        alpha = rad2deg(angle_of_attack_[0]);
        beta  = rad2deg(angle_of_attack_[1]);

        // pitch
        angle_abs = abs(alpha);
        if(angle_abs < 1e-9){
            angle_sign = 0.0;
        }else{
            angle_sign = alpha / angle_abs;
        }

        CN_pitch = angle_sign * interp_matrix_2d(mach_number, angle_abs, CN_mat);
        if ( is_consider_neutrality ) {
            pos_CP_pitch = interp_matrix_2d(mach_number, angle_abs, Xcp_mat);
            pos_CP_pitch -= Xcp_offset;     // +X direction = -STA direction
        }

        // yaw
        angle_abs = abs(beta);
        if(angle_abs < 1e-9){
            angle_sign = 0.0;
        }else{
            angle_sign = beta / angle_abs;
        }

        CN_yaw = angle_sign * interp_matrix_2d(mach_number, angle_abs, CN_mat);
        if ( is_consider_neutrality ) {
            pos_CP_yaw = interp_matrix_2d(mach_number, angle_abs, Xcp_mat);
            pos_CP_yaw -= Xcp_offset;       // +X direction = -STA direction
        }
    } else {
        CN_pitch = CN_const;
        CN_yaw   = CN_const;
        if ( is_consider_neutrality ) {
            std::cout << "ERROR: you must specify the non-constant CN when you use neutrality calculation.\n";
            exit(1);
        }
    }
    CN_pitch *= CN_multiplier;
    CN_yaw   *= CN_multiplier;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movq %rdi, %rbx
cmpb $0x1, 0x570(%rdi)
jne 0xe513
movsd 0x958(%rbx), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x598(%rbx), %rsi
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
callq 0x643a
pushq $0x1
popq %rsi
movsd 0x20(%rsp), %xmm0
movq %r14, %rdi
callq 0x15eb4
movsd %xmm0, 0x7a0(%rbx)
movq 0xa8(%rsp), %rdi
callq 0x5430
movsd 0x7a0(%rbx), %xmm0
jmp 0xe523
movsd 0x568(%rbx), %xmm0
movsd %xmm0, 0x7a0(%rbx)
mulsd 0x5b0(%rbx), %xmm0
movsd %xmm0, 0x7a0(%rbx)
cmpb $0x1, 0x520(%rbx)
jne 0xe757
movsd 0x118b8(%rip), %xmm0    # 0x1fe00
movsd 0xc30(%rbx), %xmm1
mulsd %xmm0, %xmm1
divsd 0x118ac(%rip), %xmm1    # 0x1fe08
mulsd 0xc38(%rbx), %xmm0
movapd %xmm0, 0x20(%rsp)
movapd 0x10ade(%rip), %xmm0    # 0x1f050
movapd %xmm1, 0x30(%rsp)
andpd %xmm1, %xmm0
movapd %xmm0, 0x10(%rsp)
movsd 0x958(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x550(%rbx), %r15
leaq 0x90(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x643a
movsd 0x8(%rsp), %xmm0
movapd 0x10(%rsp), %xmm1
movq %r14, %rdi
callq 0x16047
movapd 0x10(%rsp), %xmm1
movapd 0x30(%rsp), %xmm2
divsd %xmm1, %xmm2
cmpltsd 0x11859(%rip), %xmm1    # 0x1fe30
andnpd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7a8(%rbx)
movq 0x90(%rsp), %rdi
callq 0x5430
cmpb $0x1, 0x680(%rbx)
jne 0xe65d
movsd 0x958(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x728(%rbx), %rsi
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x643a
movsd 0x8(%rsp), %xmm0
movapd 0x10(%rsp), %xmm1
movq %r14, %rdi
callq 0x16047
movsd %xmm0, 0x980(%rbx)
movq 0x78(%rsp), %rdi
callq 0x5430
movsd 0x980(%rbx), %xmm0
subsd 0x6e0(%rbx), %xmm0
movsd %xmm0, 0x980(%rbx)
movapd 0x20(%rsp), %xmm0
divsd 0x1179d(%rip), %xmm0    # 0x1fe08
movapd 0x109dd(%rip), %xmm1    # 0x1f050
movapd %xmm0, 0x20(%rsp)
andpd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movsd 0x958(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x643a
movsd 0x8(%rsp), %xmm0
movapd 0x10(%rsp), %xmm1
movq %r14, %rdi
callq 0x16047
movapd 0x10(%rsp), %xmm1
movapd 0x20(%rsp), %xmm2
divsd %xmm1, %xmm2
cmpltsd 0x11762(%rip), %xmm1    # 0x1fe30
andnpd %xmm2, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x7b0(%rbx)
movq 0x60(%rsp), %rdi
callq 0x5430
cmpb $0x1, 0x680(%rbx)
jne 0xe778
movsd 0x958(%rbx), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x728(%rbx), %rsi
leaq 0x48(%rsp), %r14
movq %r14, %rdi
callq 0x643a
movsd 0x20(%rsp), %xmm0
movapd 0x10(%rsp), %xmm1
movq %r14, %rdi
callq 0x16047
movsd %xmm0, 0x988(%rbx)
movq 0x48(%rsp), %rdi
callq 0x5430
movsd 0x988(%rbx), %xmm0
subsd 0x6e0(%rbx), %xmm0
movsd %xmm0, 0x988(%rbx)
jmp 0xe778
movsd 0x518(%rbx), %xmm0
movsd %xmm0, 0x7a8(%rbx)
movsd %xmm0, 0x7b0(%rbx)
cmpb $0x1, 0x680(%rbx)
je 0xe7a5
movupd 0x548(%rbx), %xmm0
movupd 0x7a8(%rbx), %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm1, %xmm0
movupd %xmm0, 0x7a8(%rbx)
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0x20804(%rip), %rdi     # 0x2efb0
leaq 0x1229a(%rip), %rsi     # 0x20a4d
callq 0x5370
pushq $0x1
popq %rdi
callq 0x5440
jmp 0xe7c8
jmp 0xe7c8
jmp 0xe7c8
jmp 0xe7c8
movq %rax, %rbx
movq (%r14), %rdi
callq 0x5430
movq %rbx, %rdi
callq 0x5640
nop