#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
je     1167 <smbus_wait_until_done+0x47>
movzwl -0xa(%rbp),%eax
and    $0x437,%eax
cmp    $0x0,%eax
je     116c <smbus_wait_until_done+0x4c>
jmp    1187 <smbus_wait_until_done+0x67>
jmp    1171 <smbus_wait_until_done+0x51>
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>
and    $0x43f,%eax
cmp    $0x8,%ax
jne    1154 <smbus_wait_until_done+0x34>
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 = %17, %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
br i1 %9, label %15, label %10
10: ; preds = %3
%11 = load i16, i16* %2
%12 = zext i16 %11 to i32
%13 = and i32 %12, 1079
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10, %3
br label %21
16: ; preds = %10
br label %17
17: ; preds = %16
%18 = load i64, i64* %1
%19 = add i64 %18, -1
store i64 %19, i64* %1
%20 = icmp ne i64 %19, 0
br i1 %20, label %3, label %21
21: ; preds = %17, %15
%22 = load i64, i64* %1
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 0, i32 -1
ret i32 %25
}

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