#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 /*<<< orphan*/ one_int_read(int, unsigned int *);
int /*<<< orphan*/ usleep(int);
int ath9k_hw_wait(unsigned int reg, unsigned int mask, unsigned int val,
                  unsigned int timeout) {
  int i;
  unsigned int data;
  for (i = 0; i < (timeout / 20); i++) {
    one_int_read(0xb8115f18, &data);
    if (data == val)
      return 0;
    usleep(20);
  }
  return -1;
}


x86 assembly (clang, -O0):
<ath9k_hw_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x14,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jae    1198 <ath9k_hw_wait+0x78>
mov    $0xb8115f18,%edi
lea    -0x1c(%rbp),%rsi
call   1030 <one_int_read@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1180 <ath9k_hw_wait+0x60>
movl   $0x0,-0x4(%rbp)
jmp    119f <ath9k_hw_wait+0x7f>
mov    $0x14,%edi
call   1040 <usleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113b <ath9k_hw_wait+0x1b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ath9k_hw_wait>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
cmp    $0x14,%ecx
jb     1177 <ath9k_hw_wait+0x57>
mov    %edx,%ebp
mov    %ecx,%eax
mov    $0xcccccccd,%ebx
imul   %rax,%rbx
shr    $0x24,%rbx
lea    0x4(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    $0xb8115f18,%edi
mov    %r15,%rsi
call   1030 <one_int_read@plt>
cmp    %ebp,0x4(%rsp)
je     1174 <ath9k_hw_wait+0x54>
mov    $0x14,%edi
call   1040 <usleep@plt>
add    $0xffffffff,%ebx
jne    1150 <ath9k_hw_wait+0x30>
jmp    1177 <ath9k_hw_wait+0x57>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ath9k_hw_wait(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
br label %12
12: ; preds = %25, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %9
%15 = udiv i32 %14, 20
%16 = icmp ult i32 %13, %15
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = call i32 @one_int_read(i32 -1206821096, i32* %11)
%19 = load i32, i32* %11
%20 = load i32, i32* %8
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %5
br label %29
23: ; preds = %17
%24 = call i32 @usleep(i32 20)
br label %25
25: ; preds = %23
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
store i32 %27, i32* %10
br label %12
28: ; preds = %12
store i32 -1, i32* %5
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @ath9k_hw_wait(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp ult i32 %3, 20
br i1 %7, label %19, label %8
8: ; preds = %4
%9 = udiv i32 %3, 20
br label %10
10: ; preds = %8, %15
%11 = phi i32 [ %17, %15 ], [ 0, %8 ]
%12 = call i32 @one_int_read(i32 -1206821096, i32* %5)
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, %2
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = call i32 @usleep(i32 20)
%17 = add nuw nsw i32 %11, 1
%18 = icmp eq i32 %17, %9
br i1 %18, label %19, label %10
19: ; preds = %10, %15, %4
%20 = phi i32 [ -1, %4 ], [ -1, %15 ], [ 0, %10 ]
ret i32 %20
}