// File: /workspace/github_c_makefile_star2_O2/Openvario[P]sensord/ds2482.c
// Function: OWReadByte
int OWReadByte(t_ds2482 *sensor) {
	int i;
	unsigned char data;

	// See if the 1wire bus is idle
	// server.log("Function: Read Byte from One-Wire");
	if (write(sensor->fd,"\xe1\xf0",2)!=2) { // Device failed to acknowledge
		// server.log("I2C Write Failed");
		return -1;
	}
	for (i=0;i<100;++i) {
		if (read(sensor->fd,&data,1)==0) { // Read the status register
			// server.log("I2C Read Status Failed");
			return -1;
		} else {
			// server.log(format("Read Status Byte = %d", data));
			if (data & 0x01) { // 1-Wire Busy bit
				// server.log("One-Wire bus is busy");
				struct timespec nstime = {0,1e6};
				while (nanosleep(&nstime,&nstime)) ; // Wait, try again
			} else {
				// server.log("One-Wire bus is idle");
				break;
			}
		}
	}
	if (i == 100) {
		// server.log("One-Wire busy for too long");
		return -1;
	}
	// Send a read command, then wait for the 1wire bus to finish
	if (write(sensor->fd,"\x96",1)!=1) { // Device failed to acknowledge
		// server.log("I2C Write Read-Request Failed");
		return -1;
	}
	for (i=0;i<100;++i) {
		if (read(sensor->fd,&data,1)==0) { // Read the status register
			// server.log("I2C Read Status Failed");
			return -1;
		} else {
			// server.log(format("Read Status Byte = %d", data));
			if (data & 1) { // 1-Wire Busy bit
				// server.log("One-Wire bus is busy");
				struct timespec nstime = {0,1e6};
				while (nanosleep(&nstime,&nstime)) ; // Wait, try again
			} else {
				// server.log("One-Wire bus is idle");
				break;
			}
		}
	}
	if (i == 100) {
		// server.log("One-Wire busy for too long");
		return -1;
	}

	// Go get the data byte
	if (write(sensor->fd,"\xe1\xe1",2)!=2) { // Device failed to acknowledge
		// server.log("I2C Write Failed");
		return -1;
	}
	if (read(sensor->fd,&data,1)==0) { // Read the status register
		// server.log("I2C Read Status Failed");
		return -1;
	}
	return data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
movl (%rdi), %edi
leaq 0x31b8(%rip), %rsi      # 0x98bd
pushq $0x2
popq %rdx
callq 0x20b0
pushq $-0x1
popq %rbx
cmpq $0x2, %rax
jne 0x680c
xorl %ebp, %ebp
leaq 0xf(%rsp), %r15
pushq $0x1
popq %r12
leaq 0x10(%rsp), %r13
cmpl $0x64, %ebp
je 0x680c
movl (%r14), %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2180
testq %rax, %rax
je 0x680c
testb $0x1, 0xf(%rsp)
je 0x6770
movups 0x3108(%rip), %xmm0     # 0x9860
movaps %xmm0, 0x10(%rsp)
movq %r13, %rdi
movq %r13, %rsi
callq 0x2120
testl %eax, %eax
jne 0x675d
incl %ebp
jmp 0x672a
movl (%r14), %edi
leaq 0x3146(%rip), %rsi      # 0x98c0
pushq $0x1
popq %rdx
callq 0x20b0
cmpq $0x1, %rax
jne 0x680c
xorl %ebp, %ebp
leaq 0xf(%rsp), %r15
pushq $0x1
popq %r12
leaq 0x10(%rsp), %r13
cmpl $0x64, %ebp
je 0x680c
movl (%r14), %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2180
testq %rax, %rax
je 0x680c
testb $0x1, 0xf(%rsp)
je 0x67da
movups 0x309e(%rip), %xmm0     # 0x9860
movaps %xmm0, 0x10(%rsp)
movq %r13, %rdi
movq %r13, %rsi
callq 0x2120
testl %eax, %eax
jne 0x67c7
incl %ebp
jmp 0x679c
movl (%r14), %edi
leaq 0x30de(%rip), %rsi      # 0x98c2
pushq $0x2
popq %rdx
callq 0x20b0
cmpq $0x2, %rax
jne 0x680c
movl (%r14), %edi
leaq 0xf(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2180
testq %rax, %rax
je 0x680c
movzbl 0xf(%rsp), %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq