// File: /workspace/github_c_makefile_star2_O1/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 0x326d(%rip), %rsi      # 0xa83d
movl $0x2, %edx
callq 0x20b0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq $0x2, %rax
jne 0x76ed
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 0x76ed
testb $0x1, 0xf(%rsp)
je 0x763c
movups 0x31c4(%rip), %xmm0     # 0xa7e0
movaps %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r12, %rsi
callq 0x2120
testl %eax, %eax
jne 0x7621
incl %ebp
cmpl $0x64, %ebp
jne 0x75f5
movl $0x64, %ebp
cmpl $0x64, %ebp
je 0x76ed
movl (%r14), %edi
leaq 0x31f1(%rip), %rsi      # 0xa840
movl $0x1, %edx
callq 0x20b0
cmpq $0x1, %rax
jne 0x76ed
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 0x76ed
testb $0x1, 0xf(%rsp)
je 0x76b2
movups 0x314e(%rip), %xmm0     # 0xa7e0
movaps %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r12, %rsi
callq 0x2120
testl %eax, %eax
jne 0x7697
incl %ebp
cmpl $0x64, %ebp
jne 0x766f
movl $0x64, %ebp
cmpl $0x64, %ebp
je 0x76ed
movl (%r14), %edi
leaq 0x3181(%rip), %rsi      # 0xa842
movl $0x2, %edx
callq 0x20b0
cmpq $0x2, %rax
jne 0x76ed
movl (%r14), %edi
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
callq 0x2180
testq %rax, %rax
je 0x76ed
movzbl 0xf(%rsp), %ebx
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq