// File: 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 %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x7246
jp 0x7246
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x7818
movups 0x4ae73(%rip), %xmm0    # 0x520c0
movaps %xmm0, -0x60(%rbp)
movups 0x4ae58(%rip), %xmm0    # 0x520b0
movaps %xmm0, -0x70(%rbp)
movups 0x4ae3d(%rip), %xmm0    # 0x520a0
movaps %xmm0, -0x80(%rbp)
movups 0x4ae22(%rip), %xmm0    # 0x52090
movaps %xmm0, -0x90(%rbp)
movups 0x4ae04(%rip), %xmm0    # 0x52080
movaps %xmm0, -0xa0(%rbp)
movups 0x4ade6(%rip), %xmm0    # 0x52070
movaps %xmm0, -0xb0(%rbp)
movups 0x4adc8(%rip), %xmm0    # 0x52060
movaps %xmm0, -0xc0(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0xe, -0x40(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0x8240
movq -0x328(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x8260
jmp 0x72df
leaq -0xc1(%rbp), %rdi
callq 0x82e0
movups 0x4ae3e(%rip), %xmm0    # 0x52130
movaps %xmm0, -0x110(%rbp)
movups 0x4ae20(%rip), %xmm0    # 0x52120
movaps %xmm0, -0x120(%rbp)
movups 0x4ae02(%rip), %xmm0    # 0x52110
movaps %xmm0, -0x130(%rbp)
movups 0x4ade4(%rip), %xmm0    # 0x52100
movaps %xmm0, -0x140(%rbp)
movups 0x4adc6(%rip), %xmm0    # 0x520f0
movaps %xmm0, -0x150(%rbp)
movups 0x4ada8(%rip), %xmm0    # 0x520e0
movaps %xmm0, -0x160(%rbp)
movups 0x4ad8a(%rip), %xmm0    # 0x520d0
movaps %xmm0, -0x170(%rbp)
leaq -0x170(%rbp), %rax
movq %rax, -0x100(%rbp)
movq $0xe, -0xf8(%rbp)
leaq -0x171(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x8240
movq -0x330(%rbp), %rcx
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x8260
jmp 0x739c
leaq -0x171(%rbp), %rdi
callq 0x82e0
movups 0x4adf1(%rip), %xmm0    # 0x521a0
movaps %xmm0, -0x1b0(%rbp)
movups 0x4add3(%rip), %xmm0    # 0x52190
movaps %xmm0, -0x1c0(%rbp)
movups 0x4adb5(%rip), %xmm0    # 0x52180
movaps %xmm0, -0x1d0(%rbp)
movups 0x4ad97(%rip), %xmm0    # 0x52170
movaps %xmm0, -0x1e0(%rbp)
movups 0x4ad79(%rip), %xmm0    # 0x52160
movaps %xmm0, -0x1f0(%rbp)
movups 0x4ad5b(%rip), %xmm0    # 0x52150
movaps %xmm0, -0x200(%rbp)
movups 0x4ad3d(%rip), %xmm0    # 0x52140
movaps %xmm0, -0x210(%rbp)
leaq -0x210(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq $0xe, -0x198(%rbp)
leaq -0x211(%rbp), %rdi
movq %rdi, -0x338(%rbp)
callq 0x8240
movq -0x338(%rbp), %rcx
movq -0x1a0(%rbp), %rsi
movq -0x198(%rbp), %rdx
leaq -0x190(%rbp), %rdi
callq 0x8260
jmp 0x7459
leaq -0x211(%rbp), %rdi
callq 0x82e0
movups 0x4ada4(%rip), %xmm0    # 0x52210
movaps %xmm0, -0x250(%rbp)
movups 0x4ad86(%rip), %xmm0    # 0x52200
movaps %xmm0, -0x260(%rbp)
movups 0x4ad68(%rip), %xmm0    # 0x521f0
movaps %xmm0, -0x270(%rbp)
movups 0x4ad4a(%rip), %xmm0    # 0x521e0
movaps %xmm0, -0x280(%rbp)
movups 0x4ad2c(%rip), %xmm0    # 0x521d0
movaps %xmm0, -0x290(%rbp)
movups 0x4ad0e(%rip), %xmm0    # 0x521c0
movaps %xmm0, -0x2a0(%rbp)
movups 0x4acf0(%rip), %xmm0    # 0x521b0
movaps %xmm0, -0x2b0(%rbp)
leaq -0x2b0(%rbp), %rax
movq %rax, -0x240(%rbp)
movq $0xe, -0x238(%rbp)
leaq -0x2b1(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x8240
movq -0x340(%rbp), %rcx
movq -0x240(%rbp), %rsi
movq -0x238(%rbp), %rdx
leaq -0x230(%rbp), %rdi
callq 0x8260
jmp 0x7516
leaq -0x2b1(%rbp), %rdi
callq 0x82e0
xorps %xmm0, %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x769c
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x348(%rbp)
leaq -0x2d8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8300
jmp 0x754f
leaq -0x2f0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x8300
jmp 0x7564
movsd -0x348(%rbp), %xmm0
leaq -0x2d8(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0x7b40
movsd %xmm0, -0x350(%rbp)
jmp 0x7589
movsd -0x350(%rbp), %xmm0
movsd %xmm0, -0x2c0(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0x83f0
leaq -0x2d8(%rbp), %rdi
callq 0x83f0
jmp 0x7765
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x82e0
jmp 0x7826
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x171(%rbp), %rdi
callq 0x82e0
jmp 0x780d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x211(%rbp), %rdi
callq 0x82e0
jmp 0x7801
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x2b1(%rbp), %rdi
callq 0x82e0
jmp 0x77f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x77e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x768b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0x83f0
leaq -0x2d8(%rbp), %rdi
callq 0x83f0
jmp 0x77e9
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x358(%rbp)
leaq -0x308(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x8300
jmp 0x76be
leaq -0x320(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x8300
jmp 0x76d3
movsd -0x358(%rbp), %xmm0
leaq -0x308(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0x7b40
movsd %xmm0, -0x360(%rbp)
jmp 0x76f8
movsd -0x360(%rbp), %xmm0
movsd %xmm0, -0x2c0(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x83f0
leaq -0x308(%rbp), %rdi
callq 0x83f0
jmp 0x7765
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x7754
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x83f0
leaq -0x308(%rbp), %rdi
callq 0x83f0
jmp 0x77e9
movsd -0x2c0(%rbp), %xmm0
movsd 0x4a8d3(%rip), %xmm1    # 0x52048
divsd %xmm1, %xmm0
movsd %xmm0, -0x370(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x8450
movsd %xmm0, -0x368(%rbp)
jmp 0x7795
movsd -0x368(%rbp), %xmm1
movsd -0x370(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x4a897(%rip), %xmm1    # 0x52048
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x83f0
leaq -0x190(%rbp), %rdi
callq 0x83f0
leaq -0xf0(%rbp), %rdi
callq 0x83f0
leaq -0x38(%rbp), %rdi
callq 0x83f0
jmp 0x7818
leaq -0x230(%rbp), %rdi
callq 0x83f0
leaq -0x190(%rbp), %rdi
callq 0x83f0
leaq -0xf0(%rbp), %rdi
callq 0x83f0
leaq -0x38(%rbp), %rdi
callq 0x83f0
jmp 0x7826
movsd -0x8(%rbp), %xmm0
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
movq -0xd0(%rbp), %rdi
callq 0x67a0
nopw %cs:(%rax,%rax)