// File: /workspace/github_cpp_makefile_star2_O2/istellartech[P]OpenTsiolkovsky/src/air.cpp
// Function: Air::coef_density_variance(double, double)
double Air::coef_density_variance(double altitude, double input_percent){
    // altitude : [m]
    // percent : [%](-100 ~ 100), enter 0 when nominal air density
    // @output coefficient of density variance : [-1.0 ~ 1.0]
    // cf. U.S. standard atmosphere PART2 Atmospheric Model 2.1.4 Density Variations
    if (input_percent == 0){
        return 0;
    }
    //vector<double> minus_x = {-12.8, -7.9, -1.3, -14.3, -15.9, -18.6, -32.1, -38.6, -50.0, -55.3, -65.0, -68.1, -76.7, -42.2};
    vector<double> minus_x = {21.6, 7.4, -1.3, -14.3, -15.9, -18.6, -32.1, -38.6, -50.0, -55.3, -65.0, -68.1, -76.7, -42.2};
    vector<double> minus_y = {1010, 4300, 8030, 10220, 16360, 20300, 26220, 29950, 40250, 50110, 59970, 70270, 80140, 90220};
    //vector<double> plus_x = {21.6, 7.4, 1.5, 5.3, 26.7, 20.2, 14.3, 18.2, 33.6, 47.4, 59.5, 72.2, 58.7, 41.4};
    vector<double> plus_x = {-12.8, -7.9, 1.5, 5.3, 26.7, 20.2, 14.3, 18.2, 33.6, 47.4, 59.5, 72.2, 58.7, 41.4};
    vector<double> plus_y = {1230, 4300, 8030, 10000, 16360, 20300, 26220, 29950, 40250, 50110, 59970, 70270, 80360, 90880};
    double percent_of_density_with_alt;
    if (input_percent < 0){
        percent_of_density_with_alt = linear_interp1_from_y(altitude, minus_x, minus_y);
    } else {
        percent_of_density_with_alt = linear_interp1_from_y(altitude, plus_x, plus_y);
    }
    return percent_of_density_with_alt / 100 * abs(input_percent) / 100;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movapd %xmm0, %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x5c10
jnp 0x5db8
movsd %xmm2, 0x8(%rsp)
movapd %xmm1, 0x10(%rsp)
leaq 0x1944d(%rip), %rsi     # 0x1f070
pushq $0xe
popq %rbx
leaq 0xe8(%rsp), %rax
movq %rbx, %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x70(%rsp), %rdi
leaq 0x58(%rsp), %rcx
movq %rax, %rsi
movq %rbx, %rdx
callq 0x6492
leaq 0x1948d(%rip), %rsi     # 0x1f0e0
leaq 0xe8(%rsp), %rax
movq %rbx, %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %rax, %rsi
movq %rbx, %rdx
callq 0x6492
leaq 0x194d0(%rip), %rsi     # 0x1f150
pushq $0xe
popq %rdx
leaq 0xe8(%rsp), %rax
movq %rdx, %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rcx
movq %rax, %rsi
callq 0x6492
leaq 0x19513(%rip), %rsi     # 0x1f1c0
pushq $0xe
popq %rdx
leaq 0xe8(%rsp), %rax
movq %rdx, %rcx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rcx
movq %rax, %rsi
callq 0x6492
xorpd %xmm0, %xmm0
ucomisd 0x10(%rsp), %xmm0
jbe 0x5d0b
leaq 0xa0(%rsp), %rbx
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x64c8
leaq 0xd0(%rsp), %r14
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x64c8
jmp 0x5d35
leaq 0x88(%rsp), %rbx
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x64c8
leaq 0xb8(%rsp), %r14
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x64c8
movsd 0x8(%rsp), %xmm0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5fff
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
callq 0x6870
movq %rbx, %rdi
callq 0x6870
movsd 0x19304(%rip), %xmm0    # 0x1f068
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm2
andpd 0x192d4(%rip), %xmm2    # 0x1f050
mulsd %xmm1, %xmm2
divsd %xmm0, %xmm2
movapd %xmm2, 0x10(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x6870
leaq 0x40(%rsp), %rdi
callq 0x6870
leaq 0x58(%rsp), %rdi
callq 0x6870
leaq 0x70(%rsp), %rdi
callq 0x6870
movapd 0x10(%rsp), %xmm0
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r14
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x5ddb
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x6870
jmp 0x5de5
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x6870
jmp 0x5df4
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x6870
jmp 0x5e03
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x6870
jmp 0x5e12
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x6870
movq %rbx, %rdi
callq 0x5640