#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 char inb(int);
int /*<<< orphan*/ outb(unsigned char, int);
int /*<<< orphan*/ smbus_delay();
int smbus_wait_until_ready(void) {
  unsigned long loops;
  loops = (100 * 1000 * 10);
  do {
    unsigned char val;
    smbus_delay();
    val = inb(0x5000 + 0x0);
    if ((val & 1) == 0) {
      break;
    }
    if (loops == ((100 * 1000 * 10) / 2)) {
      outb(inb(0x5000 + 0x0), 0x5000 + 0x0);
    }
  } 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    $0x5000,%edi
call   1040 <inb@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1169 <smbus_wait_until_ready+0x39>
jmp    11a9 <smbus_wait_until_ready+0x79>
cmpq   $0x7a120,-0x8(%rbp)
jne    118e <smbus_wait_until_ready+0x5e>
mov    $0x5000,%edi
call   1040 <inb@plt>
mov    $0x5000,%esi
movzbl %al,%edi
call   1030 <outb@plt>
jmp    1193 <smbus_wait_until_ready+0x63>
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     1180 <smbus_wait_until_ready+0x50>
xor    %eax,%eax
call   1050 <smbus_delay@plt>
mov    $0x5000,%edi
call   1040 <inb@plt>
test   $0x1,%al
je     1185 <smbus_wait_until_ready+0x55>
test   %rbx,%rbx
jne    1140 <smbus_wait_until_ready+0x10>
mov    $0x5000,%edi
call   1040 <inb@plt>
movzbl %al,%edi
mov    $0x5000,%esi
call   1030 <outb@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 i8
store i64 1000000, i64* %1
br label %3
3: ; preds = %18, %0
%4 = call i32 (...) @smbus_delay()
%5 = call zeroext i8 @inb(i32 20480)
store i8 %5, i8* %2
%6 = load i8, i8* %2
%7 = zext i8 %6 to i32
%8 = and i32 %7, 1
%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 i8 @inb(i32 20480)
%16 = call i32 @outb(i8 zeroext %15, i32 20480)
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 i8 @inb(i32 20480)
%5 = and i8 %4, 1
%6 = icmp eq i8 %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 i8 @inb(i32 20480)
%11 = tail call i32 @outb(i8 zeroext %10, i32 20480)
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
}