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


x86 assembly (clang, -O0):
<smbus_check_stop_condition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x3e8,-0x10(%rbp)
mov    $0x0,%al
call   1050 <smbus_delay@plt>
mov    -0x4(%rbp),%edi
add    $0x3,%edi
call   1040 <inb@plt>
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    116d <smbus_check_stop_condition+0x3d>
jmp    1193 <smbus_check_stop_condition+0x63>
mov    -0x4(%rbp),%esi
add    $0x5,%esi
mov    $0xff,%edi
call   1030 <outb@plt>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1143 <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   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x5(%r15),%r14d
add    $0x3,%r15d
mov    $0xfffffffffffffc18,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <smbus_delay@plt>
mov    %r15d,%edi
call   1040 <inb@plt>
test   $0x2,%al
je     117a <smbus_check_stop_condition+0x4a>
mov    $0xff,%edi
mov    %r14d,%esi
call   1030 <outb@plt>
inc    %rbx
jne    1150 <smbus_check_stop_condition+0x20>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 1000, i64* %4
br label %5
5: ; preds = %19, %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 %23
15: ; preds = %5
%16 = load i32, i32* %2
%17 = add i32 %16, 5
%18 = call i32 @outb(i32 255, i32 %17)
br label %19
19: ; preds = %15
%20 = load i64, i64* %4
%21 = add i64 %20, -1
store i64 %21, i64* %4
%22 = icmp ne i64 %21, 0
br i1 %22, label %5, label %23
23: ; preds = %19, %14
%24 = load i64, i64* %4
%25 = icmp ne i64 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 0, i32 -2
ret i32 %27
}

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