// File: /workspace/github_c_makefile_star2_O0/Openvario[P]sensord/ds2482.c
// Function: OWReadTemperature
int OWReadTemperature(t_ds2482 *sensor) {
	int data[5];
	int i,j;

	sensor->temp_valid=0;
	for(i=0,j=0; i<5; i++) { // we only need 5 of the bytes
		// Technically we only need two, but grabbing 5 lets us double check the configuration
		data[i] = OWReadByte(sensor);
		if (data[i]<0) j=1;
		// server.log(format("read byte: %.2X", data[i]));
	}
	if (j) return 0;
	j=1;
	i = (data[1] << 8) | data[0];
	switch (data[4]&0x60) {
		case 0x60 : // server.log("12 bit resolution"); // 750 ms conversion time
			sensor->temperature=i/16.0;
			if (sensor->databits!=12) j=2;
			break;
		case 0x40 : // server.log("11 bit resolution"); // 375 ms
			sensor->temperature=(i>>1)/8.0;
			if (sensor->databits!=11) j=2;
			break;
		case 0x20 : // server.log("10 bit resolution"); // 187.5 ms
			sensor->temperature=(i>>2)/4.0;
			if (sensor->databits!=10) j=2;
			break;
		default : // server.log("9 bit resolution"); // 93.75 ms
			sensor->temperature=(i>>3)/2.0;
			if (sensor->databits!=9) j=2;
	}
	if ((sensor->temperature<125) && (sensor->temperature>-55)) sensor->temp_valid=1; else j=0;
	// server.log(format("Temperature = %.1f °C", celsius));
	debug_print("%s @ 0x18: temperature %f\n",__func__,sensor->temperature);
	return j;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, 0x2e(%rax)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x5, -0x34(%rbp)
jge 0x86fa
movq -0x10(%rbp), %rdi
callq 0x7e80
movl %eax, %ecx
movslq -0x34(%rbp), %rax
movl %ecx, -0x30(%rbp,%rax,4)
movslq -0x34(%rbp), %rax
cmpl $0x0, -0x30(%rbp,%rax,4)
jge 0x86ed
movl $0x1, -0x38(%rbp)
jmp 0x86ef
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x86c2
cmpl $0x0, -0x38(%rbp)
je 0x870c
movl $0x0, -0x4(%rbp)
jmp 0x8899
movl $0x1, -0x38(%rbp)
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %eax
shll $0x8, %eax
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x20(%rbp), %eax
andl $0x60, %eax
movl %eax, -0x3c(%rbp)
subl $0x20, %eax
je 0x87b6
jmp 0x8735
movl -0x3c(%rbp), %eax
subl $0x40, %eax
je 0x8781
jmp 0x873f
movl -0x3c(%rbp), %eax
subl $0x60, %eax
jne 0x87ec
jmp 0x874d
cvtsi2sdl -0x34(%rbp), %xmm0
movsd 0x4176(%rip), %xmm1     # 0xc8d0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movq -0x10(%rbp), %rax
cmpl $0xc, 0x3c(%rax)
je 0x877c
movl $0x2, -0x38(%rbp)
jmp 0x8822
movl -0x34(%rbp), %eax
sarl %eax
cvtsi2sd %eax, %xmm0
movsd 0x4136(%rip), %xmm1     # 0xc8c8
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movq -0x10(%rbp), %rax
cmpl $0xb, 0x3c(%rax)
je 0x87b4
movl $0x2, -0x38(%rbp)
jmp 0x8822
movl -0x34(%rbp), %eax
sarl $0x2, %eax
cvtsi2sd %eax, %xmm0
movsd 0x40f8(%rip), %xmm1     # 0xc8c0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movq -0x10(%rbp), %rax
cmpl $0xa, 0x3c(%rax)
je 0x87ea
movl $0x2, -0x38(%rbp)
jmp 0x8822
movl -0x34(%rbp), %eax
sarl $0x3, %eax
cvtsi2sd %eax, %xmm0
movsd 0x380a(%rip), %xmm1     # 0xc008
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x24(%rax)
movq -0x10(%rbp), %rax
cmpl $0x9, 0x3c(%rax)
je 0x8820
movl $0x2, -0x38(%rbp)
jmp 0x8822
movq -0x10(%rbp), %rax
movss 0x37be(%rip), %xmm0     # 0xbfec
ucomiss 0x24(%rax), %xmm0
jbe 0x8854
movq -0x10(%rbp), %rax
movss 0x24(%rax), %xmm0
movss 0x37a3(%rip), %xmm1     # 0xbfe8
ucomiss %xmm1, %xmm0
jbe 0x8854
movq -0x10(%rbp), %rax
movb $0x1, 0x2e(%rax)
jmp 0x885b
movl $0x0, -0x38(%rbp)
leaq 0x6c12(%rip), %rax      # 0xf474
cmpl $0x0, (%rax)
jle 0x8893
movq 0x678a(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movss 0x24(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x4076(%rip), %rsi      # 0xc8fb
leaq 0x408a(%rip), %rdx      # 0xc916
movb $0x1, %al
callq 0x21d0
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)