// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0x10, %esi
movl %ebp, %edx
callq 0x1f610
movl %eax, 0x34(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x1f610
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 0x2d7e(%rip), %xmm0     # 0x361e8
cvtsi2sdl 0x2c(%rbx), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
addl $0x7d0, %eax            # imm = 0x7D0
movl %eax, 0x3c(%rbx)
cmpb $0x1, 0x15(%rbx)
jne 0x33531
movq 0x13af0(%rip), %r14     # 0x46f80
leaq 0x2e2d(%rip), %rsi      # 0x362c4
movq %r14, %rdi
callq 0x1f770
movq 0x13aea(%rip), %r15     # 0x46f90
leaq 0x2e23(%rip), %rsi      # 0x362d0
movl $0x16, %edx
movq %r15, %rdi
callq 0x1f680
movl 0x34(%rbx), %esi
movq %r14, %rdi
callq 0x1f8e0
leaq 0x2e1b(%rip), %rsi      # 0x362e7
movl $0x13, %edx
movq %r15, %rdi
callq 0x1f680
movl 0x30(%rbx), %esi
movq %r14, %rdi
callq 0x1f8e0
leaq 0x2e10(%rip), %rsi      # 0x362fb
movq %r14, %rdi
callq 0x1f770
leaq 0x2e15(%rip), %rsi      # 0x3630f
movl $0xa, %edx
movq %r15, %rdi
callq 0x1f680
movl 0x38(%rbx), %esi
movq %r14, %rdi
callq 0x1f8e0
leaq 0x2e01(%rip), %rsi      # 0x3631a
movl $0xc, %edx
movq %r15, %rdi
callq 0x1f680
movl 0x3c(%rbx), %esi
movq %r14, %rdi
callq 0x1f8e0
movl 0x10(%rbx), %eax
cmpl $0x4, %eax
jle 0x33648
cmpl $0x5, %eax
je 0x33746
cmpl $0xe, %eax
je 0x33554
cmpl $0x1e, %eax
jne 0x33921
movslq 0x1c(%rbx), %rdx
shlq $0x10, %rdx
movslq 0x24(%rbx), %rcx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rcx
sarq $0x7, %rcx
addq %rdx, %rcx
movq %rcx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0xf, %rsi
movslq 0x20(%rbx), %rdx
imulq %rdi, %rdx
sarq $0x8, %rdx
addq %rsi, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x3381e
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2c48(%rip), %xmm1     # 0x361f8
mulsd %xmm1, %xmm0
mulsd 0x2c44(%rip), %xmm0     # 0x36200
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movsd 0x2c38(%rip), %xmm2     # 0x36208
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm2, %xmm1
mulsd 0x2c2c(%rip), %xmm1     # 0x36210
cvttsd2si %xmm1, %r15
mulsd 0x2acf(%rip), %xmm2     # 0x360c0
mulsd 0x2c1f(%rip), %xmm2     # 0x36218
cvttsd2si %xmm2, %r12
cmpl $0x5db, %esi            # imm = 0x5DB
jg 0x33966
addsd 0x2c0e(%rip), %xmm0     # 0x36220
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movsd 0x2c02(%rip), %xmm2     # 0x36228
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r15
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
mulsd 0x2bed(%rip), %xmm0     # 0x36230
jmp 0x33916
cmpl $0x1, %eax
je 0x33854
cmpl $0x2, %eax
jne 0x33921
movslq 0x1c(%rbx), %rdx
shlq $0x11, %rdx
movslq 0x24(%rbx), %rcx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rcx
sarq $0x6, %rcx
addq %rdx, %rcx
movq %rcx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0x10, %rsi
movslq 0x20(%rbx), %rdx
imulq %rdi, %rdx
sarq $0x7, %rdx
addq %rsi, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x3395d
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
mulsd 0x2b42(%rip), %xmm0     # 0x361f8
mulsd 0x2b7a(%rip), %xmm0     # 0x36238
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movsd 0x2b36(%rip), %xmm1     # 0x36208
addsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd 0x2b5e(%rip), %xmm2     # 0x36240
mulsd %xmm1, %xmm2
mulsd 0x2b02(%rip), %xmm2     # 0x361f0
cvttsd2si %xmm2, %r15
addsd %xmm1, %xmm1
cvttsd2si %xmm1, %r12
cmpl $0x5db, %esi            # imm = 0x5DB
jg 0x33966
addsd 0x2b10(%rip), %xmm0     # 0x36220
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movsd 0x2b24(%rip), %xmm2     # 0x36248
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r15
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
mulsd 0x2b0f(%rip), %xmm0     # 0x36250
jmp 0x33916
movslq 0x1c(%rbx), %rdx
shlq $0x12, %rdx
movslq 0x24(%rbx), %rcx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rcx
sarq $0x5, %rcx
addq %rdx, %rcx
movq %rcx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0x11, %rsi
movslq 0x20(%rbx), %rdx
imulq %rdi, %rdx
sarq $0x7, %rdx
addq %rsi, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x3395d
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2a56(%rip), %xmm1     # 0x361f8
mulsd %xmm1, %xmm0
mulsd 0x2a52(%rip), %xmm0     # 0x36200
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
addsd 0x2a46(%rip), %xmm0     # 0x36208
mulsd %xmm0, %xmm0
mulsd %xmm0, %xmm1
movsd 0x2a46(%rip), %xmm2     # 0x36218
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r15
mulsd 0x2a45(%rip), %xmm0     # 0x36228
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r12
cmpl $0xfffffa23, %esi       # imm = 0xFFFFFA23
jg 0x33966
addl $0x5dc, %esi            # imm = 0x5DC
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
mulsd 0x29df(%rip), %xmm0     # 0x361f8
jmp 0x33916
imulq %rdi, %rdi
leaq (,%rdi,8), %r14
addl $0xfffff830, %esi       # imm = 0xFFFFF830
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
subq %rdi, %r14
mulsd %xmm0, %xmm0
mulsd 0x29aa(%rip), %xmm0     # 0x361f0
shrq $0x25, %r14
cvttsd2si %xmm0, %r15
jmp 0x33963
movslq 0x1c(%rbx), %rdx
shlq $0x10, %rdx
movslq 0x24(%rbx), %rcx
movslq 0x38(%rbx), %rdi
imulq %rdi, %rcx
sarq $0x7, %rcx
addq %rdx, %rcx
movq %rcx, 0x40(%rbx)
movslq 0x18(%rbx), %rsi
shlq $0xf, %rsi
movslq 0x20(%rbx), %rdx
imulq %rdi, %rdx
sarq $0x8, %rdx
addq %rsi, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %esi
cmpl $0x7cf, %esi            # imm = 0x7CF
jg 0x33930
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2948(%rip), %xmm1     # 0x361f8
mulsd %xmm1, %xmm0
mulsd 0x297c(%rip), %xmm0     # 0x36238
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movsd 0x2938(%rip), %xmm2     # 0x36208
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r15
mulsd 0x293f(%rip), %xmm2     # 0x36228
mulsd 0x2927(%rip), %xmm2     # 0x36218
cvttsd2si %xmm2, %r12
cmpl $0x5db, %esi            # imm = 0x5DB
jg 0x33966
addsd 0x291a(%rip), %xmm0     # 0x36220
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12
jmp 0x33966
xorpd %xmm0, %xmm0
movupd %xmm0, 0x40(%rbx)
xorl %ecx, %ecx
xorl %edx, %edx
jmp 0x3395d
cmpl $0x1194, %esi           # imm = 0x1194
jb 0x3395d
addl $0xffffee6c, %esi       # imm = 0xFFFFEE6C
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulsd %xmm0, %xmm0
cvttsd2si %xmm0, %r12
sarq $0x3, %r12
negq %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x33966
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpb $0x1, 0x15(%rbx)
jne 0x339b8
movq 0x1361d(%rip), %r13     # 0x46f90
leaq 0x29ad(%rip), %rsi      # 0x36327
movl $0xb, %edx
movq %r13, %rdi
callq 0x1f680
movq 0x40(%rbx), %rdi
callq 0x1f0b0
leaq 0x299c(%rip), %rsi      # 0x36333
movl $0xc, %edx
movq %r13, %rdi
callq 0x1f680
movq 0x48(%rbx), %rdi
callq 0x1f0b0
movq 0x48(%rbx), %rdx
movq 0x40(%rbx), %rcx
movl 0x10(%rbx), %eax
subl %r14d, 0x3c(%rbx)
subq %r12, %rdx
movq %rdx, 0x48(%rbx)
subq %r15, %rcx
movq %rcx, 0x40(%rbx)
cmpl $0xd, %eax
jg 0x33a0f
leal -0x1(%rax), %esi
cmpl $0x2, %esi
jb 0x33a32
cmpl $0x5, %eax
jne 0x33b67
movslq 0x30(%rbx), %rax
imulq %rax, %rdx
sarq $0x15, %rdx
subq %rcx, %rdx
shrq $0xf, %rdx
movslq %edx, %rax
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rax
addl %ecx, %eax
movl %eax, 0x50(%rbx)
jmp 0x33a48
cmpl $0xe, %eax
je 0x33a32
cmpl $0x1e, %eax
jne 0x33b67
movslq 0x30(%rbx), %rax
imulq %rax, %rdx
sarq $0x15, %rdx
subq %rcx, %rdx
shrq $0xd, %rdx
jmp 0x33a45
movslq 0x30(%rbx), %rax
imulq %rax, %rdx
sarq $0x15, %rdx
subq %rcx, %rdx
shrq $0xf, %rdx
movl %edx, 0x50(%rbx)
cmpb $0x1, 0x15(%rbx)
jne 0x33b58
movq 0x13527(%rip), %r13     # 0x46f80
leaq 0x28e0(%rip), %rsi      # 0x36340
movq %r13, %rdi
callq 0x1f770
movq 0x13521(%rip), %rbp     # 0x46f90
leaq 0x28df(%rip), %rsi      # 0x36355
movl $0x9, %edx
movq %rbp, %rdi
callq 0x1f680
movq %r14, %rdi
callq 0x1f0b0
leaq 0x28cd(%rip), %rsi      # 0x3635f
movl $0xc, %edx
movq %rbp, %rdi
callq 0x1f680
movq %r12, %rdi
callq 0x1f0b0
leaq 0x28be(%rip), %rsi      # 0x3636c
movl $0xb, %edx
movq %rbp, %rdi
callq 0x1f680
movq %r15, %rdi
callq 0x1f0b0
leaq 0x2850(%rip), %rsi      # 0x3631a
movl $0xc, %edx
movq %rbp, %rdi
callq 0x1f680
movl 0x3c(%rbx), %esi
movq %r13, %rdi
callq 0x1f8e0
leaq 0x284a(%rip), %rsi      # 0x36333
movl $0xc, %edx
movq %rbp, %rdi
callq 0x1f680
movq 0x48(%rbx), %rdi
callq 0x1f0b0
leaq 0x2821(%rip), %rsi      # 0x36327
movl $0xb, %edx
movq %rbp, %rdi
callq 0x1f680
movq 0x40(%rbx), %rdi
callq 0x1f0b0
leaq 0x2855(%rip), %rsi      # 0x36378
movq %r13, %rdi
callq 0x1f770
leaq 0x2850(%rip), %rsi      # 0x36382
movl $0x9, %edx
movq %rbp, %rdi
callq 0x1f680
movl 0x50(%rbx), %esi
movq %r13, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1f8e0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x50(%rbx)
jmp 0x33a48
nop