#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*/ print_debug(char *);
int /*<<< orphan*/ print_debug_hex8(unsigned char);
int /*<<< orphan*/ smbus_delay();
int smbus_wait_until_ready(void) {
  unsigned char c;
  unsigned long loops;
  loops = (100 * 1000 * 10);
  do {
    smbus_delay();
    c = inb(0xf00 + 0x0);
    while ((c & 1) == 1) {
      print_debug("c is ");
      print_debug_hex8(c);
      print_debug("\n");
      c = inb(0xf00 + 0x0);
    }
  } while (--loops);
  return loops ? 0 : -1;
}


x86 assembly (clang, -O0):
<smbus_wait_until_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0xf4240,-0x10(%rbp)
mov    $0x0,%al
call   1060 <smbus_delay@plt>
mov    $0xf00,%edi
call   1040 <inb@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    11a7 <smbus_wait_until_ready+0x67>
lea    0xe85(%rip),%rdi
call   1050 <print_debug@plt>
movzbl -0x1(%rbp),%edi
call   1030 <print_debug_hex8@plt>
lea    0xe76(%rip),%rdi
call   1050 <print_debug@plt>
mov    $0xf00,%edi
call   1040 <inb@plt>
mov    %al,-0x1(%rbp)
jmp    1164 <smbus_wait_until_ready+0x24>
jmp    11ac <smbus_wait_until_ready+0x6c>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1150 <smbus_wait_until_ready+0x10>
mov    -0x10(%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_ready>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xf4240,%r12d
lea    0xeab(%rip),%r14
lea    0xeaa(%rip),%r15
jmp    1166 <smbus_wait_until_ready+0x26>
xchg   %ax,%ax
add    $0xffffffffffffffff,%r12
je     11aa <smbus_wait_until_ready+0x6a>
xor    %eax,%eax
call   1060 <smbus_delay@plt>
mov    $0xf00,%edi
call   1040 <inb@plt>
test   $0x1,%al
je     1160 <smbus_wait_until_ready+0x20>
mov    %eax,%ebx
nopl   (%rax)
mov    %r14,%rdi
call   1050 <print_debug@plt>
movzbl %bl,%edi
call   1030 <print_debug_hex8@plt>
mov    %r15,%rdi
call   1050 <print_debug@plt>
mov    $0xf00,%edi
call   1040 <inb@plt>
mov    %eax,%ebx
test   $0x1,%al
jne    1180 <smbus_wait_until_ready+0x40>
jmp    1160 <smbus_wait_until_ready+0x20>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"c is \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @smbus_wait_until_ready() {
%1 = alloca i8
%2 = alloca i64
store i64 1000000, i64* %2
br label %3
3: ; preds = %18, %0
%4 = call i32 (...) @smbus_delay()
%5 = call zeroext i8 @inb(i32 3840)
store i8 %5, i8* %1
br label %6
6: ; preds = %11, %3
%7 = load i8, i8* %1
%8 = zext i8 %7 to i32
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = load i8, i8* %1
%14 = call i32 @print_debug_hex8(i8 zeroext %13)
%15 = call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = call zeroext i8 @inb(i32 3840)
store i8 %16, i8* %1
br label %6
17: ; preds = %6
br label %18
18: ; preds = %17
%19 = load i64, i64* %2
%20 = add i64 %19, -1
store i64 %20, i64* %2
%21 = icmp ne i64 %20, 0
br i1 %21, label %3, label %22
22: ; preds = %18
%23 = load i64, i64* %2
%24 = icmp ne i64 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 0, i32 -1
ret i32 %26
}

LLVM IR (-O2):
@.str = [6 x i8] c"c is \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @smbus_wait_until_ready() {
br label %1
1: ; preds = %15, %0
%2 = phi i64 [ 1000000, %0 ], [ %16, %15 ]
%3 = tail call i32 (...) @smbus_delay()
%4 = tail call zeroext i8 @inb(i32 3840)
%5 = and i8 %4, 1
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1, %7
%8 = phi i8 [ %12, %7 ], [ %4, %1 ]
%9 = tail call i32 @print_debug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @print_debug_hex8(i8 zeroext %8)
%11 = tail call i32 @print_debug(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call zeroext i8 @inb(i32 3840)
%13 = and i8 %12, 1
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %1
%16 = add nsw i64 %2, -1
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %1
18: ; preds = %15
ret i32 -1
}