#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 */
int aty_ld_le32(int);
void ati_wait_vsync(void) {
  int i;
  for (i = 0; i < 2000000; i++)
    if ((aty_ld_le32(0x0018) & 0x00000001) == 0)
      break;
  for (i = 0; i < 2000000; i++)
    if ((aty_ld_le32(0x0018) & 0x00000001))
      break;
}


x86 assembly (clang, -O0):
<ati_wait_vsync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x1e8480,-0x4(%rbp)
jge    115a <ati_wait_vsync+0x4a>
mov    $0x18,%edi
call   1030 <aty_ld_le32@plt>
and    $0x1,%eax
cmp    $0x0,%eax
jne    1147 <ati_wait_vsync+0x37>
jmp    115a <ati_wait_vsync+0x4a>
jmp    114c <ati_wait_vsync+0x3c>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <ati_wait_vsync+0xf>
movl   $0x0,-0x4(%rbp)
cmpl   $0x1e8480,-0x4(%rbp)
jge    119c <ati_wait_vsync+0x8c>
mov    $0x18,%edi
call   1030 <aty_ld_le32@plt>
and    $0x1,%eax
cmp    $0x0,%eax
je     1189 <ati_wait_vsync+0x79>
jmp    119c <ati_wait_vsync+0x8c>
jmp    118e <ati_wait_vsync+0x7e>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1161 <ati_wait_vsync+0x51>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ati_wait_vsync>:
push   %rbx
mov    $0x1e847f,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    $0x18,%edi
call   1030 <aty_ld_le32@plt>
sub    $0x1,%ebx
setb   %cl
test   $0x1,%al
je     1138 <ati_wait_vsync+0x28>
test   %cl,%cl
je     1120 <ati_wait_vsync+0x10>
mov    $0x1e847f,%ebx
nopl   (%rax)
mov    $0x18,%edi
call   1030 <aty_ld_le32@plt>
sub    $0x1,%ebx
setb   %cl
test   $0x1,%al
jne    1158 <ati_wait_vsync+0x48>
test   %cl,%cl
je     1140 <ati_wait_vsync+0x30>
pop    %rbx
ret

LLVM IR (-O0):
define void @ati_wait_vsync() {
%1 = alloca i32
store i32 0, i32* %1
br label %2
2: ; preds = %11, %0
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 2000000
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = call i32 @aty_ld_le32(i32 24)
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %5
br label %14
10: ; preds = %5
br label %11
11: ; preds = %10
%12 = load i32, i32* %1
%13 = add nsw i32 %12, 1
store i32 %13, i32* %1
br label %2
14: ; preds = %9, %2
store i32 0, i32* %1
br label %15
15: ; preds = %24, %14
%16 = load i32, i32* %1
%17 = icmp slt i32 %16, 2000000
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = call i32 @aty_ld_le32(i32 24)
%20 = and i32 %19, 1
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %27
23: ; preds = %18
br label %24
24: ; preds = %23
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
br label %15
27: ; preds = %22, %15
ret void
}

LLVM IR (-O2):
define void @ati_wait_vsync() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %6, %1 ]
%3 = tail call i32 @aty_ld_le32(i32 24)
%4 = and i32 %3, 1
%5 = icmp eq i32 %4, 0
%6 = add nuw nsw i32 %2, 1
%7 = icmp eq i32 %6, 2000000
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %1
9: ; preds = %1, %9
%10 = phi i32 [ %14, %9 ], [ 0, %1 ]
%11 = tail call i32 @aty_ld_le32(i32 24)
%12 = and i32 %11, 1
%13 = icmp ne i32 %12, 0
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, 2000000
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %17, label %9
17: ; preds = %9
ret void
}