// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
movl (%rdi), %edi
leaq 0x343e(%rip), %rsi      # 0xa8bd
movl $0x2, %edx
callq 0x20b0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $0x2, %rax
jne 0x758b
xorl %ebp, %ebp
leaq 0xf(%rsp), %r15
leaq 0x10(%rsp), %r12
movl (%r14), %edi
movl $0x1, %edx
movq %r15, %rsi
callq 0x2180
testq %rax, %rax
je 0x758b
testb $0x1, 0xf(%rsp)
je 0x74eb
movups 0x3395(%rip), %xmm0     # 0xa860
movaps %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r12, %rsi
callq 0x2120
testl %eax, %eax
jne 0x74d0
incl %ebp
cmpl $0x64, %ebp
jne 0x74a4
jmp 0x758b
movl (%r14), %edi
leaq 0x33cb(%rip), %rsi      # 0xa8c0
movl $0x1, %edx
callq 0x20b0
cmpq $0x1, %rax
jne 0x758b
xorl %ebp, %ebp
leaq 0xf(%rsp), %r15
leaq 0x10(%rsp), %r12
movl (%r14), %edi
movl $0x1, %edx
movq %r15, %rsi
callq 0x2180
testq %rax, %rax
je 0x758b
testb $0x1, 0xf(%rsp)
je 0x7555
movups 0x3328(%rip), %xmm0     # 0xa860
movaps %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r12, %rsi
callq 0x2120
testl %eax, %eax
jne 0x753d
incl %ebp
cmpl $0x64, %ebp
jne 0x7515
jmp 0x758b
movl (%r14), %edi
leaq 0x3363(%rip), %rsi      # 0xa8c2
movl $0x2, %edx
callq 0x20b0
cmpq $0x2, %rax
jne 0x758b
movl (%r14), %edi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x2180
testq %rax, %rax
je 0x758b
movzbl 0xf(%rsp), %ebx
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq