#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int i2c_smbus_read_byte_data(int, int);
int /*<<< orphan*/ usleep(int);
int lps331_read_reg(int fd, int addr) {
  int i, byte;
  for (i = 0; i < 10; i++) {
    byte = i2c_smbus_read_byte_data(fd, addr);
    if (byte >= 0 || i == 10 - 1)
      break;
    usleep(10 * 1000);
  }
  return byte;
}


x86 assembly (clang, -O0):
<lps331_read_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    117e <lps331_read_reg+0x5e>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <i2c_smbus_read_byte_data@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1161 <lps331_read_reg+0x41>
cmpl   $0x9,-0xc(%rbp)
jne    1166 <lps331_read_reg+0x46>
jmp    117e <lps331_read_reg+0x5e>
mov    $0x2710,%edi
call   1040 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <lps331_read_reg+0x15>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lps331_read_reg>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
call   1030 <i2c_smbus_read_byte_data@plt>
test   %eax,%eax
jns    1162 <lps331_read_reg+0x42>
mov    $0x8,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x2710,%edi
call   1040 <usleep@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <i2c_smbus_read_byte_data@plt>
sub    $0x1,%ebx
setb   %cl
test   %eax,%eax
jns    1162 <lps331_read_reg+0x42>
test   %cl,%cl
je     1140 <lps331_read_reg+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lps331_read_reg(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %22, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = call i32 @i2c_smbus_read_byte_data(i32 %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp sge i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 9
br i1 %18, label %19, label %20
19: ; preds = %16, %10
br label %25
20: ; preds = %16
%21 = call i32 @usleep(i32 10000)
br label %22
22: ; preds = %20
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %7
25: ; preds = %19, %7
%26 = load i32, i32* %6
ret i32 %26
}

LLVM IR (-O2):
define i32 @lps331_read_reg(i32 %0, i32 %1) {
%3 = tail call i32 @i2c_smbus_read_byte_data(i32 %0, i32 %1)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %13, label %5
5: ; preds = %2, %5
%6 = phi i32 [ %8, %5 ], [ 0, %2 ]
%7 = tail call i32 @usleep(i32 10000)
%8 = add nuw nsw i32 %6, 1
%9 = tail call i32 @i2c_smbus_read_byte_data(i32 %0, i32 %1)
%10 = icmp sgt i32 %9, -1
%11 = icmp eq i32 %8, 9
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %13, label %5
13: ; preds = %5, %2
%14 = phi i32 [ %3, %2 ], [ %9, %5 ]
ret i32 %14
}