// File: /workspace/github_c_makefile_star2_O0/Openvario[P]sensord/ms5611.c
// Function: ms5611_calculate_pressure
int ms5611_calculate_pressure(t_ms5611 *sensor)
{
	sensor->p_meas = (((sensor->D1 * sensor->sens) >> 21) - sensor->off) >> 11;

	// check for valid range
	if ((sensor->temp > -4000) && (sensor->temp < 8500) && (sensor->p_meas > 16000) && (sensor->p_meas < 1920000))
	{
		// correct measured pressure
		sensor->p = (sensor->linearity * (float)(sensor->p_meas + sensor->offset))*.0625;

		// some debugging output
		ddebug_print("%s @ 0x%x: D1: %u\n", __func__, sensor->address, sensor->D1);
		ddebug_print("%s @ 0x%x: OFF: %" PRId64 "\n", __func__, sensor->address, sensor->off);
		ddebug_print("%s @ 0x%x: SENS: %" PRId64 "\n", __func__, sensor->address, sensor->sens);
		debug_print("%s @ 0x%x: Pressure measured: %ld, %f\n", __func__, sensor->address, (unsigned long)sensor->p_meas, sensor->p);
		return(0);
	}
	else
	{
		// TODO add error handling here !!
		return(1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x10(%rbp), %rcx
imulq 0x48(%rcx), %rax
sarq $0x15, %rax
movq -0x10(%rbp), %rcx
subq 0x40(%rcx), %rax
sarq $0xb, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x10(%rbp), %rax
cmpl $0xfffff060, 0x38(%rax) # imm = 0xFFFFF060
jle 0x3453
movq -0x10(%rbp), %rax
cmpl $0x2134, 0x38(%rax)     # imm = 0x2134
jge 0x3453
movq -0x10(%rbp), %rax
cmpl $0x3e80, 0x50(%rax)     # imm = 0x3E80
jle 0x3453
movq -0x10(%rbp), %rax
cmpl $0x1d4c00, 0x50(%rax)   # imm = 0x1D4C00
jge 0x3453
movq -0x10(%rbp), %rax
movss 0x8c(%rax), %xmm0
movq -0x10(%rbp), %rax
cvtsi2ssl 0x50(%rax), %xmm1
movq -0x10(%rbp), %rax
addss 0x90(%rax), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7ce6(%rip), %xmm1     # 0xb020
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x88(%rax)
leaq 0xc11f(%rip), %rax      # 0xf474
cmpl $0x1, (%rax)
jle 0x3389
movq 0xbc97(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %r8d
leaq 0x7fd8(%rip), %rsi      # 0xb353
leaq 0x7fe4(%rip), %rdx      # 0xb366
movb $0x0, %al
callq 0x21d0
leaq 0xc0e4(%rip), %rax      # 0xf474
cmpl $0x1, (%rax)
jle 0x33c4
movq 0xbc5c(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %r8
leaq 0x7fca(%rip), %rsi      # 0xb380
leaq 0x7fa9(%rip), %rdx      # 0xb366
movb $0x0, %al
callq 0x21d0
leaq 0xc0a9(%rip), %rax      # 0xf474
cmpl $0x1, (%rax)
jle 0x33ff
movq 0xbc21(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %r8
leaq 0x7fa4(%rip), %rsi      # 0xb395
leaq 0x7f6e(%rip), %rdx      # 0xb366
movb $0x0, %al
callq 0x21d0
leaq 0xc06e(%rip), %rax      # 0xf474
cmpl $0x0, (%rax)
jle 0x344a
movq 0xbbe6(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movslq 0x50(%rax), %r8
movq -0x10(%rbp), %rax
movss 0x88(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x7f6f(%rip), %rsi      # 0xb3ab
leaq 0x7f23(%rip), %rdx      # 0xb366
movb $0x1, %al
callq 0x21d0
movl $0x0, -0x4(%rbp)
jmp 0x345a
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)