#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*/ smbus_delay();
int smbus_wait_until_done(void) {
  unsigned long loops;
  loops = (100 * 1000 * 10);
  do {
    unsigned short val;
    smbus_delay();
    val = inw(0x0f00 + 0xe0);
    if (((val & 0x8) == 0) | ((val & 0x437) != 0)) {
      break;
    }
  } while (--loops);
  return loops ? 0 : -3;
}


x86 assembly (clang, -O0):
<smbus_wait_until_done>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0xf4240,-0x8(%rbp)
mov    $0x0,%al
call   1040 <smbus_delay@plt>
mov    $0xfe0,%edi
call   1030 <inw@plt>
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movzwl -0xa(%rbp),%ecx
and    $0x437,%ecx
cmp    $0x0,%ecx
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     117d <smbus_wait_until_done+0x5d>
jmp    1198 <smbus_wait_until_done+0x78>
jmp    1182 <smbus_wait_until_done+0x62>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1130 <smbus_wait_until_done+0x10>
mov    -0x8(%rbp),%rdx
mov    $0xfffffffd,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smbus_wait_until_done>:
push   %rbp
push   %rbx
push   %rax
mov    $0xfffffffffff0bdc0,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <smbus_delay@plt>
mov    $0xfe0,%edi
call   1030 <inw@plt>
movzwl %ax,%eax
test   $0x8,%al
sete   %cl
test   $0x437,%eax
setne  %al
or     %cl,%al
jne    115f <smbus_wait_until_done+0x3f>
inc    %rbx
jne    1130 <smbus_wait_until_done+0x10>
mov    $0xfffffffd,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @smbus_wait_until_done() {
%1 = alloca i64
%2 = alloca i16
store i64 1000000, i64* %1
br label %3
3: ; preds = %20, %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, 8
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = load i16, i16* %2
%12 = zext i16 %11 to i32
%13 = and i32 %12, 1079
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
%16 = or i32 %10, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %3
br label %24
19: ; preds = %3
br label %20
20: ; preds = %19
%21 = load i64, i64* %1
%22 = add i64 %21, -1
store i64 %22, i64* %1
%23 = icmp ne i64 %22, 0
br i1 %23, label %3, label %24
24: ; preds = %20, %18
%25 = load i64, i64* %1
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 0, i32 -3
ret i32 %28
}

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