#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(0x1000 + 0xe0);
    if (((val & 0x8) == 0) | ((val & 0x437) != 0)) {
      break;
    }
  } while (--loops);
  return loops ? 0 : -1;
}


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    $0x10e0,%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    $0xffffffff,%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   %rbx
mov    $0xf4240,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <smbus_delay@plt>
mov    $0x10e0,%edi
call   1030 <inw@plt>
movzwl %ax,%eax
test   $0x8,%al
sete   %cl
test   $0x437,%eax
setne  %al
or     %cl,%al
jne    115d <smbus_wait_until_done+0x3d>
add    $0xffffffffffffffff,%rbx
jne    1130 <smbus_wait_until_done+0x10>
xor    %ebx,%ebx
cmp    $0x1,%rbx
sbb    %eax,%eax
pop    %rbx
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 4320)
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 -1
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 4320)
%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 = %1, %14
%18 = phi i64 [ %2, %1 ], [ 0, %14 ]
%19 = icmp eq i64 %18, 0
%20 = sext i1 %19 to i32
ret i32 %20
}