// File: 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 %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
testb $0x1, 0x570(%rax)
je 0x1b3f4
movq -0xb8(%rbp), %rsi
movsd 0x958(%rsi), %xmm0
movsd %xmm0, -0xd0(%rbp)
addq $0x598, %rsi            # imm = 0x598
leaq -0x40(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x8170
movsd -0xd0(%rbp), %xmm0
movq -0xc8(%rbp), %rdi
movl $0x1, %esi
callq 0x3b470
movsd %xmm0, -0xc0(%rbp)
jmp 0x1b3b8
movq -0xb8(%rbp), %rax
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, 0x7a0(%rax)
leaq -0x40(%rbp), %rdi
callq 0x8220
jmp 0x1b40b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x8220
jmp 0x1b8a3
movq -0xb8(%rbp), %rax
movsd 0x568(%rax), %xmm0
movsd %xmm0, 0x7a0(%rax)
movq -0xb8(%rbp), %rax
movsd 0x5b0(%rax), %xmm0
mulsd 0x7a0(%rax), %xmm0
movsd %xmm0, 0x7a0(%rax)
testb $0x1, 0x520(%rax)
je 0x1b814
movq -0xb8(%rbp), %rdi
addq $0xc30, %rdi            # imm = 0xC30
xorl %eax, %eax
movl %eax, %esi
callq 0x1de40
movsd (%rax), %xmm0
callq 0x205a0
movq -0xb8(%rbp), %rdi
movsd %xmm0, -0x20(%rbp)
addq $0xc30, %rdi            # imm = 0xC30
movl $0x1, %esi
callq 0x1de40
movsd (%rax), %xmm0
callq 0x205a0
movsd %xmm0, -0x28(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x8450
movsd %xmm0, -0x18(%rbp)
movsd 0x379af(%rip), %xmm0    # 0x52e48
ucomisd -0x18(%rbp), %xmm0
jbe 0x1b4aa
xorps %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0x1b4b9
movsd -0x20(%rbp), %xmm0
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movq -0xb8(%rbp), %rsi
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd 0x958(%rsi), %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
addq $0x550, %rsi            # imm = 0x550
leaq -0x68(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x8170
movsd -0xf0(%rbp), %xmm0
movsd -0xe8(%rbp), %xmm1
movq -0xe0(%rbp), %rdi
callq 0x3b6e0
movsd %xmm0, -0xd8(%rbp)
jmp 0x1b527
movq -0xb8(%rbp), %rax
movsd -0xd8(%rbp), %xmm1
movsd -0xf8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7a8(%rax)
leaq -0x68(%rbp), %rdi
callq 0x8220
movq -0xb8(%rbp), %rax
testb $0x1, 0x680(%rax)
je 0x1b641
movq -0xb8(%rbp), %rsi
movsd 0x958(%rsi), %xmm0
movsd %xmm0, -0x118(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x110(%rbp)
addq $0x728, %rsi            # imm = 0x728
leaq -0x80(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x8170
movsd -0x118(%rbp), %xmm0
movsd -0x110(%rbp), %xmm1
movq -0x108(%rbp), %rdi
callq 0x3b6e0
movsd %xmm0, -0x100(%rbp)
jmp 0x1b5c8
movq -0xb8(%rbp), %rax
movsd -0x100(%rbp), %xmm0
movsd %xmm0, 0x980(%rax)
leaq -0x80(%rbp), %rdi
callq 0x8220
movq -0xb8(%rbp), %rax
movsd 0x6e0(%rax), %xmm1
movsd 0x980(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x980(%rax)
jmp 0x1b641
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x8220
jmp 0x1b8a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x8220
jmp 0x1b8a3
movsd -0x28(%rbp), %xmm0
callq 0x8450
movsd %xmm0, -0x18(%rbp)
movsd 0x377f0(%rip), %xmm0    # 0x52e48
ucomisd -0x18(%rbp), %xmm0
jbe 0x1b669
xorps %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0x1b678
movsd -0x28(%rbp), %xmm0
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movq -0xb8(%rbp), %rsi
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x140(%rbp)
movsd 0x958(%rsi), %xmm0
movsd %xmm0, -0x138(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
addq $0x550, %rsi            # imm = 0x550
leaq -0x98(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x8170
movsd -0x138(%rbp), %xmm0
movsd -0x130(%rbp), %xmm1
movq -0x128(%rbp), %rdi
callq 0x3b6e0
movsd %xmm0, -0x120(%rbp)
jmp 0x1b6e9
movq -0xb8(%rbp), %rax
movsd -0x120(%rbp), %xmm1
movsd -0x140(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x7b0(%rax)
leaq -0x98(%rbp), %rdi
callq 0x8220
movq -0xb8(%rbp), %rax
testb $0x1, 0x680(%rax)
je 0x1b812
movq -0xb8(%rbp), %rsi
movsd 0x958(%rsi), %xmm0
movsd %xmm0, -0x160(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x158(%rbp)
addq $0x728, %rsi            # imm = 0x728
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x8170
movsd -0x160(%rbp), %xmm0
movsd -0x158(%rbp), %xmm1
movq -0x150(%rbp), %rdi
callq 0x3b6e0
movsd %xmm0, -0x148(%rbp)
jmp 0x1b790
movq -0xb8(%rbp), %rax
movsd -0x148(%rbp), %xmm0
movsd %xmm0, 0x988(%rax)
leaq -0xb0(%rbp), %rdi
callq 0x8220
movq -0xb8(%rbp), %rax
movsd 0x6e0(%rax), %xmm1
movsd 0x988(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x988(%rax)
jmp 0x1b812
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8220
jmp 0x1b8a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x8220
jmp 0x1b8a3
jmp 0x1b863
movq -0xb8(%rbp), %rax
movsd 0x518(%rax), %xmm0
movsd %xmm0, 0x7a8(%rax)
movsd 0x518(%rax), %xmm0
movsd %xmm0, 0x7b0(%rax)
testb $0x1, 0x680(%rax)
je 0x1b861
movq 0x5d765(%rip), %rdi     # 0x78fb0
leaq 0x3838b(%rip), %rsi     # 0x53bdd
callq 0x6460
movl $0x1, %edi
callq 0x6580
jmp 0x1b863
movq -0xb8(%rbp), %rax
movsd 0x548(%rax), %xmm0
mulsd 0x7a8(%rax), %xmm0
movsd %xmm0, 0x7a8(%rax)
movsd 0x548(%rax), %xmm0
mulsd 0x7b0(%rax), %xmm0
movsd %xmm0, 0x7b0(%rax)
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x67a0
nopl (%rax)