#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 */
unsigned short inw(int);
int /*<<< orphan*/ outw(unsigned short, int);
int /*<<< orphan*/ smbus_delay();
int smbus_wait_until_ready(void) {
  unsigned long loops;
  loops = (100 * 1000 * 10);
  do {
    unsigned short val;
    smbus_delay();
    val = inw(0x0f00 + 0xe0);
    if ((val & 0x800) == 0) {
      break;
    }
    if (loops == ((100 * 1000 * 10) / 2)) {
      outw(inw(0x0f00 + 0xe0), 0x0f00 + 0xe0);
    }
  } while (--loops);
  return loops ? 0 : -2;
}


x86 assembly (clang, -O0):
<smbus_wait_until_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0xf4240,-0x8(%rbp)
mov    $0x0,%al
call   1050 <smbus_delay@plt>
mov    $0xfe0,%edi
call   1030 <inw@plt>
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
and    $0x800,%eax
cmp    $0x0,%eax
jne    116c <smbus_wait_until_ready+0x3c>
jmp    11ac <smbus_wait_until_ready+0x7c>
cmpq   $0x7a120,-0x8(%rbp)
jne    1191 <smbus_wait_until_ready+0x61>
mov    $0xfe0,%edi
call   1030 <inw@plt>
mov    $0xfe0,%esi
movzwl %ax,%edi
call   1040 <outw@plt>
jmp    1196 <smbus_wait_until_ready+0x66>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1140 <smbus_wait_until_ready+0x10>
mov    -0x8(%rbp),%rdx
mov    $0xfffffffe,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smbus_wait_until_ready>:
push   %rbp
push   %rbx
push   %rax
mov    $0xfffffffffff85ee0,%rbx
xor    %ebp,%ebp
jmp    114d <smbus_wait_until_ready+0x1d>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    $0x7a120,%rbx
je     1183 <smbus_wait_until_ready+0x53>
xor    %eax,%eax
call   1050 <smbus_delay@plt>
mov    $0xfe0,%edi
call   1030 <inw@plt>
test   $0x800,%eax
je     1188 <smbus_wait_until_ready+0x58>
test   %rbx,%rbx
jne    1140 <smbus_wait_until_ready+0x10>
mov    $0xfe0,%edi
call   1030 <inw@plt>
movzwl %ax,%edi
mov    $0xfe0,%esi
call   1040 <outw@plt>
jmp    1140 <smbus_wait_until_ready+0x10>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @smbus_wait_until_ready() {
%1 = alloca i64
%2 = alloca i16
store i64 1000000, i64* %1
br label %3
3: ; preds = %18, %0
%4 = call i32 (...) @smbus_delay()
%5 = call zeroext i16 @inw(i32 4064)
store i16 %5, i16* %2
%6 = load i16, i16* %2
%7 = zext i16 %6 to i32
%8 = and i32 %7, 2048
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
br label %22
11: ; preds = %3
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 500000
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call zeroext i16 @inw(i32 4064)
%16 = call i32 @outw(i16 zeroext %15, i32 4064)
br label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %17
%19 = load i64, i64* %1
%20 = add i64 %19, -1
store i64 %20, i64* %1
%21 = icmp ne i64 %20, 0
br i1 %21, label %3, label %22
22: ; preds = %18, %10
%23 = load i64, i64* %1
%24 = icmp ne i64 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 0, i32 -2
ret i32 %26
}

LLVM IR (-O2):
define i32 @smbus_wait_until_ready() {
br label %1
1: ; preds = %12, %0
%2 = phi i64 [ 1000000, %0 ], [ %13, %12 ]
%3 = tail call i32 (...) @smbus_delay()
%4 = tail call zeroext i16 @inw(i32 4064)
%5 = and i16 %4, 2048
%6 = icmp eq i16 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = icmp eq i64 %2, 500000
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call zeroext i16 @inw(i32 4064)
%11 = tail call i32 @outw(i16 zeroext %10, i32 4064)
br label %12
12: ; preds = %9, %7
%13 = add nsw i64 %2, -1
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %1
15: ; preds = %12, %1
%16 = phi i32 [ 0, %1 ], [ -2, %12 ]
ret i32 %16
}