// File: /workspace/github_cpp_makefile_star2_O2/mrlordkaj[P]i2cdevlib-pi/MS5803/MS5803.cpp
// Function: MS5803::calcMeasurements(precision)
void MS5803::calcMeasurements(precision _precision){
	// Get raw temperature and pressure values
	_d2_temperature = _getADCconversion(TEMPERATURE, _precision);
	_d1_pressure = _getADCconversion(PRESSURE, _precision);
	//Now that we have a raw temperature, let's compute our actual.
	_dT = _d2_temperature - ((int32_t)_c5_Tref << 8);
	double temp_dT = _dT / (double)pow(2,23);
	_TEMP = 2000 +  (int32_t)(temp_dT * _c6_TEMPSENS);
	if ( _debug ) {
		Serial.println("Raw values:");
		Serial.print("    _d2_temperature = "); Serial.println(_d2_temperature);
		Serial.print("    _d1_pressure = "); Serial.println(_d1_pressure);
		Serial.println("First order values:");
		Serial.print("    _dT = "); Serial.println(_dT);
		Serial.print("    _TEMP = "); Serial.println(_TEMP);
	}
	// Second order variables
	int64_t T2 = 0;
	int64_t off2 = 0;
	int64_t sens2 = 0;
	// Every variant does the calculations differently, so...
	switch (_model) {
		case (BA01):  //MS5803-01-----------------------------------------------------------
			_OFF  = ((int64_t)_c2_OFFt1  << 16 ) + ((((int64_t)_c4_TCO * (int64_t)_dT)) >> 7 );
			_SENS = ((int64_t)_c1_SENSt1 << 15 ) + ((((int64_t)_c3_TCS * (int64_t)_dT)) >> 8 );
			// 2nd Order calculations
			if ( _TEMP < 2000.0) {  // Is temperature below or above 20.00 deg C ?
				T2 = 3 * pow(_dT,2)/(int64_t)pow(2,31);
				off2  = 3 * pow((_TEMP - 2000.0),2);
				sens2 = 7 * pow((_TEMP - 2000.0),2) / 8;
				if ( _TEMP < 1500.0 ) sens2 += 2 * pow((_TEMP + 1500.0),2);// below 15C
			}
			else {
				T2 = 0;
				off2 = 0;
				sens2 = 0;
				if ( _TEMP >= 4500.0 ) {
					sens2 -= ((int64_t)pow((_TEMP - 4500.0),2) >> 3);
				}
			}
			break;
		case (BA02):  //MS5803-02-----------------------------------------------------------
			_OFF  = ((int64_t)_c2_OFFt1  << 17 ) + ((((int64_t)_c4_TCO * (int64_t)_dT)) >> 6 );
			_SENS = ((int64_t)_c1_SENSt1 << 16 ) + ((((int64_t)_c3_TCS * (int64_t)_dT)) >> 7 );
			// 2nd Order calculations
			if ( _TEMP < 2000.0) {  // Is temperature below or above 20.00 deg C ?
				T2 = 3 * pow(_dT,2)/(int64_t)pow(2,31);
				off2 = 61 * pow((_TEMP - 2000.0),2) / 16;
				sens2 = 2 * pow(((int64_t)_TEMP - 2000.0),2);
				if ( _TEMP < 1500.0 ) { // below 15C
					off2  += 20 * pow((_TEMP + 1500.0),2);
					sens2 += 12 * pow((_TEMP + 1500.0),2);
				}
			}
			else {
				T2 = 0;
				off2 = 0;
				sens2 = 0;
			}
			break;
		case (BA05):  //MS5803-05-----------------------------------------------------------
			_OFF  = ((int64_t)_c2_OFFt1  << 18 ) + ((((int64_t)_c4_TCO * (int64_t)_dT)) >> 5 );
			_SENS = ((int64_t)_c1_SENSt1 << 17 ) + ((((int64_t)_c3_TCS * (int64_t)_dT)) >> 7 );
			// 2nd Order calculations
			if ( _TEMP < 2000.0) {  // Is temperature below or above 20.00 deg C ?
				T2 = 3 * pow(_dT,2)/(int64_t)pow(2,33);
				off2 =  3 * pow((_TEMP - 2000.0),2) / 8;
				sens2 = 7 * pow((_TEMP - 2000.0),2) / 8;
				if ( _TEMP < -1500.0 ) { // below -15C
					sens2 += 3 * pow((_TEMP + 1500.0),2);
				}
			}
			else {
				T2 = 0;
				off2 = 0;
				sens2 = 0;
			}
			break;
		case (BA14):  //MS5803-14-----------------------------------------------------------
			// 14 and 30 are the same calculations...
		case (BA30):  //MS5803-30-----------------------------------------------------------
			_OFF  = ((int64_t)_c2_OFFt1  << 16 ) + ((((int64_t)_c4_TCO * (int64_t)_dT)) >> 7 );
			_SENS = ((int64_t)_c1_SENSt1 << 15 ) + ((((int64_t)_c3_TCS * (int64_t)_dT)) >> 8 );
			// 2nd Order calculations
			if ( _TEMP < 2000.0) {  // Is temperature below or above 20.00 deg C ?
				T2 = 3 * pow(_dT,2)/(int64_t)pow(2,33);
				off2 =  3 * pow((_TEMP - 2000.0),2) / 2;
				sens2 = 5 * pow((_TEMP - 2000.0),2) / 8;
				if ( _TEMP < 1500.0 ) { // below 15C
					off2  += 7 * pow((_TEMP + 1500.0),2);
					sens2 += 4 * pow((_TEMP + 1500.0),2);
				}
			}
			else {
				T2 =    7 * ((int64_t)_dT * _dT) >> 37;
				off2 =  1 * (pow((_TEMP - 2000.0),2)) / 16;
				sens2 = 0;
			}
			break;
		default:
			_OFF = 0;
			_SENS = 0;
			T2 = 0;
			sens2 = 0;
			off2 = 0;
	}
	if ( _debug ) {
		Serial.print("    _OFF = "); serialPrintln64(_OFF);
		Serial.print("    _SENS = "); serialPrintln64(_SENS);
	}
	 // Second Order
	_TEMP  -= T2;
	_SENS  -= sens2;
	_OFF   -= off2;
	// Now pressure
	switch (_model) {
		case (BA05):  //MS5803-05-----------------------------------------------------------
			_P = ((((int32_t)_d1_pressure * _SENS) >> 21 ) - _OFF) >> 15;
			_P /= 10; // NO IDEA WHY THIS NEEDS TO BE DONE. PERHAPS AN ERROR IN THE DATASHEET?
			break;
		case (BA01):  //MS5803-01--passthrough----------------------------------------------
		case (BA02):  //MS5803-02--passthrough----------------------------------------------
		case (BA14):  //MS5803-14--passthrough----------------------------------------------
			_P = ((((int32_t)_d1_pressure * _SENS) >> 21 ) - _OFF) >> 15;
			break;
		case (BA30):  //MS5803-30-----------------------------------------------------------
			_P = ((((int32_t)_d1_pressure * _SENS) >> 21 ) - _OFF) >> 13;
			break;
		default:
			_P = 0;
	}
	if ( _debug ) {
		Serial.println("Second order values:");
		Serial.print("    T2 = "); serialPrintln64(T2);
		Serial.print("    sens2 = "); serialPrintln64(sens2);
		Serial.print("    off2 = "); serialPrintln64(off2);
		Serial.print("    _TEMP = "); Serial.println(_TEMP);
		Serial.print("    _SENS = "); serialPrintln64(_SENS);
		Serial.print("    _OFF = "); serialPrintln64(_OFF);
		Serial.println("Pressure:");
		Serial.print("    _P = "); Serial.println(_P);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
pushq $0x10
popq %rsi
movl %ebp, %edx
callq 0x1f850
movl %eax, 0x34(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x1f850
movl %eax, 0x30(%rbx)
movl 0x34(%rbx), %eax
movl 0x28(%rbx), %ecx
shll $0x8, %ecx
subl %ecx, %eax
movl %eax, 0x38(%rbx)
cvtsi2sd %eax, %xmm0
mulsd 0x2f2e(%rip), %xmm0     # 0x341d0
cvtsi2sdl 0x2c(%rbx), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
addl $0x7d0, %eax            # imm = 0x7D0
movl %eax, 0x3c(%rbx)
cmpb $0x1, 0x15(%rbx)
jne 0x31355
movq 0x17cb8(%rip), %r14     # 0x48f80
leaq 0x2fdd(%rip), %rsi      # 0x342ac
movq %r14, %rdi
callq 0x1fa60
movq 0x17cb2(%rip), %r15     # 0x48f90
leaq 0x2fd3(%rip), %rsi      # 0x342b8
movq %r15, %rdi
callq 0x1f7c0
movl 0x34(%rbx), %esi
movq %r14, %rdi
callq 0x1fcd0
leaq 0x2fd0(%rip), %rsi      # 0x342cf
movq %r15, %rdi
callq 0x1f7c0
movl 0x30(%rbx), %esi
movq %r14, %rdi
callq 0x1fcd0
leaq 0x2fca(%rip), %rsi      # 0x342e3
movq %r14, %rdi
callq 0x1fa60
leaq 0x2fcf(%rip), %rsi      # 0x342f7
movq %r15, %rdi
callq 0x1f7c0
movl 0x38(%rbx), %esi
movq %r14, %rdi
callq 0x1fcd0
leaq 0x2fc0(%rip), %rsi      # 0x34302
movq %r15, %rdi
callq 0x1f7c0
movl 0x3c(%rbx), %esi
movq %r14, %rdi
callq 0x1fcd0
movl 0x10(%rbx), %ecx
cmpl $0x1e, %ecx
je 0x31447
cmpl $0x2, %ecx
je 0x3152f
cmpl $0x5, %ecx
je 0x3160f
cmpl $0xe, %ecx
je 0x31447
cmpl $0x1, %ecx
jne 0x31706
movslq 0x1c(%rbx), %rax
shlq $0x10, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rdx
sarq $0x7, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0xf, %rsi
movslq 0x20(%rbx), %rax
imulq %rdi, %rax
sarq $0x8, %rax
addq %rsi, %rax
movq %rax, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x318df
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2e02(%rip), %xmm1     # 0x341e0
mulsd %xmm1, %xmm0
mulsd 0x2e36(%rip), %xmm0     # 0x34220
cvttsd2si %xmm0, %r14
cvtsi2sd %esi, %xmm0
movsd 0x2df5(%rip), %xmm2     # 0x341f0
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r15
mulsd 0x2dfc(%rip), %xmm2     # 0x34210
mulsd 0x2de4(%rip), %xmm2     # 0x34200
cvttsd2si %xmm2, %r12
cmpl $0x5db, %esi            # imm = 0x5DB
jg 0x3171c
addsd 0x2dd3(%rip), %xmm0     # 0x34208
mulsd %xmm0, %xmm0
cvtsi2sd %r12, %xmm1
addsd %xmm0, %xmm0
jmp 0x316d2
movslq 0x1c(%rbx), %rax
shlq $0x10, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rdx
sarq $0x7, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0xf, %rsi
movslq 0x20(%rbx), %rax
imulq %rdi, %rax
sarq $0x8, %rax
addq %rsi, %rax
movq %rax, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x316dd
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2d40(%rip), %xmm1     # 0x341e0
mulsd %xmm1, %xmm0
mulsd 0x2d3c(%rip), %xmm0     # 0x341e8
cvttsd2si %xmm0, %r14
cvtsi2sd %esi, %xmm0
movsd 0x2d33(%rip), %xmm2     # 0x341f0
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm2, %xmm1
mulsd 0x2d27(%rip), %xmm1     # 0x341f8
cvttsd2si %xmm1, %r15
mulsd 0x2be2(%rip), %xmm2     # 0x340c0
mulsd 0x2d1a(%rip), %xmm2     # 0x34200
cvttsd2si %xmm2, %r12
cmpl $0x5db, %esi            # imm = 0x5DB
jg 0x3171c
addsd 0x2d09(%rip), %xmm0     # 0x34208
mulsd %xmm0, %xmm0
cvtsi2sd %r15, %xmm1
movsd 0x2d00(%rip), %xmm2     # 0x34210
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r15
cvtsi2sd %r12, %xmm1
mulsd 0x2cee(%rip), %xmm0     # 0x34218
jmp 0x316d2
movslq 0x1c(%rbx), %rax
shlq $0x11, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rdx
sarq $0x6, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0x10, %rsi
movslq 0x20(%rbx), %rax
imulq %rdi, %rax
sarq $0x7, %rax
addq %rsi, %rax
movq %rax, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x31713
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
mulsd 0x2c58(%rip), %xmm0     # 0x341e0
mulsd 0x2c90(%rip), %xmm0     # 0x34220
cvttsd2si %xmm0, %r14
cvtsi2sd %esi, %xmm0
movsd 0x2c4f(%rip), %xmm1     # 0x341f0
addsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd 0x2c77(%rip), %xmm2     # 0x34228
mulsd %xmm1, %xmm2
mulsd 0x2c1b(%rip), %xmm2     # 0x341d8
cvttsd2si %xmm2, %r15
addsd %xmm1, %xmm1
cvttsd2si %xmm1, %r12
cmpl $0x5db, %esi            # imm = 0x5DB
jg 0x3171c
addsd 0x2c29(%rip), %xmm0     # 0x34208
mulsd %xmm0, %xmm0
cvtsi2sd %r15, %xmm1
movsd 0x2c40(%rip), %xmm2     # 0x34230
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r15
cvtsi2sd %r12, %xmm1
mulsd 0x2c2e(%rip), %xmm0     # 0x34238
jmp 0x316d2
movslq 0x1c(%rbx), %rax
shlq $0x12, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rdx
sarq $0x5, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0x11, %rsi
movslq 0x20(%rbx), %rax
imulq %rdi, %rax
sarq $0x7, %rax
addq %rsi, %rax
movq %rax, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x31713
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2b78(%rip), %xmm1     # 0x341e0
mulsd %xmm1, %xmm0
mulsd 0x2b74(%rip), %xmm0     # 0x341e8
cvttsd2si %xmm0, %r14
cvtsi2sd %esi, %xmm0
addsd 0x2b6b(%rip), %xmm0     # 0x341f0
mulsd %xmm0, %xmm0
mulsd %xmm0, %xmm1
movsd 0x2b6b(%rip), %xmm2     # 0x34200
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r15
mulsd 0x2b6a(%rip), %xmm0     # 0x34210
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r12
cmpl $0xfffffa23, %esi       # imm = 0xFFFFFA23
jg 0x3171c
addl $0x5dc, %esi            # imm = 0x5DC
cvtsi2sd %esi, %xmm0
mulsd %xmm0, %xmm0
cvtsi2sd %r12, %xmm1
mulsd 0x2b0e(%rip), %xmm0     # 0x341e0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12
jmp 0x3171c
imulq %rdi, %rdi
addl $0xfffff830, %esi       # imm = 0xFFFFF830
cvtsi2sd %esi, %xmm0
imulq $0x7, %rdi, %r14
mulsd %xmm0, %xmm0
mulsd 0x2add(%rip), %xmm0     # 0x341d8
shrq $0x25, %r14
cvttsd2si %xmm0, %r15
jmp 0x31719
xorpd %xmm0, %xmm0
movupd %xmm0, 0x40(%rbx)
xorl %edx, %edx
xorl %eax, %eax
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpb $0x1, 0x15(%rbx)
jne 0x31764
movq 0x17867(%rip), %r13     # 0x48f90
leaq 0x2bdf(%rip), %rsi      # 0x3430f
movq %r13, %rdi
callq 0x1f7c0
movq 0x40(%rbx), %rdi
callq 0x1f0e0
leaq 0x2bd3(%rip), %rsi      # 0x3431b
movq %r13, %rdi
callq 0x1f7c0
movq 0x48(%rbx), %rdi
callq 0x1f0e0
movq 0x48(%rbx), %rax
movq 0x40(%rbx), %rdx
movl 0x10(%rbx), %ecx
subl %r14d, 0x3c(%rbx)
subq %r12, %rax
movq %rax, 0x48(%rbx)
subq %r15, %rdx
movq %rdx, 0x40(%rbx)
leal -0x1(%rcx), %esi
cmpl $0x2, %esi
jb 0x317af
cmpl $0x1e, %ecx
je 0x317c4
cmpl $0xe, %ecx
je 0x317af
cmpl $0x5, %ecx
jne 0x318d6
movslq 0x30(%rbx), %rcx
imulq %rcx, %rax
sarq $0x15, %rax
subq %rdx, %rax
shrq $0xf, %rax
pushq $0xa
popq %rcx
cltd
idivl %ecx
movl %eax, 0x50(%rbx)
jmp 0x317da
movslq 0x30(%rbx), %rcx
imulq %rcx, %rax
sarq $0x15, %rax
subq %rdx, %rax
shrq $0xf, %rax
jmp 0x317d7
movslq 0x30(%rbx), %rcx
imulq %rcx, %rax
sarq $0x15, %rax
subq %rdx, %rax
shrq $0xd, %rax
movl %eax, 0x50(%rbx)
cmpb $0x1, 0x15(%rbx)
jne 0x318c7
movq 0x17795(%rip), %r13     # 0x48f80
leaq 0x2b36(%rip), %rsi      # 0x34328
movq %r13, %rdi
callq 0x1fa60
movq 0x1778f(%rip), %rbp     # 0x48f90
leaq 0x2b35(%rip), %rsi      # 0x3433d
movq %rbp, %rdi
callq 0x1f7c0
movq %r14, %rdi
callq 0x1f0e0
leaq 0x2b28(%rip), %rsi      # 0x34347
movq %rbp, %rdi
callq 0x1f7c0
movq %r12, %rdi
callq 0x1f0e0
leaq 0x2b1e(%rip), %rsi      # 0x34354
movq %rbp, %rdi
callq 0x1f7c0
movq %r15, %rdi
callq 0x1f0e0
leaq 0x2ab5(%rip), %rsi      # 0x34302
movq %rbp, %rdi
callq 0x1f7c0
movl 0x3c(%rbx), %esi
movq %r13, %rdi
callq 0x1fcd0
leaq 0x2ab4(%rip), %rsi      # 0x3431b
movq %rbp, %rdi
callq 0x1f7c0
movq 0x48(%rbx), %rdi
callq 0x1f0e0
leaq 0x2a90(%rip), %rsi      # 0x3430f
movq %rbp, %rdi
callq 0x1f7c0
movq 0x40(%rbx), %rdi
callq 0x1f0e0
leaq 0x2ac9(%rip), %rsi      # 0x34360
movq %r13, %rdi
callq 0x1fa60
leaq 0x2ac4(%rip), %rsi      # 0x3436a
movq %rbp, %rdi
callq 0x1f7c0
movl 0x50(%rbx), %esi
movq %r13, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1fcd0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andl $0x0, 0x50(%rbx)
jmp 0x317da
cmpl $0x1194, %esi           # imm = 0x1194
jb 0x31713
addl $0xffffee6c, %esi       # imm = 0xFFFFEE6C
cvtsi2sd %esi, %xmm0
mulsd %xmm0, %xmm0
cvttsd2si %xmm0, %r12
sarq $0x3, %r12
negq %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x3171c