int titan_i2c_poll(void) {
  int i = 0;
  unsigned long val = 0;
  for (i = 0; i < 100; i++) {
    val = *(volatile unsigned long *)(0xbb000000 + 0x01A4);
    if (!(val & 0x8000))
      return 0;
  }
  return (-9223);
}


x86 assembly (clang, -O0):
<titan_i2c_poll>:
push   %rbp
mov    %rsp,%rbp
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    1163 <titan_i2c_poll+0x63>
mov    $0xbb0001a4,%eax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x8000,%rax
cmp    $0x0,%rax
jne    1150 <titan_i2c_poll+0x50>
movl   $0x0,-0x4(%rbp)
jmp    116a <titan_i2c_poll+0x6a>
jmp    1155 <titan_i2c_poll+0x55>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    111a <titan_i2c_poll+0x1a>
movl   $0xffffdbf9,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<titan_i2c_poll>:
mov    $0x64,%ecx
mov    $0xbb0001a4,%edx
xor    %eax,%eax
nopl   0x0(%rax)
testq  $0x8000,(%rdx)
je     1147 <titan_i2c_poll+0x47>
testq  $0x8000,(%rdx)
je     1147 <titan_i2c_poll+0x47>
testq  $0x8000,(%rdx)
je     1147 <titan_i2c_poll+0x47>
testq  $0x8000,(%rdx)
je     1147 <titan_i2c_poll+0x47>
testq  $0x8000,(%rdx)
je     1147 <titan_i2c_poll+0x47>
add    $0xfffffffb,%ecx
jne    1110 <titan_i2c_poll+0x10>
mov    $0xffffdbf9,%eax
ret

LLVM IR (-O0):
define i32 @titan_i2c_poll() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i32 0, i32* %2
store i64 0, i64* %3
store i32 0, i32* %2
br label %4
4: ; preds = %14, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 100
br i1 %6, label %7, label %17
7: ; preds = %4
%8 = load volatile i64, i64* inttoptr (i64 3137339812 to i64*)
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = and i64 %9, 32768
%11 = icmp ne i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %7
store i32 0, i32* %1
br label %18
13: ; preds = %7
br label %14
14: ; preds = %13
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %4
17: ; preds = %4
store i32 -9223, i32* %1
br label %18
18: ; preds = %17, %12
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
define i32 @titan_i2c_poll() {
br label %20
1: ; preds = %20
%2 = load volatile i64, i64* inttoptr (i64 3137339812 to i64*)
%3 = and i64 %2, 32768
%4 = icmp eq i64 %3, 0
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = load volatile i64, i64* inttoptr (i64 3137339812 to i64*)
%7 = and i64 %6, 32768
%8 = icmp eq i64 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %5
%10 = load volatile i64, i64* inttoptr (i64 3137339812 to i64*)
%11 = and i64 %10, 32768
%12 = icmp eq i64 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %9
%14 = load volatile i64, i64* inttoptr (i64 3137339812 to i64*)
%15 = and i64 %14, 32768
%16 = icmp eq i64 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %13
%18 = add nuw nsw i32 %21, 5
%19 = icmp eq i32 %18, 100
br i1 %19, label %25, label %20
20: ; preds = %17, %0
%21 = phi i32 [ 0, %0 ], [ %18, %17 ]
%22 = load volatile i64, i64* inttoptr (i64 3137339812 to i64*)
%23 = and i64 %22, 32768
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %1
25: ; preds = %17, %13, %9, %5, %1, %20
%26 = phi i32 [ 0, %20 ], [ 0, %1 ], [ 0, %5 ], [ 0, %9 ], [ 0, %13 ], [ -9223, %17 ]
ret i32 %26
}