// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ca4(%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 0x3360b
movq 0x13a16(%rip), %r14     # 0x46f80
leaq 0x2d53(%rip), %rsi      # 0x362c4
movq %r14, %rdi
callq 0x1f770
movq 0x13a10(%rip), %r15     # 0x46f90
leaq 0x2d49(%rip), %rsi      # 0x362d0
movl $0x16, %edx
movq %r15, %rdi
callq 0x1f680
movl 0x34(%rbx), %esi
movq %r14, %rdi
callq 0x1f8e0
leaq 0x2d41(%rip), %rsi      # 0x362e7
movl $0x13, %edx
movq %r15, %rdi
callq 0x1f680
movl 0x30(%rbx), %esi
movq %r14, %rdi
callq 0x1f8e0
leaq 0x2d36(%rip), %rsi      # 0x362fb
movq %r14, %rdi
callq 0x1f770
leaq 0x2d3b(%rip), %rsi      # 0x3630f
movl $0xa, %edx
movq %r15, %rdi
callq 0x1f680
movl 0x38(%rbx), %esi
movq %r14, %rdi
callq 0x1f8e0
leaq 0x2d27(%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 0x33720
cmpl $0x5, %eax
je 0x3381c
cmpl $0xe, %eax
je 0x3362e
cmpl $0x1e, %eax
jne 0x339f1
movslq 0x1c(%rbx), %rax
shlq $0x10, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rcx
imulq %rcx, %rdx
sarq $0x7, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rax
shlq $0xf, %rax
movslq 0x20(%rbx), %rdx
imulq %rcx, %rdx
sarq $0x8, %rdx
addq %rax, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %eax
cmpl $0x7cf, %eax            # imm = 0x7CF
jg 0x338f1
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2b6f(%rip), %xmm1     # 0x361f8
mulsd %xmm1, %xmm0
mulsd 0x2b6b(%rip), %xmm0     # 0x36200
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x2b5f(%rip), %xmm2     # 0x36208
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm2, %xmm1
mulsd 0x2b53(%rip), %xmm1     # 0x36210
cvttsd2si %xmm1, %r15
mulsd 0x29f6(%rip), %xmm2     # 0x360c0
mulsd 0x2b46(%rip), %xmm2     # 0x36218
cvttsd2si %xmm2, %r12
cmpl $0x5db, %eax            # imm = 0x5DB
jg 0x33a30
addsd 0x2b36(%rip), %xmm0     # 0x36220
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movsd 0x2b2a(%rip), %xmm2     # 0x36228
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r15
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
mulsd 0x2b15(%rip), %xmm0     # 0x36230
jmp 0x339e6
cmpl $0x1, %eax
je 0x33926
cmpl $0x2, %eax
jne 0x339f1
movslq 0x1c(%rbx), %rax
shlq $0x11, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rcx
imulq %rcx, %rdx
sarq $0x6, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rax
shlq $0x10, %rax
movslq 0x20(%rbx), %rdx
imulq %rcx, %rdx
sarq $0x7, %rdx
addq %rax, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %eax
cmpl $0x7cf, %eax            # imm = 0x7CF
jg 0x33a27
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm0, %xmm0
mulsd 0x2a6b(%rip), %xmm0     # 0x361f8
mulsd 0x2aa3(%rip), %xmm0     # 0x36238
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x2a5f(%rip), %xmm1     # 0x36208
addsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd 0x2a87(%rip), %xmm2     # 0x36240
mulsd %xmm1, %xmm2
mulsd 0x2a2b(%rip), %xmm2     # 0x361f0
cvttsd2si %xmm2, %r15
addsd %xmm1, %xmm1
cvttsd2si %xmm1, %r12
cmpl $0x5db, %eax            # imm = 0x5DB
jg 0x33a30
addsd 0x2a3a(%rip), %xmm0     # 0x36220
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movsd 0x2a4e(%rip), %xmm2     # 0x36248
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %r15
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
mulsd 0x2a39(%rip), %xmm0     # 0x36250
jmp 0x339e6
movslq 0x1c(%rbx), %rax
shlq $0x12, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rcx
imulq %rcx, %rdx
sarq $0x5, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rax
shlq $0x11, %rax
movslq 0x20(%rbx), %rdx
imulq %rcx, %rdx
sarq $0x7, %rdx
addq %rax, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %eax
cmpl $0x7cf, %eax            # imm = 0x7CF
jg 0x33a27
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2981(%rip), %xmm1     # 0x361f8
mulsd %xmm1, %xmm0
mulsd 0x297d(%rip), %xmm0     # 0x36200
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
addsd 0x2971(%rip), %xmm0     # 0x36208
mulsd %xmm0, %xmm0
mulsd %xmm0, %xmm1
movsd 0x2971(%rip), %xmm2     # 0x36218
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r15
mulsd 0x2970(%rip), %xmm0     # 0x36228
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r12
cmpl $0xfffffa23, %eax       # imm = 0xFFFFFA23
jg 0x33a30
addl $0x5dc, %eax            # imm = 0x5DC
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
mulsd 0x290c(%rip), %xmm0     # 0x361f8
jmp 0x339e6
imulq %rcx, %rcx
leaq (,%rcx,8), %r14
addl $0xfffff830, %eax       # imm = 0xFFFFF830
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subq %rcx, %r14
mulsd %xmm0, %xmm0
mulsd 0x28d8(%rip), %xmm0     # 0x361f0
shrq $0x25, %r14
cvttsd2si %xmm0, %r15
jmp 0x33a2d
movslq 0x1c(%rbx), %rax
shlq $0x10, %rax
movslq 0x24(%rbx), %rdx
movslq 0x38(%rbx), %rcx
imulq %rcx, %rdx
sarq $0x7, %rdx
addq %rax, %rdx
movq %rdx, 0x40(%rbx)
movslq 0x18(%rbx), %rax
shlq $0xf, %rax
movslq 0x20(%rbx), %rdx
imulq %rcx, %rdx
sarq $0x8, %rdx
addq %rax, %rdx
movq %rdx, 0x48(%rbx)
movl 0x3c(%rbx), %eax
cmpl $0x7cf, %eax            # imm = 0x7CF
jg 0x339fc
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm0, %xmm0
movsd 0x2877(%rip), %xmm1     # 0x361f8
mulsd %xmm1, %xmm0
mulsd 0x28ab(%rip), %xmm0     # 0x36238
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x2867(%rip), %xmm2     # 0x36208
addsd %xmm0, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %r15
mulsd 0x286e(%rip), %xmm2     # 0x36228
mulsd 0x2856(%rip), %xmm2     # 0x36218
cvttsd2si %xmm2, %r12
cmpl $0x5db, %eax            # imm = 0x5DB
jg 0x33a30
addsd 0x284a(%rip), %xmm0     # 0x36220
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r12
jmp 0x33a30
xorpd %xmm0, %xmm0
movupd %xmm0, 0x40(%rbx)
jmp 0x33a27
cmpl $0x1194, %eax           # imm = 0x1194
jl 0x33a27
addl $0xffffee6c, %eax       # imm = 0xFFFFEE6C
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm0, %xmm0
cvttsd2si %xmm0, %r12
sarq $0x3, %r12
negq %r12
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x33a30
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpb $0x1, 0x15(%rbx)
jne 0x33a77
movq 0x13553(%rip), %r13     # 0x46f90
leaq 0x28e3(%rip), %rsi      # 0x36327
movl $0xb, %edx
movq %r13, %rdi
callq 0x1f680
movq 0x40(%rbx), %rdi
callq 0x1f0b0
leaq 0x28d2(%rip), %rsi      # 0x36333
movl $0xc, %edx
movq %r13, %rdi
callq 0x1f680
movq 0x48(%rbx), %rdi
callq 0x1f0b0
subl %r14d, 0x3c(%rbx)
movq 0x48(%rbx), %rax
subq %r12, %rax
movq %rax, 0x48(%rbx)
movq 0x40(%rbx), %rcx
subq %r15, %rcx
movq %rcx, 0x40(%rbx)
movl 0x10(%rbx), %edx
cmpl $0xd, %edx
jg 0x33ad5
leal -0x1(%rdx), %esi
cmpl $0x2, %esi
jb 0x33af8
cmpl $0x5, %edx
jne 0x33c2d
movslq 0x30(%rbx), %rdx
imulq %rdx, %rax
sarq $0x15, %rax
subq %rcx, %rax
shrq $0xf, %rax
cltq
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rax
addl %ecx, %eax
jmp 0x33b0b
cmpl $0xe, %edx
je 0x33af8
cmpl $0x1e, %edx
jne 0x33c2d
movslq 0x30(%rbx), %rdx
imulq %rdx, %rax
sarq $0x15, %rax
subq %rcx, %rax
shrq $0xd, %rax
jmp 0x33b0b
movslq 0x30(%rbx), %rdx
imulq %rdx, %rax
sarq $0x15, %rax
subq %rcx, %rax
shrq $0xf, %rax
movl %eax, 0x50(%rbx)
cmpb $0x1, 0x15(%rbx)
jne 0x33c1e
movq 0x13461(%rip), %r13     # 0x46f80
leaq 0x281a(%rip), %rsi      # 0x36340
movq %r13, %rdi
callq 0x1f770
movq 0x1345b(%rip), %rbp     # 0x46f90
leaq 0x2819(%rip), %rsi      # 0x36355
movl $0x9, %edx
movq %rbp, %rdi
callq 0x1f680
movq %r14, %rdi
callq 0x1f0b0
leaq 0x2807(%rip), %rsi      # 0x3635f
movl $0xc, %edx
movq %rbp, %rdi
callq 0x1f680
movq %r12, %rdi
callq 0x1f0b0
leaq 0x27f8(%rip), %rsi      # 0x3636c
movl $0xb, %edx
movq %rbp, %rdi
callq 0x1f680
movq %r15, %rdi
callq 0x1f0b0
leaq 0x278a(%rip), %rsi      # 0x3631a
movl $0xc, %edx
movq %rbp, %rdi
callq 0x1f680
movl 0x3c(%rbx), %esi
movq %r13, %rdi
callq 0x1f8e0
leaq 0x2784(%rip), %rsi      # 0x36333
movl $0xc, %edx
movq %rbp, %rdi
callq 0x1f680
movq 0x48(%rbx), %rdi
callq 0x1f0b0
leaq 0x275b(%rip), %rsi      # 0x36327
movl $0xb, %edx
movq %rbp, %rdi
callq 0x1f680
movq 0x40(%rbx), %rdi
callq 0x1f0b0
leaq 0x278f(%rip), %rsi      # 0x36378
movq %r13, %rdi
callq 0x1f770
leaq 0x278a(%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 0x33b0e
nop