#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*/ smbus_delay();
int smbus_wait_until_done(void) {
  unsigned long loops;
  loops = (100 * 1000);
  do {
    unsigned char val;
    smbus_delay();
    val = inb(0x1000 + 0x0);
    if ((val & 1) == 0) {
      break;
    }
    if ((val & ~((1 << 6) | (1 << 0))) != 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   $0x186a0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <smbus_delay@plt>
mov    $0x1000,%edi
call   1030 <inb@plt>
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1159 <smbus_wait_until_done+0x39>
jmp    1189 <smbus_wait_until_done+0x69>
movzbl -0x9(%rbp),%eax
and    $0xffffffbe,%eax
cmp    $0x0,%eax
je     116e <smbus_wait_until_done+0x4e>
jmp    1189 <smbus_wait_until_done+0x69>
jmp    1173 <smbus_wait_until_done+0x53>
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    $0xfffffffffffe7960,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <smbus_delay@plt>
mov    $0x1000,%edi
call   1030 <inb@plt>
and    $0xbf,%al
cmp    $0x1,%al
jne    1151 <smbus_wait_until_done+0x31>
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 i8
store i64 100000, i64* %1
br label %3
3: ; preds = %18, %0
%4 = call i32 (...) @smbus_delay()
%5 = call zeroext i8 @inb(i32 4096)
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 i8, i8* %2
%13 = zext i8 %12 to i32
%14 = and i32 %13, -66
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
br label %22
17: ; preds = %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, %16, %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 -3
ret i32 %26
}

LLVM IR (-O2):
define i32 @smbus_wait_until_done() {
br label %1
1: ; preds = %7, %0
%2 = phi i64 [ 100000, %0 ], [ %8, %7 ]
%3 = tail call i32 (...) @smbus_delay()
%4 = tail call zeroext i8 @inb(i32 4096)
%5 = and i8 %4, -65
%6 = icmp eq i8 %5, 1
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 = %7, %1
%11 = phi i32 [ 0, %1 ], [ -3, %7 ]
ret i32 %11
}