#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(unsigned int);
int /*<<< orphan*/ outb(unsigned char, unsigned int);
int /*<<< orphan*/ smbus_delay();
int smbus_check_stop_condition(unsigned smbus_io_base) {
  unsigned char val;
  unsigned long loops;
  loops = (100 * 1000 * 10);
  do {
    smbus_delay();
    val = inb(smbus_io_base + 0x03);
    if ((val & (0x01 << 1)) == 0) {
      break;
    }
  } while (--loops);
  return loops ? 0 : -2;
  val = inb(smbus_io_base + 0x03);
  outb(val & ~((0x01 << 7) | (0x01 << 6)), smbus_io_base + 0x03);
  outb((0x01 << 5) | (0x01 << 4) | (0x01 << 3), smbus_io_base + 0x01);
  val = inb(smbus_io_base + 0x02);
  outb(val | (0x01 << 1), smbus_io_base + 0x02);
}


x86 assembly (clang, -O0):
<smbus_check_stop_condition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movq   $0xf4240,-0x10(%rbp)
mov    $0x0,%al
call   1040 <smbus_delay@plt>
mov    -0x4(%rbp),%edi
add    $0x3,%edi
call   1030 <inb@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    115d <smbus_check_stop_condition+0x3d>
jmp    1178 <smbus_check_stop_condition+0x58>
jmp    1162 <smbus_check_stop_condition+0x42>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1133 <smbus_check_stop_condition+0x13>
mov    -0x10(%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_check_stop_condition>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
add    $0x3,%r14d
mov    $0xfffffffffff0bdc0,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <smbus_delay@plt>
mov    %r14d,%edi
call   1030 <inb@plt>
test   $0x2,%al
je     115d <smbus_check_stop_condition+0x3d>
inc    %rbx
jne    1140 <smbus_check_stop_condition+0x20>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @smbus_check_stop_condition(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i64
store i32 %0, i32* %2
store i64 1000000, i64* %4
br label %5
5: ; preds = %16, %1
%6 = call i32 (...) @smbus_delay()
%7 = load i32, i32* %2
%8 = add i32 %7, 3
%9 = call zeroext i8 @inb(i32 %8)
store i8 %9, i8* %3
%10 = load i8, i8* %3
%11 = zext i8 %10 to i32
%12 = and i32 %11, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %5
br label %20
15: ; preds = %5
br label %16
16: ; preds = %15
%17 = load i64, i64* %4
%18 = add i64 %17, -1
store i64 %18, i64* %4
%19 = icmp ne i64 %18, 0
br i1 %19, label %5, label %20
20: ; preds = %16, %14
%21 = load i64, i64* %4
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 0, i32 -2
ret i32 %24
}

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