// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq 0x4a58(%rip), %rsi      # 0xc8f1
movl $0x2, %edx
callq 0x20a0
cmpq $0x2, %rax
je 0x7eb5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movl $0x0, -0x14(%rbp)
cmpl $0x64, -0x14(%rbp)
jge 0x7f30
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x15(%rbp), %rsi
movl $0x1, %edx
callq 0x2180
cmpq $0x0, %rax
jne 0x7ee8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movzbl -0x15(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7f1f
movq 0x4a2d(%rip), %rax      # 0xc928
movq %rax, -0x28(%rbp)
movq 0x4a2a(%rip), %rax      # 0xc930
movq %rax, -0x20(%rbp)
leaq -0x28(%rbp), %rsi
movq %rsi, %rdi
callq 0x2120
cmpl $0x0, %eax
je 0x7f1d
jmp 0x7f0a
jmp 0x7f21
jmp 0x7f30
jmp 0x7f23
jmp 0x7f25
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7ebc
cmpl $0x64, -0x14(%rbp)
jne 0x7f42
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq 0x49a5(%rip), %rsi      # 0xc8f4
movl $0x1, %edx
callq 0x20a0
cmpq $0x1, %rax
je 0x7f6b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movl $0x0, -0x14(%rbp)
cmpl $0x64, -0x14(%rbp)
jge 0x7fe6
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x15(%rbp), %rsi
movl $0x1, %edx
callq 0x2180
cmpq $0x0, %rax
jne 0x7f9e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movzbl -0x15(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7fd5
movq 0x4977(%rip), %rax      # 0xc928
movq %rax, -0x38(%rbp)
movq 0x4974(%rip), %rax      # 0xc930
movq %rax, -0x30(%rbp)
leaq -0x38(%rbp), %rsi
movq %rsi, %rdi
callq 0x2120
cmpl $0x0, %eax
je 0x7fd3
jmp 0x7fc0
jmp 0x7fd7
jmp 0x7fe6
jmp 0x7fd9
jmp 0x7fdb
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7f72
cmpl $0x64, -0x14(%rbp)
jne 0x7ff5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq 0x48f4(%rip), %rsi      # 0xc8f6
movl $0x2, %edx
callq 0x20a0
cmpq $0x2, %rax
je 0x801b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x15(%rbp), %rsi
movl $0x1, %edx
callq 0x2180
cmpq $0x0, %rax
jne 0x803e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8045
movzbl -0x15(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop